mirror of
https://github.com/minio/minio.git
synced 2025-11-09 21:49:46 -05:00
Rename replication target handler (#10142)
Rename replication target handler to a generic bucket target handler
This commit is contained in:
@@ -108,12 +108,12 @@ const (
|
||||
// GetBucketQuotaAdminAction - allow getting bucket quota
|
||||
GetBucketQuotaAdminAction = "admin:GetBucketQuota"
|
||||
|
||||
// Bucket Replication admin Actions
|
||||
// Bucket Target admin Actions
|
||||
|
||||
// SetBucketReplicationTargetAction - allow setting bucket replication target
|
||||
SetBucketReplicationTargetAction = "admin:SetBucketReplicationTarget"
|
||||
// GetBucketReplicationTargetAction - allow getting bucket replication targets
|
||||
GetBucketReplicationTargetAction = "admin:GetBucketReplicationTarget"
|
||||
// SetBucketTargetAction - allow setting bucket target
|
||||
SetBucketTargetAction = "admin:SetBucketTarget"
|
||||
// GetBucketTargetAction - allow getting bucket targets
|
||||
GetBucketTargetAction = "admin:GetBucketTarget"
|
||||
|
||||
// AllAdminActions - provides all admin permissions
|
||||
AllAdminActions = "admin:*"
|
||||
@@ -121,42 +121,42 @@ const (
|
||||
|
||||
// List of all supported admin actions.
|
||||
var supportedAdminActions = map[AdminAction]struct{}{
|
||||
HealAdminAction: {},
|
||||
StorageInfoAdminAction: {},
|
||||
DataUsageInfoAdminAction: {},
|
||||
TopLocksAdminAction: {},
|
||||
ProfilingAdminAction: {},
|
||||
TraceAdminAction: {},
|
||||
ConsoleLogAdminAction: {},
|
||||
KMSKeyStatusAdminAction: {},
|
||||
ServerInfoAdminAction: {},
|
||||
OBDInfoAdminAction: {},
|
||||
ServerUpdateAdminAction: {},
|
||||
ServiceRestartAdminAction: {},
|
||||
ServiceStopAdminAction: {},
|
||||
ConfigUpdateAdminAction: {},
|
||||
CreateUserAdminAction: {},
|
||||
DeleteUserAdminAction: {},
|
||||
ListUsersAdminAction: {},
|
||||
EnableUserAdminAction: {},
|
||||
DisableUserAdminAction: {},
|
||||
GetUserAdminAction: {},
|
||||
AddUserToGroupAdminAction: {},
|
||||
RemoveUserFromGroupAdminAction: {},
|
||||
GetGroupAdminAction: {},
|
||||
ListGroupsAdminAction: {},
|
||||
EnableGroupAdminAction: {},
|
||||
DisableGroupAdminAction: {},
|
||||
CreatePolicyAdminAction: {},
|
||||
DeletePolicyAdminAction: {},
|
||||
GetPolicyAdminAction: {},
|
||||
AttachPolicyAdminAction: {},
|
||||
ListUserPoliciesAdminAction: {},
|
||||
SetBucketQuotaAdminAction: {},
|
||||
GetBucketQuotaAdminAction: {},
|
||||
SetBucketReplicationTargetAction: {},
|
||||
GetBucketReplicationTargetAction: {},
|
||||
AllAdminActions: {},
|
||||
HealAdminAction: {},
|
||||
StorageInfoAdminAction: {},
|
||||
DataUsageInfoAdminAction: {},
|
||||
TopLocksAdminAction: {},
|
||||
ProfilingAdminAction: {},
|
||||
TraceAdminAction: {},
|
||||
ConsoleLogAdminAction: {},
|
||||
KMSKeyStatusAdminAction: {},
|
||||
ServerInfoAdminAction: {},
|
||||
OBDInfoAdminAction: {},
|
||||
ServerUpdateAdminAction: {},
|
||||
ServiceRestartAdminAction: {},
|
||||
ServiceStopAdminAction: {},
|
||||
ConfigUpdateAdminAction: {},
|
||||
CreateUserAdminAction: {},
|
||||
DeleteUserAdminAction: {},
|
||||
ListUsersAdminAction: {},
|
||||
EnableUserAdminAction: {},
|
||||
DisableUserAdminAction: {},
|
||||
GetUserAdminAction: {},
|
||||
AddUserToGroupAdminAction: {},
|
||||
RemoveUserFromGroupAdminAction: {},
|
||||
GetGroupAdminAction: {},
|
||||
ListGroupsAdminAction: {},
|
||||
EnableGroupAdminAction: {},
|
||||
DisableGroupAdminAction: {},
|
||||
CreatePolicyAdminAction: {},
|
||||
DeletePolicyAdminAction: {},
|
||||
GetPolicyAdminAction: {},
|
||||
AttachPolicyAdminAction: {},
|
||||
ListUserPoliciesAdminAction: {},
|
||||
SetBucketQuotaAdminAction: {},
|
||||
GetBucketQuotaAdminAction: {},
|
||||
SetBucketTargetAction: {},
|
||||
GetBucketTargetAction: {},
|
||||
AllAdminActions: {},
|
||||
}
|
||||
|
||||
// IsValid - checks if action is valid or not.
|
||||
@@ -167,39 +167,39 @@ func (action AdminAction) IsValid() bool {
|
||||
|
||||
// adminActionConditionKeyMap - holds mapping of supported condition key for an action.
|
||||
var adminActionConditionKeyMap = map[Action]condition.KeySet{
|
||||
AllAdminActions: condition.NewKeySet(condition.AllSupportedAdminKeys...),
|
||||
HealAdminAction: condition.NewKeySet(condition.AllSupportedAdminKeys...),
|
||||
StorageInfoAdminAction: condition.NewKeySet(condition.AllSupportedAdminKeys...),
|
||||
ServerInfoAdminAction: condition.NewKeySet(condition.AllSupportedAdminKeys...),
|
||||
DataUsageInfoAdminAction: condition.NewKeySet(condition.AllSupportedAdminKeys...),
|
||||
OBDInfoAdminAction: condition.NewKeySet(condition.AllSupportedAdminKeys...),
|
||||
TopLocksAdminAction: condition.NewKeySet(condition.AllSupportedAdminKeys...),
|
||||
ProfilingAdminAction: condition.NewKeySet(condition.AllSupportedAdminKeys...),
|
||||
TraceAdminAction: condition.NewKeySet(condition.AllSupportedAdminKeys...),
|
||||
ConsoleLogAdminAction: condition.NewKeySet(condition.AllSupportedAdminKeys...),
|
||||
KMSKeyStatusAdminAction: condition.NewKeySet(condition.AllSupportedAdminKeys...),
|
||||
ServerUpdateAdminAction: condition.NewKeySet(condition.AllSupportedAdminKeys...),
|
||||
ServiceRestartAdminAction: condition.NewKeySet(condition.AllSupportedAdminKeys...),
|
||||
ServiceStopAdminAction: condition.NewKeySet(condition.AllSupportedAdminKeys...),
|
||||
ConfigUpdateAdminAction: condition.NewKeySet(condition.AllSupportedAdminKeys...),
|
||||
CreateUserAdminAction: condition.NewKeySet(condition.AllSupportedAdminKeys...),
|
||||
DeleteUserAdminAction: condition.NewKeySet(condition.AllSupportedAdminKeys...),
|
||||
ListUsersAdminAction: condition.NewKeySet(condition.AllSupportedAdminKeys...),
|
||||
EnableUserAdminAction: condition.NewKeySet(condition.AllSupportedAdminKeys...),
|
||||
DisableUserAdminAction: condition.NewKeySet(condition.AllSupportedAdminKeys...),
|
||||
GetUserAdminAction: condition.NewKeySet(condition.AllSupportedAdminKeys...),
|
||||
AddUserToGroupAdminAction: condition.NewKeySet(condition.AllSupportedAdminKeys...),
|
||||
RemoveUserFromGroupAdminAction: condition.NewKeySet(condition.AllSupportedAdminKeys...),
|
||||
ListGroupsAdminAction: condition.NewKeySet(condition.AllSupportedAdminKeys...),
|
||||
EnableGroupAdminAction: condition.NewKeySet(condition.AllSupportedAdminKeys...),
|
||||
DisableGroupAdminAction: condition.NewKeySet(condition.AllSupportedAdminKeys...),
|
||||
CreatePolicyAdminAction: condition.NewKeySet(condition.AllSupportedAdminKeys...),
|
||||
DeletePolicyAdminAction: condition.NewKeySet(condition.AllSupportedAdminKeys...),
|
||||
GetPolicyAdminAction: condition.NewKeySet(condition.AllSupportedAdminKeys...),
|
||||
AttachPolicyAdminAction: condition.NewKeySet(condition.AllSupportedAdminKeys...),
|
||||
ListUserPoliciesAdminAction: condition.NewKeySet(condition.AllSupportedAdminKeys...),
|
||||
SetBucketQuotaAdminAction: condition.NewKeySet(condition.AllSupportedAdminKeys...),
|
||||
GetBucketQuotaAdminAction: condition.NewKeySet(condition.AllSupportedAdminKeys...),
|
||||
SetBucketReplicationTargetAction: condition.NewKeySet(condition.AllSupportedAdminKeys...),
|
||||
GetBucketReplicationTargetAction: condition.NewKeySet(condition.AllSupportedAdminKeys...),
|
||||
AllAdminActions: condition.NewKeySet(condition.AllSupportedAdminKeys...),
|
||||
HealAdminAction: condition.NewKeySet(condition.AllSupportedAdminKeys...),
|
||||
StorageInfoAdminAction: condition.NewKeySet(condition.AllSupportedAdminKeys...),
|
||||
ServerInfoAdminAction: condition.NewKeySet(condition.AllSupportedAdminKeys...),
|
||||
DataUsageInfoAdminAction: condition.NewKeySet(condition.AllSupportedAdminKeys...),
|
||||
OBDInfoAdminAction: condition.NewKeySet(condition.AllSupportedAdminKeys...),
|
||||
TopLocksAdminAction: condition.NewKeySet(condition.AllSupportedAdminKeys...),
|
||||
ProfilingAdminAction: condition.NewKeySet(condition.AllSupportedAdminKeys...),
|
||||
TraceAdminAction: condition.NewKeySet(condition.AllSupportedAdminKeys...),
|
||||
ConsoleLogAdminAction: condition.NewKeySet(condition.AllSupportedAdminKeys...),
|
||||
KMSKeyStatusAdminAction: condition.NewKeySet(condition.AllSupportedAdminKeys...),
|
||||
ServerUpdateAdminAction: condition.NewKeySet(condition.AllSupportedAdminKeys...),
|
||||
ServiceRestartAdminAction: condition.NewKeySet(condition.AllSupportedAdminKeys...),
|
||||
ServiceStopAdminAction: condition.NewKeySet(condition.AllSupportedAdminKeys...),
|
||||
ConfigUpdateAdminAction: condition.NewKeySet(condition.AllSupportedAdminKeys...),
|
||||
CreateUserAdminAction: condition.NewKeySet(condition.AllSupportedAdminKeys...),
|
||||
DeleteUserAdminAction: condition.NewKeySet(condition.AllSupportedAdminKeys...),
|
||||
ListUsersAdminAction: condition.NewKeySet(condition.AllSupportedAdminKeys...),
|
||||
EnableUserAdminAction: condition.NewKeySet(condition.AllSupportedAdminKeys...),
|
||||
DisableUserAdminAction: condition.NewKeySet(condition.AllSupportedAdminKeys...),
|
||||
GetUserAdminAction: condition.NewKeySet(condition.AllSupportedAdminKeys...),
|
||||
AddUserToGroupAdminAction: condition.NewKeySet(condition.AllSupportedAdminKeys...),
|
||||
RemoveUserFromGroupAdminAction: condition.NewKeySet(condition.AllSupportedAdminKeys...),
|
||||
ListGroupsAdminAction: condition.NewKeySet(condition.AllSupportedAdminKeys...),
|
||||
EnableGroupAdminAction: condition.NewKeySet(condition.AllSupportedAdminKeys...),
|
||||
DisableGroupAdminAction: condition.NewKeySet(condition.AllSupportedAdminKeys...),
|
||||
CreatePolicyAdminAction: condition.NewKeySet(condition.AllSupportedAdminKeys...),
|
||||
DeletePolicyAdminAction: condition.NewKeySet(condition.AllSupportedAdminKeys...),
|
||||
GetPolicyAdminAction: condition.NewKeySet(condition.AllSupportedAdminKeys...),
|
||||
AttachPolicyAdminAction: condition.NewKeySet(condition.AllSupportedAdminKeys...),
|
||||
ListUserPoliciesAdminAction: condition.NewKeySet(condition.AllSupportedAdminKeys...),
|
||||
SetBucketQuotaAdminAction: condition.NewKeySet(condition.AllSupportedAdminKeys...),
|
||||
GetBucketQuotaAdminAction: condition.NewKeySet(condition.AllSupportedAdminKeys...),
|
||||
SetBucketTargetAction: condition.NewKeySet(condition.AllSupportedAdminKeys...),
|
||||
GetBucketTargetAction: condition.NewKeySet(condition.AllSupportedAdminKeys...),
|
||||
}
|
||||
|
||||
@@ -42,19 +42,19 @@ func main() {
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
target := madmin.BucketReplicationTarget{Endpoint: "site2:9000", Credentials: creds, TargetBucket: "destbucket", IsSSL: false}
|
||||
// Set bucket replication target
|
||||
if err := madmClnt.SetBucketReplicationTarget(ctx, "srcbucket", &target); err != nil {
|
||||
target := madmin.BucketTarget{Endpoint: "site2:9000", Credentials: creds, TargetBucket: "destbucket", IsSSL: false}
|
||||
// Set bucket target
|
||||
if err := madmClnt.SetBucketTarget(ctx, "srcbucket", &target); err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
// Get bucket replication target
|
||||
target, err = madmClnt.GetBucketReplicationTarget(ctx, "srcbucket")
|
||||
// Get bucket target
|
||||
target, err = madmClnt.GetBucketTarget(ctx, "srcbucket")
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
|
||||
// Remove bucket replication target
|
||||
if err := madmClnt.SetBucketReplicationTarget(ctx, "srcbucket", nil); err != nil {
|
||||
// Remove bucket target
|
||||
if err := madmClnt.SetBucketTarget(ctx, "srcbucket", nil); err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
|
||||
@@ -29,46 +29,60 @@ import (
|
||||
"github.com/minio/minio/pkg/auth"
|
||||
)
|
||||
|
||||
// BucketReplicationTarget represents the target bucket and site to be replicated to.
|
||||
type BucketReplicationTarget struct {
|
||||
// ArnType represents bucket ARN type
|
||||
type ArnType string
|
||||
|
||||
const (
|
||||
// Replication specifies a ARN type of replication
|
||||
Replication ArnType = "replication"
|
||||
)
|
||||
|
||||
// IsValid returns true if ARN type is replication
|
||||
func (t ArnType) IsValid() bool {
|
||||
return t == Replication
|
||||
}
|
||||
|
||||
// BucketTarget represents the target bucket and site association.
|
||||
type BucketTarget struct {
|
||||
Endpoint string `json:"endpoint"`
|
||||
Credentials *auth.Credentials `json:"credentials"`
|
||||
TargetBucket string `json:"targetbucket"`
|
||||
IsSSL bool `json:"isssl"`
|
||||
Secure bool `json:"secure"`
|
||||
Path string `json:"path,omitempty"`
|
||||
API string `json:"api,omitempty"`
|
||||
Arn string `json:"arn,omitempty"`
|
||||
Type ArnType `json:"type"`
|
||||
}
|
||||
|
||||
// URL returns replication target url
|
||||
func (t BucketReplicationTarget) URL() string {
|
||||
func (t BucketTarget) URL() string {
|
||||
scheme := "http"
|
||||
if t.IsSSL {
|
||||
if t.Secure {
|
||||
scheme = "https"
|
||||
}
|
||||
return fmt.Sprintf("%s://%s", scheme, t.Endpoint)
|
||||
}
|
||||
|
||||
// Empty returns true if struct is empty.
|
||||
func (t BucketReplicationTarget) Empty() bool {
|
||||
func (t BucketTarget) Empty() bool {
|
||||
return t.String() == "" || t.Credentials == nil
|
||||
}
|
||||
|
||||
func (t *BucketReplicationTarget) String() string {
|
||||
func (t *BucketTarget) String() string {
|
||||
return fmt.Sprintf("%s %s", t.Endpoint, t.TargetBucket)
|
||||
}
|
||||
|
||||
// GetBucketReplicationTarget - gets replication target for this bucket
|
||||
func (adm *AdminClient) GetBucketReplicationTarget(ctx context.Context, bucket string) (target BucketReplicationTarget, err error) {
|
||||
// GetBucketTarget - gets target for this bucket
|
||||
func (adm *AdminClient) GetBucketTarget(ctx context.Context, bucket string) (target BucketTarget, err error) {
|
||||
queryValues := url.Values{}
|
||||
queryValues.Set("bucket", bucket)
|
||||
|
||||
reqData := requestData{
|
||||
relPath: adminAPIPrefix + "/get-bucket-replication-target",
|
||||
relPath: adminAPIPrefix + "/get-bucket-target",
|
||||
queryValues: queryValues,
|
||||
}
|
||||
|
||||
// Execute GET on /minio/admin/v3/get-bucket-replication-target
|
||||
// Execute GET on /minio/admin/v3/get-bucket-target
|
||||
resp, err := adm.executeMethod(ctx, http.MethodGet, reqData)
|
||||
|
||||
defer closeResponse(resp)
|
||||
@@ -88,13 +102,13 @@ func (adm *AdminClient) GetBucketReplicationTarget(ctx context.Context, bucket s
|
||||
return target, err
|
||||
}
|
||||
if target.Empty() {
|
||||
return target, errors.New("No Replication target configured")
|
||||
return target, errors.New("No bucket target configured")
|
||||
}
|
||||
return target, nil
|
||||
}
|
||||
|
||||
// SetBucketReplicationTarget sets up a replication target for this bucket
|
||||
func (adm *AdminClient) SetBucketReplicationTarget(ctx context.Context, bucket string, target *BucketReplicationTarget) error {
|
||||
// SetBucketTarget sets up a remote target for this bucket
|
||||
func (adm *AdminClient) SetBucketTarget(ctx context.Context, bucket string, target *BucketTarget) error {
|
||||
data, err := json.Marshal(target)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -107,7 +121,7 @@ func (adm *AdminClient) SetBucketReplicationTarget(ctx context.Context, bucket s
|
||||
queryValues.Set("bucket", bucket)
|
||||
|
||||
reqData := requestData{
|
||||
relPath: adminAPIPrefix + "/set-bucket-replication-target",
|
||||
relPath: adminAPIPrefix + "/set-bucket-target",
|
||||
queryValues: queryValues,
|
||||
content: encData,
|
||||
}
|
||||
@@ -127,17 +141,17 @@ func (adm *AdminClient) SetBucketReplicationTarget(ctx context.Context, bucket s
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetBucketReplicationARN - gets replication Arn for this remote
|
||||
func (adm *AdminClient) GetBucketReplicationARN(ctx context.Context, rURL string) (arn string, err error) {
|
||||
// GetBucketTargetARN - gets Arn for this remote target
|
||||
func (adm *AdminClient) GetBucketTargetARN(ctx context.Context, rURL string) (arn string, err error) {
|
||||
queryValues := url.Values{}
|
||||
queryValues.Set("url", rURL)
|
||||
|
||||
reqData := requestData{
|
||||
relPath: adminAPIPrefix + "/get-bucket-replication-arn",
|
||||
relPath: adminAPIPrefix + "/get-bucket-target-arn",
|
||||
queryValues: queryValues,
|
||||
}
|
||||
|
||||
// Execute GET on /minio/admin/v3/list-bucket-replication-arn
|
||||
// Execute GET on /minio/admin/v3/list-bucket-target-arn
|
||||
resp, err := adm.executeMethod(ctx, http.MethodGet, reqData)
|
||||
|
||||
defer closeResponse(resp)
|
||||
@@ -157,7 +171,7 @@ func (adm *AdminClient) GetBucketReplicationARN(ctx context.Context, rURL string
|
||||
return arn, err
|
||||
}
|
||||
if arn == "" {
|
||||
return arn, fmt.Errorf("Missing Replication ARN")
|
||||
return arn, fmt.Errorf("Missing target ARN")
|
||||
}
|
||||
return arn, nil
|
||||
}
|
||||
Reference in New Issue
Block a user