admin api: mention admin_token and metrics_token in ListAdminTokensResponse

This commit is contained in:
Alex Auvolat 2025-03-11 15:57:29 +01:00
parent 9511b20153
commit ec0da3b644
3 changed files with 33 additions and 5 deletions

View file

@ -2043,7 +2043,6 @@
"GetAdminTokenInfoResponse": {
"type": "object",
"required": [
"id",
"name",
"expired",
"scope"
@ -2061,7 +2060,10 @@
"description": "Whether this admin token is expired already"
},
"id": {
"type": "string",
"type": [
"string",
"null"
],
"description": "Identifier of the admin token (which is also a prefix of the full bearer token)"
},
"name": {

View file

@ -22,7 +22,7 @@ impl RequestHandler for ListAdminTokensRequest {
) -> Result<ListAdminTokensResponse, Error> {
let now = now_msec();
let res = garage
let mut res = garage
.admin_token_table
.get_range(
&EmptyKey,
@ -36,6 +36,32 @@ impl RequestHandler for ListAdminTokensRequest {
.map(|t| admin_token_info_results(t, now))
.collect::<Vec<_>>();
if garage.config.admin.admin_token.is_some() {
res.insert(
0,
GetAdminTokenInfoResponse {
id: None,
name: "admin_token (from daemon configuration)".into(),
expiration: None,
expired: false,
scope: vec!["*".into()],
},
);
}
if garage.config.admin.metrics_token.is_some() {
res.insert(
1,
GetAdminTokenInfoResponse {
id: None,
name: "metrics_token (from daemon configuration)".into(),
expiration: None,
expired: false,
scope: vec!["Metrics".into()],
},
);
}
Ok(ListAdminTokensResponse(res))
}
}
@ -153,7 +179,7 @@ fn admin_token_info_results(token: &AdminApiToken, now: u64) -> GetAdminTokenInf
let params = token.params().unwrap();
GetAdminTokenInfoResponse {
id: token.prefix.clone(),
id: Some(token.prefix.clone()),
name: params.name.get().to_string(),
expiration: params.expiration.get().map(|x| {
DateTime::from_timestamp_millis(x as i64).expect("invalid timestamp stored in db")

View file

@ -313,7 +313,7 @@ pub struct GetAdminTokenInfoRequest {
#[serde(rename_all = "camelCase")]
pub struct GetAdminTokenInfoResponse {
/// Identifier of the admin token (which is also a prefix of the full bearer token)
pub id: String,
pub id: Option<String>,
/// Name of the admin API token
pub name: String,
/// Expiration time and date, formatted according to RFC 3339