admin api: clearer syntax for AddBucketAlias and RemoveBucketAlias
This commit is contained in:
parent
35c69964ef
commit
79a81f81cf
7 changed files with 78 additions and 69 deletions
|
@ -962,17 +962,19 @@ paths:
|
||||||
application/json:
|
application/json:
|
||||||
schema:
|
schema:
|
||||||
type: object
|
type: object
|
||||||
required: [bucketId, alias]
|
required: [bucketId]
|
||||||
properties:
|
properties:
|
||||||
bucketId:
|
bucketId:
|
||||||
type: string
|
type: string
|
||||||
example: e6a14cd6a27f48684579ec6b381c078ab11697e6bc8513b72b2f5307e25fff9b
|
example: e6a14cd6a27f48684579ec6b381c078ab11697e6bc8513b72b2f5307e25fff9b
|
||||||
|
globalAlias:
|
||||||
|
type: string
|
||||||
|
localAlias:
|
||||||
|
type: string
|
||||||
|
example: my_documents
|
||||||
accessKeyId:
|
accessKeyId:
|
||||||
type: string
|
type: string
|
||||||
example: GK31c2f218a2e44f485b94239e
|
example: GK31c2f218a2e44f485b94239e
|
||||||
alias:
|
|
||||||
type: string
|
|
||||||
example: my_documents
|
|
||||||
responses:
|
responses:
|
||||||
'500':
|
'500':
|
||||||
description: "The server can not handle your request. Check your connectivity with the rest of the cluster."
|
description: "The server can not handle your request. Check your connectivity with the rest of the cluster."
|
||||||
|
@ -1003,17 +1005,18 @@ paths:
|
||||||
application/json:
|
application/json:
|
||||||
schema:
|
schema:
|
||||||
type: object
|
type: object
|
||||||
required: [bucketId, alias]
|
required: [bucketId]
|
||||||
properties:
|
properties:
|
||||||
bucketId:
|
bucketId:
|
||||||
type: string
|
type: string
|
||||||
example: e6a14cd6a27f48684579ec6b381c078ab11697e6bc8513b72b2f5307e25fff9b
|
example: e6a14cd6a27f48684579ec6b381c078ab11697e6bc8513b72b2f5307e25fff9b
|
||||||
|
globalAlias:
|
||||||
|
type: string
|
||||||
|
example: the_bucket
|
||||||
|
localAlias:
|
||||||
|
type: string
|
||||||
accessKeyId:
|
accessKeyId:
|
||||||
type: string
|
type: string
|
||||||
example: GK31c2f218a2e44f485b94239e
|
|
||||||
alias:
|
|
||||||
type: string
|
|
||||||
example: my_documents
|
|
||||||
responses:
|
responses:
|
||||||
'500':
|
'500':
|
||||||
description: "The server can not handle your request. Check your connectivity with the rest of the cluster."
|
description: "The server can not handle your request. Check your connectivity with the rest of the cluster."
|
||||||
|
|
|
@ -753,32 +753,32 @@ Other flags will remain unchanged.
|
||||||
#### AddBucketAlias `POST /v2/AddBucketAlias`
|
#### AddBucketAlias `POST /v2/AddBucketAlias`
|
||||||
|
|
||||||
Creates an alias for a bucket in the namespace of a specific access key.
|
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
|
To create a global alias, specify the `globalAlias` field.
|
||||||
of the key. Otherwise, a global alias is created.
|
To create a local alias, specify the `localAlias` and `accessKeyId` fields.
|
||||||
|
|
||||||
Request body format:
|
Request body format:
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"bucketId": "e6a14cd6a27f48684579ec6b381c078ab11697e6bc8513b72b2f5307e25fff9b",
|
||||||
|
"globalAlias": "my-bucket"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
or:
|
||||||
|
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"bucketId": "e6a14cd6a27f48684579ec6b381c078ab11697e6bc8513b72b2f5307e25fff9b",
|
"bucketId": "e6a14cd6a27f48684579ec6b381c078ab11697e6bc8513b72b2f5307e25fff9b",
|
||||||
"accessKeyId": "GK31c2f218a2e44f485b94239e",
|
"accessKeyId": "GK31c2f218a2e44f485b94239e",
|
||||||
"alias": "my-bucket"
|
"localAlias": "my-bucket"
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
#### RemoveBucketAlias `POST /v2/RemoveBucketAlias`
|
#### RemoveBucketAlias `POST /v2/RemoveBucketAlias`
|
||||||
|
|
||||||
Removes an alias for a bucket in the namespace of a specific access key.
|
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
|
To remove a global alias, specify the `globalAlias` field.
|
||||||
of the key. Otherwise, the alias is removed from the global namespace.
|
To remove a local alias, specify the `localAlias` and `accessKeyId` fields.
|
||||||
|
|
||||||
Request body format:
|
|
||||||
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"bucketId": "e6a14cd6a27f48684579ec6b381c078ab11697e6bc8513b72b2f5307e25fff9b",
|
|
||||||
"accessKeyId": "GK31c2f218a2e44f485b94239e",
|
|
||||||
"alias": "my-bucket"
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
|
Request body format: same as AddBucketAlias.
|
||||||
|
|
|
@ -515,22 +515,36 @@ pub struct DenyBucketKeyResponse(pub GetBucketInfoResponse);
|
||||||
// ---- AddBucketAlias ----
|
// ---- AddBucketAlias ----
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize)]
|
||||||
|
#[serde(rename_all = "camelCase")]
|
||||||
pub struct AddBucketAliasRequest {
|
pub struct AddBucketAliasRequest {
|
||||||
pub bucket_id: String,
|
pub bucket_id: String,
|
||||||
pub access_key_id: Option<String>,
|
#[serde(flatten)]
|
||||||
pub alias: String,
|
pub alias: BucketAliasEnum,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize)]
|
||||||
pub struct AddBucketAliasResponse(pub GetBucketInfoResponse);
|
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 ----
|
// ---- RemoveBucketAlias ----
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize)]
|
||||||
|
#[serde(rename_all = "camelCase")]
|
||||||
pub struct RemoveBucketAliasRequest {
|
pub struct RemoveBucketAliasRequest {
|
||||||
pub bucket_id: String,
|
pub bucket_id: String,
|
||||||
pub access_key_id: Option<String>,
|
#[serde(flatten)]
|
||||||
pub alias: String,
|
pub alias: BucketAliasEnum,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize)]
|
||||||
|
|
|
@ -16,15 +16,7 @@ use garage_model::permission::*;
|
||||||
use garage_model::s3::mpu_table;
|
use garage_model::s3::mpu_table;
|
||||||
use garage_model::s3::object_table::*;
|
use garage_model::s3::object_table::*;
|
||||||
|
|
||||||
use crate::admin::api::ApiBucketKeyPerm;
|
use crate::admin::api::*;
|
||||||
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::error::*;
|
use crate::admin::error::*;
|
||||||
use crate::admin::EndpointHandler;
|
use crate::admin::EndpointHandler;
|
||||||
use crate::common_error::CommonError;
|
use crate::common_error::CommonError;
|
||||||
|
@ -459,15 +451,18 @@ impl EndpointHandler for AddBucketAliasRequest {
|
||||||
|
|
||||||
let helper = garage.locked_helper().await;
|
let helper = garage.locked_helper().await;
|
||||||
|
|
||||||
match self.access_key_id {
|
match self.alias {
|
||||||
None => {
|
BucketAliasEnum::Global { global_alias } => {
|
||||||
helper
|
helper
|
||||||
.set_global_bucket_alias(bucket_id, &self.alias)
|
.set_global_bucket_alias(bucket_id, &global_alias)
|
||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
Some(ak) => {
|
BucketAliasEnum::Local {
|
||||||
|
local_alias,
|
||||||
|
access_key_id,
|
||||||
|
} => {
|
||||||
helper
|
helper
|
||||||
.set_local_bucket_alias(bucket_id, &ak, &self.alias)
|
.set_local_bucket_alias(bucket_id, &access_key_id, &local_alias)
|
||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -487,15 +482,18 @@ impl EndpointHandler for RemoveBucketAliasRequest {
|
||||||
|
|
||||||
let helper = garage.locked_helper().await;
|
let helper = garage.locked_helper().await;
|
||||||
|
|
||||||
match self.access_key_id {
|
match self.alias {
|
||||||
None => {
|
BucketAliasEnum::Global { global_alias } => {
|
||||||
helper
|
helper
|
||||||
.unset_global_bucket_alias(bucket_id, &self.alias)
|
.unset_global_bucket_alias(bucket_id, &global_alias)
|
||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
Some(ak) => {
|
BucketAliasEnum::Local {
|
||||||
|
local_alias,
|
||||||
|
access_key_id,
|
||||||
|
} => {
|
||||||
helper
|
helper
|
||||||
.unset_local_bucket_alias(bucket_id, &ak, &self.alias)
|
.unset_local_bucket_alias(bucket_id, &access_key_id, &local_alias)
|
||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,14 +10,7 @@ use garage_rpc::layout;
|
||||||
|
|
||||||
use garage_model::garage::Garage;
|
use garage_model::garage::Garage;
|
||||||
|
|
||||||
use crate::admin::api::{
|
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::error::*;
|
use crate::admin::error::*;
|
||||||
use crate::admin::EndpointHandler;
|
use crate::admin::EndpointHandler;
|
||||||
|
|
||||||
|
|
|
@ -8,12 +8,7 @@ use garage_table::*;
|
||||||
use garage_model::garage::Garage;
|
use garage_model::garage::Garage;
|
||||||
use garage_model::key_table::*;
|
use garage_model::key_table::*;
|
||||||
|
|
||||||
use crate::admin::api::{
|
use crate::admin::api::*;
|
||||||
ApiBucketKeyPerm, CreateKeyRequest, CreateKeyResponse, DeleteKeyRequest, DeleteKeyResponse,
|
|
||||||
GetKeyInfoRequest, GetKeyInfoResponse, ImportKeyRequest, ImportKeyResponse,
|
|
||||||
KeyInfoBucketResponse, KeyPerm, ListKeysRequest, ListKeysResponse, ListKeysResponseItem,
|
|
||||||
UpdateKeyRequest, UpdateKeyResponse,
|
|
||||||
};
|
|
||||||
use crate::admin::error::*;
|
use crate::admin::error::*;
|
||||||
use crate::admin::EndpointHandler;
|
use crate::admin::EndpointHandler;
|
||||||
|
|
||||||
|
|
|
@ -174,16 +174,18 @@ impl AdminApiRequest {
|
||||||
// Bucket aliasing
|
// Bucket aliasing
|
||||||
Endpoint::GlobalAliasBucket { id, alias } => {
|
Endpoint::GlobalAliasBucket { id, alias } => {
|
||||||
Ok(AdminApiRequest::AddBucketAlias(AddBucketAliasRequest {
|
Ok(AdminApiRequest::AddBucketAlias(AddBucketAliasRequest {
|
||||||
access_key_id: None,
|
|
||||||
bucket_id: id,
|
bucket_id: id,
|
||||||
alias,
|
alias: BucketAliasEnum::Global {
|
||||||
|
global_alias: alias,
|
||||||
|
},
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
Endpoint::GlobalUnaliasBucket { id, alias } => Ok(AdminApiRequest::RemoveBucketAlias(
|
Endpoint::GlobalUnaliasBucket { id, alias } => Ok(AdminApiRequest::RemoveBucketAlias(
|
||||||
RemoveBucketAliasRequest {
|
RemoveBucketAliasRequest {
|
||||||
access_key_id: None,
|
|
||||||
bucket_id: id,
|
bucket_id: id,
|
||||||
alias,
|
alias: BucketAliasEnum::Global {
|
||||||
|
global_alias: alias,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
)),
|
)),
|
||||||
Endpoint::LocalAliasBucket {
|
Endpoint::LocalAliasBucket {
|
||||||
|
@ -191,9 +193,11 @@ impl AdminApiRequest {
|
||||||
access_key_id,
|
access_key_id,
|
||||||
alias,
|
alias,
|
||||||
} => Ok(AdminApiRequest::AddBucketAlias(AddBucketAliasRequest {
|
} => Ok(AdminApiRequest::AddBucketAlias(AddBucketAliasRequest {
|
||||||
access_key_id: Some(access_key_id),
|
|
||||||
bucket_id: id,
|
bucket_id: id,
|
||||||
alias,
|
alias: BucketAliasEnum::Local {
|
||||||
|
local_alias: alias,
|
||||||
|
access_key_id,
|
||||||
|
},
|
||||||
})),
|
})),
|
||||||
Endpoint::LocalUnaliasBucket {
|
Endpoint::LocalUnaliasBucket {
|
||||||
id,
|
id,
|
||||||
|
@ -201,9 +205,11 @@ impl AdminApiRequest {
|
||||||
alias,
|
alias,
|
||||||
} => Ok(AdminApiRequest::RemoveBucketAlias(
|
} => Ok(AdminApiRequest::RemoveBucketAlias(
|
||||||
RemoveBucketAliasRequest {
|
RemoveBucketAliasRequest {
|
||||||
access_key_id: Some(access_key_id),
|
|
||||||
bucket_id: id,
|
bucket_id: id,
|
||||||
alias,
|
alias: BucketAliasEnum::Local {
|
||||||
|
local_alias: alias,
|
||||||
|
access_key_id,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
)),
|
)),
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue