// Generated by openapi-moonbit — DO NOT EDIT
// Spec SHA-256: 7e574664c0f434e52021e12f313a3266fd3175fe2ecddde4c0e0930549c72ba2
///|
/// Operations in the `Token` group. Implement this trait to mock or wrap `Client`.
pub(open) trait TokenClient {
async fn list_account_tokens(self : Self, account_id~ : @uuid.UUID) -> @model.PageToken raise GolemError
async fn create_token(
self : Self,
account_id~ : @uuid.UUID,
body~ : @model.TokenCreation,
) -> @model.TokenWithSecret raise GolemError
async fn get_token(self : Self, token_id~ : @uuid.UUID) -> @model.Token raise GolemError
async fn delete_token(self : Self, token_id~ : @uuid.UUID) -> @model.Empty raise GolemError
}
///|
/// List all tokens of an account.
/// The format of each element is the same as the data object in the oauth2 endpoint's response.
///
/// `GET /v1/accounts/{account_id}/tokens` (`list_account_tokens`).
pub impl[T : @runtime.Transport] TokenClient for Client[T] with fn list_account_tokens(
self : Client[T],
account_id~ : @uuid.UUID,
) -> @model.PageToken raise GolemError {
let __path_params : Array[(String, String)] = []
__path_params.push(("account_id", account_id.to_string()))
let __path = self.expand_op_path(
"/v1/accounts/{account_id}/tokens", __path_params,
)
let __req = self.prepare_request(http_method="GET", path=__path)
let __resp = self.send_request(__req)
match __resp.status() {
200 =>
self.decode_json_response(__resp, __r => {
(@cjson.FromJson::from_json(__r.raw(), __r.context()) : @model.PageToken)
})
_ => raise self.api_error_from_response(__resp)
}
}
///|
/// Create new token
/// Creates a new token with a given expiration date.
/// The response not only contains the token data but also the secret which can be passed as a bearer token to the Authorization header to the Golem Cloud REST API.
///
/// `POST /v1/accounts/{account_id}/tokens` (`create_token`).
pub impl[T : @runtime.Transport] TokenClient for Client[T] with fn create_token(
self : Client[T],
account_id~ : @uuid.UUID,
body~ : @model.TokenCreation,
) -> @model.TokenWithSecret raise GolemError {
let __path_params : Array[(String, String)] = []
__path_params.push(("account_id", account_id.to_string()))
let __path = self.expand_op_path(
"/v1/accounts/{account_id}/tokens", __path_params,
)
let __req = self.prepare_request(http_method="POST", path=__path)
let _ = __req.with_body(
content_type="application/json",
body=@runtime.utf8_encode(body.to_json().stringify()),
)
let __resp = self.send_request(__req)
match __resp.status() {
200 =>
self.decode_json_response(__resp, __r => {
(
@cjson.FromJson::from_json(__r.raw(), __r.context()) :
@model.TokenWithSecret)
})
_ => raise self.api_error_from_response(__resp)
}
}
///|
/// Get token by id
///
/// `GET /v1/tokens/{token_id}` (`get_token`).
pub impl[T : @runtime.Transport] TokenClient for Client[T] with fn get_token(
self : Client[T],
token_id~ : @uuid.UUID,
) -> @model.Token raise GolemError {
let __path_params : Array[(String, String)] = []
__path_params.push(("token_id", token_id.to_string()))
let __path = self.expand_op_path("/v1/tokens/{token_id}", __path_params)
let __req = self.prepare_request(http_method="GET", path=__path)
let __resp = self.send_request(__req)
match __resp.status() {
200 =>
self.decode_json_response(__resp, __r => {
(@cjson.FromJson::from_json(__r.raw(), __r.context()) : @model.Token)
})
_ => raise self.api_error_from_response(__resp)
}
}
///|
/// Delete a token
/// Deletes a previously created token given by its identifier.
///
/// `DELETE /v1/tokens/{token_id}` (`delete_token`).
pub impl[T : @runtime.Transport] TokenClient for Client[T] with fn delete_token(
self : Client[T],
token_id~ : @uuid.UUID,
) -> @model.Empty raise GolemError {
let __path_params : Array[(String, String)] = []
__path_params.push(("token_id", token_id.to_string()))
let __path = self.expand_op_path("/v1/tokens/{token_id}", __path_params)
let __req = self.prepare_request(http_method="DELETE", path=__path)
let __resp = self.send_request(__req)
match __resp.status() {
200 =>
if __resp.body().is_empty() {
@cjson.Json::null()
} else {
let __b = __resp.text()
@rjson.parse_json(__b) catch {
e => {
let __err = GolemError::Decode(
status=__resp.status(),
message=e.to_string(),
body=__b,
)
raise __err
}
}
}
_ => raise self.api_error_from_response(__resp)
}
}
///|
pub extend Client with TokenClient::{
list_account_tokens,
create_token,
get_token,
delete_token,
}