diff options
author | Øyvind Grønnesby <oyving@yahooinc.com> | 2022-05-31 14:22:15 +0200 |
---|---|---|
committer | Øyvind Grønnesby <oyving@yahooinc.com> | 2022-05-31 14:22:15 +0200 |
commit | da46b1496b114ef7d9bb163a56f8f4ddbac2dd16 (patch) | |
tree | f69fa3b79e937ba42d5073587ff7a4b668bf131b /controller-server | |
parent | da8c0d839fb45fddd4b59efa5a469d0b7e948d3f (diff) |
Expose all plans in billing API
Diffstat (limited to 'controller-server')
2 files changed, 23 insertions, 0 deletions
diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/billing/BillingApiHandler.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/billing/BillingApiHandler.java index 206303adc80..d45e69f781b 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/billing/BillingApiHandler.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/billing/BillingApiHandler.java @@ -24,6 +24,7 @@ import com.yahoo.vespa.hosted.controller.api.integration.billing.CollectionMetho import com.yahoo.vespa.hosted.controller.api.integration.billing.InstrumentOwner; import com.yahoo.vespa.hosted.controller.api.integration.billing.PaymentInstrument; import com.yahoo.vespa.hosted.controller.api.integration.billing.PlanId; +import com.yahoo.vespa.hosted.controller.api.integration.billing.PlanRegistry; import com.yahoo.vespa.hosted.controller.api.role.Role; import com.yahoo.vespa.hosted.controller.api.role.SecurityContext; import com.yahoo.vespa.hosted.controller.tenant.Tenant; @@ -56,11 +57,13 @@ public class BillingApiHandler extends ThreadedHttpRequestHandler { private final BillingController billingController; private final ApplicationController applicationController; private final TenantController tenantController; + private final PlanRegistry planRegistry; public BillingApiHandler(Executor executor, Controller controller) { super(executor); this.billingController = controller.serviceRegistry().billingController(); + this.planRegistry = controller.serviceRegistry().planRegistry(); this.applicationController = controller.applications(); this.tenantController = controller.tenants(); } @@ -103,6 +106,7 @@ public class BillingApiHandler extends ThreadedHttpRequestHandler { if (path.matches("/billing/v1/billing")) return getBillingAllTenants(request.getProperty("until")); if (path.matches("/billing/v1/invoice/export")) return getAllBills(); if (path.matches("/billing/v1/invoice/tenant/{tenant}/line-item")) return getLineItems(path.get("tenant")); + if (path.matches("/billing/v1/plans")) return getPlans(); return ErrorResponse.notFoundError("Nothing at " + path); } @@ -295,6 +299,18 @@ public class BillingApiHandler extends ThreadedHttpRequestHandler { } } + private HttpResponse getPlans() { + var slime = new Slime(); + var root = slime.setObject(); + var plans = root.setArray("plans"); + for (var plan : planRegistry.all()) { + var p = plans.addObject(); + p.setString("id", plan.id().value()); + p.setString("name", plan.displayName()); + } + return new SlimeJsonResponse(slime); + } + private HttpResponse getLineItems(String tenant) { var slimeResponse = new Slime(); var root = slimeResponse.setObject(); diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/billing/BillingApiHandlerTest.java b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/billing/BillingApiHandlerTest.java index b58e5294f66..c9e86849ed8 100644 --- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/billing/BillingApiHandlerTest.java +++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/billing/BillingApiHandlerTest.java @@ -79,6 +79,13 @@ public class BillingApiHandlerTest extends ControllerContainerCloudTest { } @Test + public void list_plans() { + var listPlansRequest = request("/billing/v1/plans", GET) + .roles(Role.hostedAccountant()); + tester.assertResponse(listPlansRequest, "{\"plans\":[{\"id\":\"trial\",\"name\":\"Free Trial - for testing purposes\"},{\"id\":\"paid\",\"name\":\"Paid Plan - for testing purposes\"},{\"id\":\"none\",\"name\":\"None Plan - for testing purposes\"}]}"); + } + + @Test public void setting_and_deleting_instrument() { assertTrue(billingController.getDefaultInstrument(tenant).isEmpty()); |