Skip to content

Commit 5d1976e

Browse files
geroplroboquat
authored andcommitted
[server] Introduce UsageServiceMock to unblock the Self-Hosted release
1 parent b3976cc commit 5d1976e

File tree

3 files changed

+38
-3
lines changed

3 files changed

+38
-3
lines changed

components/server/ee/src/container-module.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ import { BillingModes, BillingModesImpl } from "./billing/billing-mode";
6565
import { EntitlementServiceLicense } from "./billing/entitlement-service-license";
6666
import { EntitlementServiceImpl } from "./billing/entitlement-service";
6767
import { EntitlementServiceUBP } from "./billing/entitlement-service-ubp";
68+
import { UsageService, UsageServiceImpl, NoOpUsageService } from "../../src/user/usage-service";
6869

6970
export const productionEEContainerModule = new ContainerModule((bind, unbind, isBound, rebind) => {
7071
rebind(Server).to(ServerEE).inSingletonScope();
@@ -132,4 +133,15 @@ export const productionEEContainerModule = new ContainerModule((bind, unbind, is
132133
bind(EntitlementServiceImpl).toSelf().inSingletonScope();
133134
rebind(EntitlementService).to(EntitlementServiceImpl).inSingletonScope();
134135
bind(BillingModes).to(BillingModesImpl).inSingletonScope();
136+
137+
// TODO(gpl) Remove as part of fixing https://github.com/gitpod-io/gitpod/issues/14129
138+
rebind(UsageService)
139+
.toDynamicValue((ctx) => {
140+
const config = ctx.container.get<Config>(Config);
141+
if (config.enablePayment) {
142+
return ctx.container.get<UsageServiceImpl>(UsageServiceImpl);
143+
}
144+
return new NoOpUsageService();
145+
})
146+
.inSingletonScope();
135147
});

components/server/src/container-module.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ import { WebhookEventGarbageCollector } from "./projects/webhook-event-garbage-c
111111
import { LivenessController } from "./liveness/liveness-controller";
112112
import { IDEServiceClient, IDEServiceDefinition } from "@gitpod/ide-service-api/lib/ide.pb";
113113
import { prometheusClientMiddleware } from "@gitpod/gitpod-protocol/lib/util/nice-grpc";
114-
import { UsageService } from "./user/usage-service";
114+
import { UsageService, UsageServiceImpl } from "./user/usage-service";
115115
import { OpenPrebuildPrefixContextParser } from "./workspace/open-prebuild-prefix-context-parser";
116116

117117
export const productionContainerModule = new ContainerModule((bind, unbind, isBound, rebind) => {
@@ -297,5 +297,6 @@ export const productionContainerModule = new ContainerModule((bind, unbind, isBo
297297

298298
bind(WebhookEventGarbageCollector).toSelf().inSingletonScope();
299299

300-
bind(UsageService).toSelf().inSingletonScope();
300+
bind(UsageServiceImpl).toSelf().inSingletonScope();
301+
bind(UsageService).toService(UsageServiceImpl);
301302
});

components/server/src/user/usage-service.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,16 @@ import {
1212
} from "@gitpod/usage-api/lib/usage/v1/usage.pb";
1313
import { inject, injectable } from "inversify";
1414

15+
export const UsageService = Symbol("UsageService");
16+
17+
export interface UsageService {
18+
getCurrentBalance(attributionId: AttributionId): Promise<{ usedCredits: number; usageLimit: number }>;
19+
20+
getCurrentBillingStategy(attributionId: AttributionId): Promise<CostCenter_BillingStrategy | undefined>;
21+
}
22+
1523
@injectable()
16-
export class UsageService {
24+
export class UsageServiceImpl implements UsageService {
1725
@inject(UsageServiceDefinition.name)
1826
protected readonly usageService: UsageServiceClient;
1927

@@ -40,3 +48,17 @@ export class UsageService {
4048
return response.costCenter?.billingStrategy;
4149
}
4250
}
51+
52+
// TODO(gpl) Remove as part of fixing https://github.com/gitpod-io/gitpod/issues/14129
53+
export class NoOpUsageService implements UsageService {
54+
async getCurrentBalance(attributionId: AttributionId): Promise<{ usedCredits: number; usageLimit: number }> {
55+
return {
56+
usedCredits: 0,
57+
usageLimit: 1000000000,
58+
};
59+
}
60+
61+
async getCurrentBillingStategy(attributionId: AttributionId): Promise<CostCenter_BillingStrategy | undefined> {
62+
return CostCenter_BillingStrategy.BILLING_STRATEGY_OTHER;
63+
}
64+
}

0 commit comments

Comments
 (0)