From 2eea197d10330623159a9d3e2b54e29d601849e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Vall=C3=A9s?= <3977183+jvallesm@users.noreply.github.com> Date: Tue, 14 May 2024 09:09:16 +0200 Subject: [PATCH] feat(vdp): add private remaining credit endpont (#331) Because - When checking the remaining credit during execution usage collection, we need round trips to fetch the user ID (user UID->user ID (mgmt)->remaining credit (mgmt)). Moreover, we need to add an authentication layer that shouldn't be needed from a backend service. This commit - Adds a private endpoint to fetch the remaining credit. --------- Co-authored-by: droplet-bot --- core/mgmt/v1beta/mgmt.proto | 15 +++++++++++++++ core/mgmt/v1beta/mgmt_private_service.proto | 10 ++++++++++ openapiv2/core/service.swagger.yaml | 10 ++++++++++ 3 files changed, 35 insertions(+) diff --git a/core/mgmt/v1beta/mgmt.proto b/core/mgmt/v1beta/mgmt.proto index af0833a8..d7f573bc 100644 --- a/core/mgmt/v1beta/mgmt.proto +++ b/core/mgmt/v1beta/mgmt.proto @@ -591,6 +591,21 @@ message GetRemainingCreditResponse { float amount = 1; } +// GetRemainingCreditAdminRequest represents a request to get the remaining +// credit of a user or organization without authentication. +message GetRemainingCreditAdminRequest { + // The user or organization to which the credit belongs. + // Format: `{[users|organizations]}/{uid}`. + string owner = 1 [ (google.api.field_behavior) = REQUIRED ]; +} + +// GetRemainingCreditAdminResponse contains the remaining credit of a user or +// organization. +message GetRemainingCreditAdminResponse { + // The requested credit. + float amount = 1; +} + // SubtractCreditRequest represents a request to subtract Instill Credit from // an account. message SubtractCreditRequest { diff --git a/core/mgmt/v1beta/mgmt_private_service.proto b/core/mgmt/v1beta/mgmt_private_service.proto index 4cf6eb25..81cbe01a 100644 --- a/core/mgmt/v1beta/mgmt_private_service.proto +++ b/core/mgmt/v1beta/mgmt_private_service.proto @@ -76,5 +76,15 @@ service MgmtPrivateService { option (google.api.method_signature) = "owner,amount"; } + // Get the remaining Instill Credit by owner UID + // + // This endpoint fetches the remaining unexpired credit of a user or + // organization, referenced by UID. + // + // On Instill Core, this endpoint will return a 404 Not Found status. + rpc GetRemainingCreditAdmin(GetRemainingCreditAdminRequest) returns (GetRemainingCreditAdminResponse) { + option (google.api.method_signature) = "owner"; + } + option (google.api.api_visibility).restriction = "INTERNAL"; } diff --git a/openapiv2/core/service.swagger.yaml b/openapiv2/core/service.swagger.yaml index e2e95936..49c1c7e8 100644 --- a/openapiv2/core/service.swagger.yaml +++ b/openapiv2/core/service.swagger.yaml @@ -1998,6 +1998,16 @@ definitions: title: GetPipelinesResponse represents a respond to GetPipelineRequest required: - pipelines + v1betaGetRemainingCreditAdminResponse: + type: object + properties: + amount: + type: number + format: float + description: The requested credit. + description: |- + GetRemainingCreditAdminResponse contains the remaining credit of a user or + organization. v1betaGetRemainingCreditResponse: type: object properties: