Skip to content

Commit

Permalink
feat(vdp): add private remaining credit endpont (#331)
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
jvallesm and droplet-bot authored May 14, 2024
1 parent 796a98a commit 2eea197
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
15 changes: 15 additions & 0 deletions core/mgmt/v1beta/mgmt.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
10 changes: 10 additions & 0 deletions core/mgmt/v1beta/mgmt_private_service.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
10 changes: 10 additions & 0 deletions openapiv2/core/service.swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 2eea197

Please sign in to comment.