Skip to content

Commit daf53bd

Browse files
authored
chore(mgmt): implement API token in mgmt backend (#150)
Because - we want to use API tokens to trigger pipelines in Instill Cloud This commit - add API token resource in mgmt-backend - update OpenAPI
1 parent 1148ada commit daf53bd

File tree

4 files changed

+445
-15
lines changed

4 files changed

+445
-15
lines changed

openapiv2/openapiv2.swagger.yaml

Lines changed: 250 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2093,6 +2093,87 @@ paths:
20932093
default: VIEW_UNSPECIFIED
20942094
tags:
20952095
- ConnectorPublicService
2096+
/v1alpha/{token.name}:
2097+
get:
2098+
summary: |-
2099+
GetToken method receives a GetTokenRequest message and returns a
2100+
GetTokenResponse message.
2101+
operationId: MgmtPublicService_GetToken
2102+
responses:
2103+
"200":
2104+
description: A successful response.
2105+
schema:
2106+
$ref: '#/definitions/v1alphaGetTokenResponse'
2107+
default:
2108+
description: An unexpected error response.
2109+
schema:
2110+
$ref: '#/definitions/rpcStatus'
2111+
parameters:
2112+
- name: token.name
2113+
description: API tokens resource name. It must have the format of "tokens/*"
2114+
in: path
2115+
required: true
2116+
type: string
2117+
pattern: tokens/[^/]+
2118+
tags:
2119+
- MgmtPublicService
2120+
delete:
2121+
summary: |-
2122+
DeleteToken method receives a DeleteTokenRequest message and returns
2123+
a DeleteTokenResponse message.
2124+
operationId: MgmtPublicService_DeleteToken
2125+
responses:
2126+
"200":
2127+
description: A successful response.
2128+
schema:
2129+
$ref: '#/definitions/v1alphaDeleteTokenResponse'
2130+
default:
2131+
description: An unexpected error response.
2132+
schema:
2133+
$ref: '#/definitions/rpcStatus'
2134+
parameters:
2135+
- name: token.name
2136+
description: API token resource name. It must have the format of "tokens/*"
2137+
in: path
2138+
required: true
2139+
type: string
2140+
pattern: tokens/[^/]+
2141+
tags:
2142+
- MgmtPublicService
2143+
/v1alpha/{token.name}/validate:
2144+
post:
2145+
summary: |-
2146+
ValidateToken method receives a ValidateTokenRequest message and
2147+
returns a ValidateTokenResponse
2148+
operationId: MgmtPrivateService_ValidateToken
2149+
responses:
2150+
"200":
2151+
description: A successful response.
2152+
schema:
2153+
$ref: '#/definitions/v1alphaValidateTokenResponse'
2154+
default:
2155+
description: An unexpected error response.
2156+
schema:
2157+
$ref: '#/definitions/rpcStatus'
2158+
parameters:
2159+
- name: token.name
2160+
description: |-
2161+
The resource name of the API token to validate,
2162+
for example: "tokens/test-token"
2163+
in: path
2164+
required: true
2165+
type: string
2166+
pattern: tokens/[^/]+
2167+
- name: body
2168+
in: body
2169+
required: true
2170+
schema:
2171+
type: object
2172+
title: |-
2173+
ValidateTokenRequest represents a request to validate whether
2174+
an API token is valid to be used for triggering pipelines
2175+
tags:
2176+
- MgmtPrivateService
20962177
/v1alpha/{user.name}/exist:
20972178
get:
20982179
summary: |-
@@ -2111,7 +2192,7 @@ paths:
21112192
parameters:
21122193
- name: user.name
21132194
description: |-
2114-
The resource name of the user to be deleted,
2195+
The resource name of the user to check,
21152196
for example: "users/local-user"
21162197
in: path
21172198
required: true
@@ -3749,6 +3830,63 @@ paths:
37493830
- source_connector
37503831
tags:
37513832
- ConnectorPublicService
3833+
/v1alpha/tokens:
3834+
get:
3835+
summary: |-
3836+
ListTokens method receives a ListTokensRequest message and returns a
3837+
ListTokensResponse message.
3838+
operationId: MgmtPublicService_ListTokens
3839+
responses:
3840+
"200":
3841+
description: A successful response.
3842+
schema:
3843+
$ref: '#/definitions/v1alphaListTokensResponse'
3844+
default:
3845+
description: An unexpected error response.
3846+
schema:
3847+
$ref: '#/definitions/rpcStatus'
3848+
parameters:
3849+
- name: page_size
3850+
description: |-
3851+
The maximum number of API tokens to return. The service may return fewer
3852+
than this value. If unspecified, at most 10 API tokens will be returned. The
3853+
maximum value is 100; values above 100 will be coerced to 100.
3854+
in: query
3855+
required: false
3856+
type: string
3857+
format: int64
3858+
- name: page_token
3859+
description: Page token
3860+
in: query
3861+
required: false
3862+
type: string
3863+
tags:
3864+
- MgmtPublicService
3865+
post:
3866+
summary: |-
3867+
CreateToken method receives a CreateTokenRequest message and returns
3868+
a CreateTokenResponse message.
3869+
operationId: MgmtPublicService_CreateToken
3870+
responses:
3871+
"200":
3872+
description: A successful response.
3873+
schema:
3874+
$ref: '#/definitions/v1alphaCreateTokenResponse'
3875+
default:
3876+
description: An unexpected error response.
3877+
schema:
3878+
$ref: '#/definitions/rpcStatus'
3879+
parameters:
3880+
- name: token
3881+
description: A token resource to create
3882+
in: body
3883+
required: true
3884+
schema:
3885+
$ref: '#/definitions/v1alphaApiToken'
3886+
required:
3887+
- token
3888+
tags:
3889+
- MgmtPublicService
37523890
/v1alpha/users/me:
37533891
get:
37543892
summary: |-
@@ -3983,6 +4121,10 @@ definitions:
39834121
if (any.is(Foo.class)) {
39844122
foo = any.unpack(Foo.class);
39854123
}
4124+
// or ...
4125+
if (any.isSameTypeAs(Foo.getDefaultInstance())) {
4126+
foo = any.unpack(Foo.getDefaultInstance());
4127+
}
39864128
39874129
Example 3: Pack and unpack a message in Python.
39884130
@@ -4013,7 +4155,6 @@ definitions:
40134155
in the type URL, for example "foo.bar.com/x/y.z" will yield type
40144156
name "y.z".
40154157
4016-
40174158
JSON
40184159
40194160
The JSON representation of an `Any` value uses the regular
@@ -4159,6 +4300,71 @@ definitions:
41594300
instance or workspace admins beforehand. The trade-off is that the user does
41604301
not have to provide as many technical inputs anymore and the auth process is
41614302
faster and easier to complete.
4303+
v1alphaApiToken:
4304+
type: object
4305+
properties:
4306+
name:
4307+
type: string
4308+
title: API token resource name. It must have the format of "tokens/*"
4309+
readOnly: true
4310+
uid:
4311+
type: string
4312+
title: API token UUID
4313+
readOnly: true
4314+
id:
4315+
type: string
4316+
description: |-
4317+
API token resource ID (the last segment of the resource name) used to
4318+
construct the resource name. This conforms to RFC-1034, which restricts to
4319+
letters, numbers, and hyphen, with the first character a letter, the last a
4320+
letter or a number, and a 63 character maximum.
4321+
Use this field to define where it's being used.
4322+
create_time:
4323+
type: string
4324+
format: date-time
4325+
title: API token creation time
4326+
readOnly: true
4327+
update_time:
4328+
type: string
4329+
format: date-time
4330+
title: API token update time
4331+
readOnly: true
4332+
access_token:
4333+
type: string
4334+
description: "An opaque access token representing the API token string. \nTo validate the token, the recipient of the token needs to call the server that issued the token."
4335+
readOnly: true
4336+
state:
4337+
$ref: '#/definitions/v1alphaApiTokenState'
4338+
title: API token state
4339+
readOnly: true
4340+
token_type:
4341+
type: string
4342+
title: API token type, value is fixed to "Bearer"
4343+
readOnly: true
4344+
lifetime:
4345+
type: string
4346+
format: int64
4347+
title: The amount of time (in seconds) the API token will live. If set to -1, indicating a non-expire token
4348+
expires_in:
4349+
type: string
4350+
format: int64
4351+
title: The amount of time (in seconds) the API token will expire. If value is -1, indicating a non-expire token
4352+
readOnly: true
4353+
title: ApiToken represents the content of a API token
4354+
v1alphaApiTokenState:
4355+
type: string
4356+
enum:
4357+
- STATE_UNSPECIFIED
4358+
- STATE_INACTIVE
4359+
- STATE_ACTIVE
4360+
- STATE_EXPIRED
4361+
default: STATE_UNSPECIFIED
4362+
description: |-
4363+
- STATE_UNSPECIFIED: State: UNSPECIFIED
4364+
- STATE_INACTIVE: State: INACTIVE
4365+
- STATE_ACTIVE: State: ACTIVE
4366+
- STATE_EXPIRED: State: EXPIRED
4367+
title: State enumerates the state of an API token
41624368
v1alphaBoundingBox:
41634369
type: object
41644370
properties:
@@ -4498,6 +4704,13 @@ definitions:
44984704
title: |-
44994705
CreateSourceConnectorResponse represents a response for a
45004706
SourceConnector resource
4707+
v1alphaCreateTokenResponse:
4708+
type: object
4709+
properties:
4710+
token:
4711+
$ref: '#/definitions/v1alphaApiToken'
4712+
title: The created API token resource
4713+
title: CreateTokenResponse represents a response for a API token resource
45014714
v1alphaCreateUserAdminResponse:
45024715
type: object
45034716
properties:
@@ -4527,6 +4740,9 @@ definitions:
45274740
v1alphaDeleteSourceConnectorResponse:
45284741
type: object
45294742
title: DeleteSourceConnectorResponse represents an empty response
4743+
v1alphaDeleteTokenResponse:
4744+
type: object
4745+
title: DeleteTokenResponse represents an empty response
45304746
v1alphaDeleteUserAdminResponse:
45314747
type: object
45324748
title: DeleteUserAdminResponse represents an empty response
@@ -5128,6 +5344,13 @@ definitions:
51285344
title: |-
51295345
GetSourceConnectorResponse represents a response for a
51305346
SourceConnector resource
5347+
v1alphaGetTokenResponse:
5348+
type: object
5349+
properties:
5350+
token:
5351+
$ref: '#/definitions/v1alphaApiToken'
5352+
title: An API token resource
5353+
title: GetTokenResponse represents a response for an API token resource
51315354
v1alphaGetUserAdminResponse:
51325355
type: object
51335356
properties:
@@ -5508,6 +5731,22 @@ definitions:
55085731
title: |-
55095732
ListSourceConnectorsResponse represents a response for a list of
55105733
SourceConnector resources
5734+
v1alphaListTokensResponse:
5735+
type: object
5736+
properties:
5737+
tokens:
5738+
type: array
5739+
items:
5740+
$ref: '#/definitions/v1alphaApiToken'
5741+
title: A list of API tokens resources
5742+
next_page_token:
5743+
type: string
5744+
title: Next page token
5745+
total_size:
5746+
type: string
5747+
format: int64
5748+
title: Total count of API tokens resources
5749+
title: ListTokensResponse represents a response for a list of API tokens
55115750
v1alphaListUsersAdminResponse:
55125751
type: object
55135752
properties:
@@ -7165,6 +7404,15 @@ definitions:
71657404
title: User records definition
71667405
required:
71677406
- uid
7407+
v1alphaValidateTokenResponse:
7408+
type: object
7409+
properties:
7410+
valid:
7411+
type: boolean
7412+
title: A boolean value indicating whether the token is valid
7413+
title: |-
7414+
ValidateTokenResponse represents a response about whether
7415+
the queried token is valid
71687416
v1alphaWatchDestinationConnectorResponse:
71697417
type: object
71707418
properties:

0 commit comments

Comments
 (0)