diff --git a/doc/api/garage-admin-v2.yml b/doc/api/garage-admin-v2.yml index 5cca7dd1..9020fe50 100644 --- a/doc/api/garage-admin-v2.yml +++ b/doc/api/garage-admin-v2.yml @@ -962,17 +962,19 @@ paths: application/json: schema: type: object - required: [bucketId, alias] + required: [bucketId] properties: bucketId: type: string example: e6a14cd6a27f48684579ec6b381c078ab11697e6bc8513b72b2f5307e25fff9b + globalAlias: + type: string + localAlias: + type: string + example: my_documents accessKeyId: type: string example: GK31c2f218a2e44f485b94239e - alias: - type: string - example: my_documents responses: '500': description: "The server can not handle your request. Check your connectivity with the rest of the cluster." @@ -1003,17 +1005,18 @@ paths: application/json: schema: type: object - required: [bucketId, alias] + required: [bucketId] properties: bucketId: type: string example: e6a14cd6a27f48684579ec6b381c078ab11697e6bc8513b72b2f5307e25fff9b + globalAlias: + type: string + example: the_bucket + localAlias: + type: string accessKeyId: type: string - example: GK31c2f218a2e44f485b94239e - alias: - type: string - example: my_documents responses: '500': description: "The server can not handle your request. Check your connectivity with the rest of the cluster." diff --git a/doc/drafts/admin-api.md b/doc/drafts/admin-api.md index 6d24a1b6..ca60ead1 100644 --- a/doc/drafts/admin-api.md +++ b/doc/drafts/admin-api.md @@ -753,32 +753,32 @@ Other flags will remain unchanged. #### AddBucketAlias `POST /v2/AddBucketAlias` Creates an alias for a bucket in the namespace of a specific access key. -If `accessKeyId` is specified, an alias is created in the local namespace -of the key. Otherwise, a global alias is created. +To create a global alias, specify the `globalAlias` field. +To create a local alias, specify the `localAlias` and `accessKeyId` fields. Request body format: +```json +{ + "bucketId": "e6a14cd6a27f48684579ec6b381c078ab11697e6bc8513b72b2f5307e25fff9b", + "globalAlias": "my-bucket" +} +``` + +or: + ```json { "bucketId": "e6a14cd6a27f48684579ec6b381c078ab11697e6bc8513b72b2f5307e25fff9b", "accessKeyId": "GK31c2f218a2e44f485b94239e", - "alias": "my-bucket" + "localAlias": "my-bucket" } ``` #### RemoveBucketAlias `POST /v2/RemoveBucketAlias` Removes an alias for a bucket in the namespace of a specific access key. -If `accessKeyId` is specified, the alias is removed from the local namespace -of the key. Otherwise, the alias is removed from the global namespace. - -Request body format: - -```json -{ - "bucketId": "e6a14cd6a27f48684579ec6b381c078ab11697e6bc8513b72b2f5307e25fff9b", - "accessKeyId": "GK31c2f218a2e44f485b94239e", - "alias": "my-bucket" -} -``` +To remove a global alias, specify the `globalAlias` field. +To remove a local alias, specify the `localAlias` and `accessKeyId` fields. +Request body format: same as AddBucketAlias. diff --git a/src/api/admin/api.rs b/src/api/admin/api.rs index 5fedd11f..eac93b6e 100644 --- a/src/api/admin/api.rs +++ b/src/api/admin/api.rs @@ -515,22 +515,36 @@ pub struct DenyBucketKeyResponse(pub GetBucketInfoResponse); // ---- AddBucketAlias ---- #[derive(Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] pub struct AddBucketAliasRequest { pub bucket_id: String, - pub access_key_id: Option, - pub alias: String, + #[serde(flatten)] + pub alias: BucketAliasEnum, } #[derive(Serialize, Deserialize)] pub struct AddBucketAliasResponse(pub GetBucketInfoResponse); +#[derive(Serialize, Deserialize)] +#[serde(untagged)] +pub enum BucketAliasEnum { + #[serde(rename_all = "camelCase")] + Global { global_alias: String }, + #[serde(rename_all = "camelCase")] + Local { + local_alias: String, + access_key_id: String, + }, +} + // ---- RemoveBucketAlias ---- #[derive(Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] pub struct RemoveBucketAliasRequest { pub bucket_id: String, - pub access_key_id: Option, - pub alias: String, + #[serde(flatten)] + pub alias: BucketAliasEnum, } #[derive(Serialize, Deserialize)] diff --git a/src/api/admin/bucket.rs b/src/api/admin/bucket.rs index ee7a5e12..0cc420ec 100644 --- a/src/api/admin/bucket.rs +++ b/src/api/admin/bucket.rs @@ -16,15 +16,7 @@ use garage_model::permission::*; use garage_model::s3::mpu_table; use garage_model::s3::object_table::*; -use crate::admin::api::ApiBucketKeyPerm; -use crate::admin::api::{ - AddBucketAliasRequest, AddBucketAliasResponse, AllowBucketKeyRequest, AllowBucketKeyResponse, - ApiBucketQuotas, BucketKeyPermChangeRequest, BucketLocalAlias, CreateBucketRequest, - CreateBucketResponse, DeleteBucketRequest, DeleteBucketResponse, DenyBucketKeyRequest, - DenyBucketKeyResponse, GetBucketInfoKey, GetBucketInfoRequest, GetBucketInfoResponse, - GetBucketInfoWebsiteResponse, ListBucketsRequest, ListBucketsResponse, ListBucketsResponseItem, - RemoveBucketAliasRequest, RemoveBucketAliasResponse, UpdateBucketRequest, UpdateBucketResponse, -}; +use crate::admin::api::*; use crate::admin::error::*; use crate::admin::EndpointHandler; use crate::common_error::CommonError; @@ -459,15 +451,18 @@ impl EndpointHandler for AddBucketAliasRequest { let helper = garage.locked_helper().await; - match self.access_key_id { - None => { + match self.alias { + BucketAliasEnum::Global { global_alias } => { helper - .set_global_bucket_alias(bucket_id, &self.alias) + .set_global_bucket_alias(bucket_id, &global_alias) .await?; } - Some(ak) => { + BucketAliasEnum::Local { + local_alias, + access_key_id, + } => { helper - .set_local_bucket_alias(bucket_id, &ak, &self.alias) + .set_local_bucket_alias(bucket_id, &access_key_id, &local_alias) .await?; } } @@ -487,15 +482,18 @@ impl EndpointHandler for RemoveBucketAliasRequest { let helper = garage.locked_helper().await; - match self.access_key_id { - None => { + match self.alias { + BucketAliasEnum::Global { global_alias } => { helper - .unset_global_bucket_alias(bucket_id, &self.alias) + .unset_global_bucket_alias(bucket_id, &global_alias) .await?; } - Some(ak) => { + BucketAliasEnum::Local { + local_alias, + access_key_id, + } => { helper - .unset_local_bucket_alias(bucket_id, &ak, &self.alias) + .unset_local_bucket_alias(bucket_id, &access_key_id, &local_alias) .await?; } } diff --git a/src/api/admin/cluster.rs b/src/api/admin/cluster.rs index 3327cb4c..112cb542 100644 --- a/src/api/admin/cluster.rs +++ b/src/api/admin/cluster.rs @@ -10,14 +10,7 @@ use garage_rpc::layout; use garage_model::garage::Garage; -use crate::admin::api::{ - ApplyClusterLayoutRequest, ApplyClusterLayoutResponse, ConnectClusterNodeResponse, - ConnectClusterNodesRequest, ConnectClusterNodesResponse, FreeSpaceResp, - GetClusterHealthRequest, GetClusterHealthResponse, GetClusterLayoutRequest, - GetClusterLayoutResponse, GetClusterStatusRequest, GetClusterStatusResponse, NodeResp, - NodeRoleChange, NodeRoleChangeEnum, NodeRoleResp, RevertClusterLayoutRequest, - RevertClusterLayoutResponse, UpdateClusterLayoutRequest, UpdateClusterLayoutResponse, -}; +use crate::admin::api::*; use crate::admin::error::*; use crate::admin::EndpointHandler; diff --git a/src/api/admin/key.rs b/src/api/admin/key.rs index 5bec2202..3e4201d9 100644 --- a/src/api/admin/key.rs +++ b/src/api/admin/key.rs @@ -8,12 +8,7 @@ use garage_table::*; use garage_model::garage::Garage; use garage_model::key_table::*; -use crate::admin::api::{ - ApiBucketKeyPerm, CreateKeyRequest, CreateKeyResponse, DeleteKeyRequest, DeleteKeyResponse, - GetKeyInfoRequest, GetKeyInfoResponse, ImportKeyRequest, ImportKeyResponse, - KeyInfoBucketResponse, KeyPerm, ListKeysRequest, ListKeysResponse, ListKeysResponseItem, - UpdateKeyRequest, UpdateKeyResponse, -}; +use crate::admin::api::*; use crate::admin::error::*; use crate::admin::EndpointHandler; diff --git a/src/api/admin/router_v2.rs b/src/api/admin/router_v2.rs index a6f110a7..29250f39 100644 --- a/src/api/admin/router_v2.rs +++ b/src/api/admin/router_v2.rs @@ -174,16 +174,18 @@ impl AdminApiRequest { // Bucket aliasing Endpoint::GlobalAliasBucket { id, alias } => { Ok(AdminApiRequest::AddBucketAlias(AddBucketAliasRequest { - access_key_id: None, bucket_id: id, - alias, + alias: BucketAliasEnum::Global { + global_alias: alias, + }, })) } Endpoint::GlobalUnaliasBucket { id, alias } => Ok(AdminApiRequest::RemoveBucketAlias( RemoveBucketAliasRequest { - access_key_id: None, bucket_id: id, - alias, + alias: BucketAliasEnum::Global { + global_alias: alias, + }, }, )), Endpoint::LocalAliasBucket { @@ -191,9 +193,11 @@ impl AdminApiRequest { access_key_id, alias, } => Ok(AdminApiRequest::AddBucketAlias(AddBucketAliasRequest { - access_key_id: Some(access_key_id), bucket_id: id, - alias, + alias: BucketAliasEnum::Local { + local_alias: alias, + access_key_id, + }, })), Endpoint::LocalUnaliasBucket { id, @@ -201,9 +205,11 @@ impl AdminApiRequest { alias, } => Ok(AdminApiRequest::RemoveBucketAlias( RemoveBucketAliasRequest { - access_key_id: Some(access_key_id), bucket_id: id, - alias, + alias: BucketAliasEnum::Local { + local_alias: alias, + access_key_id, + }, }, )),