Change mc replicate add|update to integrate create remote targets (#4403)
This commit is contained in:
@@ -18,292 +18,23 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/url"
|
||||
"path"
|
||||
"time"
|
||||
|
||||
humanize "github.com/dustin/go-humanize"
|
||||
"github.com/fatih/color"
|
||||
"github.com/minio/cli"
|
||||
json "github.com/minio/colorjson"
|
||||
"github.com/minio/madmin-go/v2"
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
"github.com/minio/minio-go/v7/pkg/s3utils"
|
||||
"github.com/minio/pkg/console"
|
||||
)
|
||||
|
||||
var adminBucketRemoteAddFlags = []cli.Flag{
|
||||
cli.StringFlag{
|
||||
Name: "path",
|
||||
Value: "auto",
|
||||
Usage: "bucket path lookup supported by the server. Valid options are '[on,off,auto]'",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "service",
|
||||
Usage: "type of service. Valid options are '[replication]'",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "region",
|
||||
Usage: "region of the destination bucket (optional)",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "bandwidth",
|
||||
Usage: "Set bandwidth limit in bits per second (K,B,G,T for metric and Ki,Bi,Gi,Ti for IEC units)",
|
||||
},
|
||||
cli.BoolFlag{
|
||||
Name: "sync",
|
||||
Usage: "enable synchronous replication for this target. Default is async",
|
||||
},
|
||||
cli.UintFlag{
|
||||
Name: "healthcheck-seconds",
|
||||
Usage: "health check duration in seconds",
|
||||
Value: 60,
|
||||
},
|
||||
cli.BoolFlag{
|
||||
Name: "disable-proxy",
|
||||
Usage: "disable proxying in active-active replication. If unset, default behavior is to proxy",
|
||||
},
|
||||
}
|
||||
|
||||
var adminBucketRemoteAddCmd = cli.Command{
|
||||
Name: "add",
|
||||
Usage: "add a new remote target",
|
||||
Action: mainAdminBucketRemoteAdd,
|
||||
OnUsageError: onUsageError,
|
||||
Before: setGlobalsFromContext,
|
||||
Flags: append(globalFlags, adminBucketRemoteAddFlags...),
|
||||
CustomHelpTemplate: `NAME:
|
||||
{{.HelpName}} - {{.Usage}}
|
||||
|
||||
USAGE:
|
||||
{{.HelpName}} TARGET http(s)://ACCESSKEY:SECRETKEY@DEST_URL/DEST_BUCKET [--path | --region | --bandwidth] --service
|
||||
|
||||
TARGET:
|
||||
Also called as alias/sourcebucketname
|
||||
|
||||
DEST_BUCKET:
|
||||
Also called as remote target bucket.
|
||||
|
||||
DEST_URL:
|
||||
Also called as remote endpoint.
|
||||
|
||||
ACCESSKEY:
|
||||
Also called as username.
|
||||
|
||||
SECRETKEY:
|
||||
Also called as password.
|
||||
|
||||
FLAGS:
|
||||
{{range .VisibleFlags}}{{.}}
|
||||
{{end}}
|
||||
EXAMPLES:
|
||||
1. Set a new replication target "targetbucket" in region "us-west-1" on https://minio.siteb.example.com for
|
||||
bucket 'sourcebucket'.
|
||||
{{.Prompt}} {{.HelpName}} sitea/sourcebucket https://foobar:foo12345@minio.siteb.example.com/targetbucket \
|
||||
--service "replication" --region "us-west-1"
|
||||
|
||||
2. Set a new synchronous replication target 'targetbucket' in region "us-west-1" on https://minio.siteb.example.com for
|
||||
bucket 'sourcebucket' with bandwidth set to 2 gigabits per second.
|
||||
{{.Prompt}} {{.HelpName}} sitea/sourcebucket https://foobar:foo12345@minio.siteb.example.com/targetbucket \
|
||||
--service "replication" --region "us-west-1 --bandwidth "2G" --sync
|
||||
`,
|
||||
}
|
||||
|
||||
// checkAdminBucketRemoteAddSyntax - validate all the passed arguments
|
||||
func checkAdminBucketRemoteAddSyntax(ctx *cli.Context) {
|
||||
argsNr := len(ctx.Args())
|
||||
if argsNr < 2 {
|
||||
showCommandHelpAndExit(ctx, 1) // last argument is exit code
|
||||
}
|
||||
if argsNr > 2 {
|
||||
fatalIf(errInvalidArgument().Trace(ctx.Args().Tail()...),
|
||||
"Incorrect number of arguments for remote add command.")
|
||||
}
|
||||
}
|
||||
|
||||
// RemoteMessage container for content message structure
|
||||
type RemoteMessage struct {
|
||||
op string
|
||||
Status string `json:"status"`
|
||||
AccessKey string `json:"accessKey,omitempty"`
|
||||
SecretKey string `json:"secretKey,omitempty"`
|
||||
SourceBucket string `json:"sourceBucket"`
|
||||
TargetURL string `json:"TargetURL,omitempty"`
|
||||
TargetBucket string `json:"TargetBucket,omitempty"`
|
||||
RemoteARN string `json:"RemoteARN,omitempty"`
|
||||
Path string `json:"path,omitempty"`
|
||||
Region string `json:"region,omitempty"`
|
||||
ServiceType string `json:"service"`
|
||||
Bandwidth int64 `json:"bandwidth"`
|
||||
ReplicationSync bool `json:"replicationSync"`
|
||||
Proxy bool `json:"proxy"`
|
||||
HealthCheckDuration time.Duration `json:"healthcheckDuration"`
|
||||
ResetID string `json:"resetID"`
|
||||
ResetBefore time.Time `json:"resetBeforeDate"`
|
||||
}
|
||||
|
||||
func (r RemoteMessage) String() string {
|
||||
switch r.op {
|
||||
case "ls":
|
||||
message := console.Colorize("TargetURL", fmt.Sprintf("%s ", r.TargetURL))
|
||||
message += console.Colorize("SourceBucket", r.SourceBucket)
|
||||
message += console.Colorize("Arrow", "->")
|
||||
message += console.Colorize("TargetBucket", r.TargetBucket)
|
||||
message += " "
|
||||
message += console.Colorize("ARN", r.RemoteARN)
|
||||
syncStr := " "
|
||||
if r.ReplicationSync && r.ServiceType == string(madmin.ReplicationService) {
|
||||
syncStr = "sync"
|
||||
}
|
||||
message += " " + console.Colorize("SyncLabel", syncStr)
|
||||
proxyStr := " "
|
||||
if r.Proxy && r.ServiceType == string(madmin.ReplicationService) {
|
||||
proxyStr = "proxy"
|
||||
}
|
||||
message += " "
|
||||
message += console.Colorize("ProxyLabel", proxyStr)
|
||||
return message
|
||||
case "rm":
|
||||
return console.Colorize("RemoteMessage", "Removed remote target for `"+r.SourceBucket+"` bucket successfully.")
|
||||
case "add":
|
||||
return console.Colorize("RemoteMessage", "Remote ARN = `"+r.RemoteARN+"`.")
|
||||
case "edit":
|
||||
return console.Colorize("RemoteMessage", "Remote target updated successfully for target with ARN:`"+r.RemoteARN+"`.")
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// JSON returns jsonified message
|
||||
func (r RemoteMessage) JSON() string {
|
||||
r.Status = "success"
|
||||
jsonMessageBytes, e := json.MarshalIndent(r, "", " ")
|
||||
fatalIf(probe.NewError(e), "Unable to marshal into JSON.")
|
||||
|
||||
return string(jsonMessageBytes)
|
||||
}
|
||||
|
||||
func extractCredentialURL(argURL string) (accessKey, secretKey string, u *url.URL) {
|
||||
var parsedURL string
|
||||
if hostKeyTokens.MatchString(argURL) {
|
||||
fatalIf(errInvalidArgument().Trace(argURL), "temporary tokens are not allowed for remote targets")
|
||||
}
|
||||
if hostKeys.MatchString(argURL) {
|
||||
parts := hostKeys.FindStringSubmatch(argURL)
|
||||
if len(parts) != 5 {
|
||||
fatalIf(errInvalidArgument().Trace(argURL), "Unsupported remote target format, please check --help")
|
||||
}
|
||||
accessKey = parts[2]
|
||||
secretKey = parts[3]
|
||||
parsedURL = fmt.Sprintf("%s%s", parts[1], parts[4])
|
||||
}
|
||||
var e error
|
||||
if parsedURL == "" {
|
||||
fatalIf(errInvalidArgument().Trace(argURL), "No valid credentials were detected")
|
||||
}
|
||||
u, e = url.Parse(parsedURL)
|
||||
if e != nil {
|
||||
fatalIf(errInvalidArgument().Trace(parsedURL), "Unsupported URL format %v", e)
|
||||
}
|
||||
|
||||
return accessKey, secretKey, u
|
||||
}
|
||||
|
||||
// fetchRemoteTarget - returns the dest bucket, dest endpoint, access and secret key
|
||||
func fetchRemoteTarget(cli *cli.Context) (sourceBucket string, bktTarget *madmin.BucketTarget) {
|
||||
args := cli.Args()
|
||||
argCount := len(args)
|
||||
if argCount < 2 {
|
||||
fatalIf(probe.NewError(fmt.Errorf("Missing Remote target configuration")), "Unable to parse remote target")
|
||||
}
|
||||
_, sourceBucket = url2Alias(args[0])
|
||||
p := cli.String("path")
|
||||
if !isValidPath(p) {
|
||||
fatalIf(errInvalidArgument().Trace(p),
|
||||
"Unrecognized bucket path style. Valid options are `[on,off, auto]`.")
|
||||
}
|
||||
|
||||
tgtURL := args[1]
|
||||
accessKey, secretKey, u := extractCredentialURL(tgtURL)
|
||||
var tgtBucket string
|
||||
if u.Path != "" {
|
||||
tgtBucket = path.Clean(u.Path[1:])
|
||||
}
|
||||
if e := s3utils.CheckValidBucketName(tgtBucket); e != nil {
|
||||
fatalIf(probe.NewError(e).Trace(tgtURL), "Invalid target bucket specified")
|
||||
}
|
||||
|
||||
serviceType := cli.String("service")
|
||||
if !madmin.ServiceType(serviceType).IsValid() {
|
||||
fatalIf(errInvalidArgument().Trace(serviceType), "Invalid service type. Valid option is `[replication]`.")
|
||||
}
|
||||
if cli.IsSet("sync") && serviceType != string(madmin.ReplicationService) {
|
||||
fatalIf(errInvalidArgument(), "Invalid usage. --sync flag applies only to replication service")
|
||||
}
|
||||
bandwidthStr := cli.String("bandwidth")
|
||||
bandwidth, err := getBandwidthInBytes(bandwidthStr)
|
||||
if err != nil {
|
||||
fatalIf(errInvalidArgument().Trace(bandwidthStr), "Invalid bandwidth number")
|
||||
}
|
||||
console.SetColor(cred, color.New(color.FgYellow, color.Italic))
|
||||
creds := &madmin.Credentials{AccessKey: accessKey, SecretKey: secretKey}
|
||||
disableproxy := cli.Bool("disable-proxy")
|
||||
bktTarget = &madmin.BucketTarget{
|
||||
TargetBucket: tgtBucket,
|
||||
Secure: u.Scheme == "https",
|
||||
Credentials: creds,
|
||||
Endpoint: u.Host,
|
||||
Path: p,
|
||||
API: "s3v4",
|
||||
Type: madmin.ServiceType(serviceType),
|
||||
Region: cli.String("region"),
|
||||
BandwidthLimit: int64(bandwidth),
|
||||
ReplicationSync: cli.Bool("sync"),
|
||||
DisableProxy: disableproxy,
|
||||
HealthCheckDuration: time.Duration(cli.Uint("healthcheck-seconds")) * time.Second,
|
||||
}
|
||||
return sourceBucket, bktTarget
|
||||
}
|
||||
|
||||
func getBandwidthInBytes(bandwidthStr string) (bandwidth uint64, err error) {
|
||||
if bandwidthStr != "" {
|
||||
bandwidth, err = humanize.ParseBytes(bandwidthStr)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
bandwidth = bandwidth / 8
|
||||
return
|
||||
Flags: globalFlags,
|
||||
Hidden: true,
|
||||
HideHelp: true,
|
||||
}
|
||||
|
||||
// mainAdminBucketRemoteAdd is the handle for "mc admin bucket remote set" command.
|
||||
func mainAdminBucketRemoteAdd(ctx *cli.Context) error {
|
||||
checkAdminBucketRemoteAddSyntax(ctx)
|
||||
console.SetColor("RemoteMessage", color.New(color.FgGreen))
|
||||
|
||||
// Get the alias parameter from cli
|
||||
args := ctx.Args()
|
||||
aliasedURL := args.Get(0)
|
||||
// Create a new MinIO Admin Client
|
||||
client, cerr := newAdminClient(aliasedURL)
|
||||
fatalIf(cerr, "Unable to initialize admin connection.")
|
||||
|
||||
sourceBucket, bktTarget := fetchRemoteTarget(ctx)
|
||||
arn, e := client.SetRemoteTarget(globalContext, sourceBucket, bktTarget)
|
||||
if e != nil {
|
||||
fatalIf(probe.NewError(e).Trace(args...), "Unable to configure remote target")
|
||||
}
|
||||
|
||||
printMsg(RemoteMessage{
|
||||
op: ctx.Command.Name,
|
||||
TargetURL: bktTarget.URL().String(),
|
||||
TargetBucket: bktTarget.TargetBucket,
|
||||
AccessKey: bktTarget.Credentials.AccessKey,
|
||||
SourceBucket: sourceBucket,
|
||||
RemoteARN: arn,
|
||||
ReplicationSync: bktTarget.ReplicationSync,
|
||||
Proxy: !bktTarget.DisableProxy,
|
||||
})
|
||||
|
||||
console.Infoln("Please use 'mc replicate add'")
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -18,230 +18,23 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"path"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/fatih/color"
|
||||
"github.com/minio/cli"
|
||||
"github.com/minio/madmin-go/v2"
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
"github.com/minio/minio-go/v7/pkg/s3utils"
|
||||
"github.com/minio/pkg/console"
|
||||
)
|
||||
|
||||
var adminBucketRemoteEditFlags = []cli.Flag{
|
||||
cli.StringFlag{
|
||||
Name: "arn",
|
||||
Usage: "ARN of target",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "sync",
|
||||
Usage: "enable synchronous replication for this target. Valid values are enable,disable.Defaults to disable if unset",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "proxy",
|
||||
Usage: "enable proxying in active-active replication. Valid values are enable,disable.By default proxying is enabled.",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "bandwidth",
|
||||
Usage: "Set bandwidth limit in bits per second (K,B,G,T for metric and Ki,Bi,Gi,Ti for IEC units)",
|
||||
},
|
||||
cli.UintFlag{
|
||||
Name: "healthcheck-seconds",
|
||||
Usage: "health check duration in seconds",
|
||||
Value: 60,
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "path",
|
||||
Value: "auto",
|
||||
Usage: "bucket path lookup supported by the server. Valid options are '[on,off,auto]'",
|
||||
},
|
||||
}
|
||||
|
||||
var adminBucketRemoteEditCmd = cli.Command{
|
||||
Name: "edit",
|
||||
Usage: "edit remote target",
|
||||
Action: mainAdminBucketRemoteEdit,
|
||||
Before: setGlobalsFromContext,
|
||||
OnUsageError: onUsageError,
|
||||
Flags: append(globalFlags, adminBucketRemoteEditFlags...),
|
||||
CustomHelpTemplate: `NAME:
|
||||
{{.HelpName}} - {{.Usage}}
|
||||
|
||||
USAGE:
|
||||
{{.HelpName}} TARGET http(s)://ACCESSKEY:SECRETKEY@DEST_URL/DEST_BUCKET --arn arn
|
||||
|
||||
TARGET:
|
||||
Also called as alias/sourcebucketname
|
||||
|
||||
DEST_BUCKET:
|
||||
Also called as remote target bucket.
|
||||
|
||||
DEST_URL:
|
||||
Also called as remote endpoint.
|
||||
|
||||
ACCESSKEY:
|
||||
Also called as username.
|
||||
|
||||
SECRETKEY:
|
||||
Also called as password.
|
||||
|
||||
FLAGS:
|
||||
{{range .VisibleFlags}}{{.}}
|
||||
{{end}}
|
||||
EXAMPLES:
|
||||
1. Edit credentials for existing remote target with arn where a remote target has been configured between sourcebucket on sitea to targetbucket on siteb.
|
||||
{{.DisableHistory}}
|
||||
{{.Prompt}} {{.HelpName}} sitea/sourcebucket \
|
||||
https://foobar:newpassword@minio.siteb.example.com/targetbucket \
|
||||
--arn "arn:minio:replication:us-west-1:993bc6b6-accd-45e3-884f-5f3e652aed2a:dest1"
|
||||
{{.EnableHistory}}
|
||||
|
||||
2. Edit remote target for sourceBucket on sitea with specified ARN to disable proxying and enable synchronous replication
|
||||
{{.Prompt}} {{.HelpName}} sitea/sourcebucket --sync "enable" --proxy "disable"
|
||||
--arn "arn:minio:replication:us-west-1:993bc6b6-accd-45e3-884f-5f3e652aed2a:dest1"
|
||||
`,
|
||||
}
|
||||
|
||||
// checkAdminBucketRemoteEditSyntax - validate all the passed arguments
|
||||
func checkAdminBucketRemoteEditSyntax(ctx *cli.Context) {
|
||||
argsNr := len(ctx.Args())
|
||||
if argsNr > 2 || argsNr == 0 {
|
||||
showCommandHelpAndExit(ctx, 1) // last argument is exit code
|
||||
}
|
||||
if !ctx.IsSet("arn") {
|
||||
fatalIf(errInvalidArgument().Trace(ctx.Args()...), "--arn flag needs to be set")
|
||||
}
|
||||
}
|
||||
|
||||
// modifyRemoteTarget - modifies the dest credentials or updates sync , disable-proxy settings
|
||||
func modifyRemoteTarget(cli *cli.Context, targets []madmin.BucketTarget) (*madmin.BucketTarget, []madmin.TargetUpdateType) {
|
||||
args := cli.Args()
|
||||
foundIdx := -1
|
||||
arn := cli.String("arn")
|
||||
for i, t := range targets {
|
||||
if t.Arn == arn {
|
||||
foundIdx = i
|
||||
break
|
||||
}
|
||||
}
|
||||
if foundIdx < 0 {
|
||||
fatalIf(errInvalidArgument().Trace(args...), "Unable to edit remote target - `"+arn+"` not found")
|
||||
}
|
||||
var ops []madmin.TargetUpdateType
|
||||
bktTarget := targets[foundIdx].Clone()
|
||||
if cli.IsSet("sync") {
|
||||
syncState := strings.ToLower(cli.String("sync"))
|
||||
switch syncState {
|
||||
case "enable", "disable":
|
||||
bktTarget.ReplicationSync = syncState == "enable"
|
||||
ops = append(ops, madmin.SyncUpdateType)
|
||||
default:
|
||||
fatalIf(errInvalidArgument().Trace(args...), "--sync can be either [enable|disable]")
|
||||
}
|
||||
}
|
||||
if cli.IsSet("proxy") {
|
||||
proxyState := strings.ToLower(cli.String("proxy"))
|
||||
switch proxyState {
|
||||
case "enable", "disable":
|
||||
bktTarget.DisableProxy = proxyState == "disable"
|
||||
ops = append(ops, madmin.ProxyUpdateType)
|
||||
|
||||
default:
|
||||
fatalIf(errInvalidArgument().Trace(args...), "--proxy can be either [enable|disable]")
|
||||
}
|
||||
}
|
||||
|
||||
if len(args) == 2 {
|
||||
_, sourceBucket := url2Alias(args[0])
|
||||
|
||||
tgtURL := args[1]
|
||||
accessKey, secretKey, u := extractCredentialURL(tgtURL)
|
||||
var tgtBucket string
|
||||
if u.Path != "" {
|
||||
tgtBucket = path.Clean(u.Path[1:])
|
||||
}
|
||||
if e := s3utils.CheckValidBucketName(tgtBucket); e != nil {
|
||||
fatalIf(probe.NewError(e).Trace(tgtURL), "Invalid target bucket specified")
|
||||
}
|
||||
secure := u.Scheme == "https"
|
||||
host := u.Host
|
||||
if u.Port() == "" {
|
||||
port := 80
|
||||
if secure {
|
||||
port = 443
|
||||
}
|
||||
host = host + ":" + strconv.Itoa(port)
|
||||
}
|
||||
console.SetColor(cred, color.New(color.FgYellow, color.Italic))
|
||||
creds := &madmin.Credentials{AccessKey: accessKey, SecretKey: secretKey}
|
||||
if tgtBucket != bktTarget.TargetBucket {
|
||||
fatalIf(errInvalidArgument().Trace(args...), "configured remote target bucket `"+tgtBucket+"` does not match "+bktTarget.TargetBucket+"` for this ARN `"+bktTarget.Arn+"`")
|
||||
}
|
||||
if sourceBucket != bktTarget.SourceBucket {
|
||||
fatalIf(errInvalidArgument().Trace(args...), "configured source bucket `"+sourceBucket+"` does not match "+bktTarget.SourceBucket+"` for this ARN `"+bktTarget.Arn+"`")
|
||||
}
|
||||
bktTarget.TargetBucket = tgtBucket
|
||||
bktTarget.Secure = secure
|
||||
bktTarget.Credentials = creds
|
||||
bktTarget.Endpoint = host
|
||||
ops = append(ops, madmin.CredentialsUpdateType)
|
||||
}
|
||||
if cli.IsSet("bandwidth") {
|
||||
bandwidthStr := cli.String("bandwidth")
|
||||
bandwidth, err := getBandwidthInBytes(bandwidthStr)
|
||||
if err != nil {
|
||||
fatalIf(errInvalidArgument().Trace(bandwidthStr), "Invalid bandwidth number")
|
||||
}
|
||||
bktTarget.BandwidthLimit = int64(bandwidth)
|
||||
ops = append(ops, madmin.BandwidthLimitUpdateType)
|
||||
|
||||
}
|
||||
if cli.IsSet("healthcheck-seconds") {
|
||||
bktTarget.HealthCheckDuration = time.Duration(cli.Uint("healthcheck-seconds")) * time.Second
|
||||
ops = append(ops, madmin.HealthCheckDurationUpdateType)
|
||||
}
|
||||
if cli.IsSet("path") {
|
||||
bktTarget.Path = cli.String("path")
|
||||
ops = append(ops, madmin.PathUpdateType)
|
||||
}
|
||||
return &bktTarget, ops
|
||||
Flags: globalFlags,
|
||||
HideHelp: true,
|
||||
Hidden: true,
|
||||
}
|
||||
|
||||
// mainAdminBucketRemoteEdit is the handle for "mc admin bucket remote edit" command.
|
||||
func mainAdminBucketRemoteEdit(ctx *cli.Context) error {
|
||||
checkAdminBucketRemoteEditSyntax(ctx)
|
||||
|
||||
console.SetColor("RemoteMessage", color.New(color.FgGreen))
|
||||
|
||||
// Get the alias parameter from cli
|
||||
args := ctx.Args()
|
||||
aliasedURL := args.Get(0)
|
||||
// Create a new MinIO Admin Client
|
||||
client, cerr := newAdminClient(aliasedURL)
|
||||
fatalIf(cerr, "Unable to initialize admin connection.")
|
||||
_, sourceBucket := url2Alias(args[0])
|
||||
|
||||
targets, e := client.ListRemoteTargets(globalContext, sourceBucket, "")
|
||||
fatalIf(probe.NewError(e).Trace(args...), "Unable to fetch remote target.")
|
||||
|
||||
bktTarget, ops := modifyRemoteTarget(ctx, targets)
|
||||
|
||||
arn, e := client.UpdateRemoteTarget(globalContext, bktTarget, ops...)
|
||||
if e != nil {
|
||||
fatalIf(probe.NewError(e).Trace(args...), "Unable to update remote target `"+bktTarget.Endpoint+"` from `"+bktTarget.SourceBucket+"` -> `"+bktTarget.TargetBucket+"`")
|
||||
}
|
||||
|
||||
printMsg(RemoteMessage{
|
||||
op: ctx.Command.Name,
|
||||
TargetURL: bktTarget.URL().String(),
|
||||
TargetBucket: bktTarget.TargetBucket,
|
||||
AccessKey: bktTarget.Credentials.AccessKey,
|
||||
SourceBucket: bktTarget.SourceBucket,
|
||||
RemoteARN: arn,
|
||||
})
|
||||
|
||||
console.Infoln("Please use 'mc replicate update'")
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -1,164 +0,0 @@
|
||||
// Copyright (c) 2015-2022 MinIO, Inc.
|
||||
//
|
||||
// This file is part of MinIO Object Storage stack
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/fatih/color"
|
||||
"github.com/minio/cli"
|
||||
"github.com/minio/madmin-go/v2"
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
"github.com/minio/pkg/console"
|
||||
)
|
||||
|
||||
var adminBucketRemoteListFlags = []cli.Flag{
|
||||
cli.StringFlag{
|
||||
Name: "service",
|
||||
Usage: "type of service. valid options are '[replication]'",
|
||||
},
|
||||
}
|
||||
|
||||
var adminBucketRemoteListCmd = cli.Command{
|
||||
Name: "ls",
|
||||
Usage: "list remote target ARN(s)",
|
||||
Action: mainAdminBucketRemoteList,
|
||||
OnUsageError: onUsageError,
|
||||
Before: setGlobalsFromContext,
|
||||
Flags: append(globalFlags, adminBucketRemoteListFlags...),
|
||||
CustomHelpTemplate: `NAME:
|
||||
{{.HelpName}} - {{.Usage}}
|
||||
|
||||
USAGE:
|
||||
{{.HelpName}} TARGET
|
||||
|
||||
FLAGS:
|
||||
{{range .VisibleFlags}}{{.}}
|
||||
{{end}}
|
||||
EXAMPLES:
|
||||
1. Get remote bucket target for replication on MinIO server for bucket 'srcbucket'.
|
||||
{{.Prompt}} {{.HelpName}} myminio/srcbucket --service "replication"
|
||||
|
||||
2. List all remote bucket target(s) on MinIO server for bucket 'srcbucket'.
|
||||
{{.Prompt}} {{.HelpName}} myminio/srcbucket
|
||||
|
||||
3. List all remote bucket target(s) on MinIO tenant.
|
||||
{{.Prompt}} {{.HelpName}} myminio
|
||||
`,
|
||||
}
|
||||
|
||||
// checkAdminBucketRemoteListSyntax - validate all the passed arguments
|
||||
func checkAdminBucketRemoteListSyntax(ctx *cli.Context) {
|
||||
if len(ctx.Args()) != 1 {
|
||||
showCommandHelpAndExit(ctx, 1) // last argument is exit code
|
||||
}
|
||||
}
|
||||
|
||||
// mainAdminBucketRemoteList is the handle for "mc admin bucket remote list" command.
|
||||
func mainAdminBucketRemoteList(ctx *cli.Context) error {
|
||||
checkAdminBucketRemoteListSyntax(ctx)
|
||||
|
||||
// Additional command specific theme customization.
|
||||
console.SetColor("RemoteListMessage", color.New(color.Bold, color.FgHiGreen))
|
||||
console.SetColor("RemoteListEmpty", color.New(color.FgYellow))
|
||||
console.SetColor("SourceBucket", color.New(color.FgYellow))
|
||||
console.SetColor("TargetBucket", color.New(color.FgYellow))
|
||||
console.SetColor("TargetURL", color.New(color.FgHiWhite))
|
||||
console.SetColor("ARN", color.New(color.FgCyan))
|
||||
console.SetColor("Arrow", color.New(color.FgHiWhite))
|
||||
console.SetColor("SyncLabel", color.New(color.FgHiYellow))
|
||||
console.SetColor("ProxyLabel", color.New(color.FgHiYellow))
|
||||
|
||||
// Get the alias parameter from cli
|
||||
args := ctx.Args()
|
||||
aliasedURL := args.Get(0)
|
||||
aliasedURL = filepath.Clean(aliasedURL)
|
||||
_, sourceBucket := url2Alias(aliasedURL)
|
||||
// Create a new MinIO Admin Client
|
||||
client, err := newAdminClient(aliasedURL)
|
||||
fatalIf(err, "Unable to initialize admin connection.")
|
||||
targets, e := client.ListRemoteTargets(globalContext, sourceBucket, ctx.String("service"))
|
||||
fatalIf(probe.NewError(e).Trace(args...), "Unable to list remote target")
|
||||
printRemotes(ctx, aliasedURL, targets)
|
||||
return nil
|
||||
}
|
||||
|
||||
func printRemotes(ctx *cli.Context, urlStr string, targets []madmin.BucketTarget) {
|
||||
maxURLLen := 10
|
||||
maxTgtLen := 6
|
||||
maxSrcLen := 6
|
||||
maxArnLen := 3
|
||||
|
||||
if !globalJSON {
|
||||
if len(targets) == 0 {
|
||||
console.Print(console.Colorize("RemoteListEmpty", fmt.Sprintf("No remote targets found for `%s`. \n", urlStr)))
|
||||
return
|
||||
}
|
||||
for _, t := range targets {
|
||||
l := len(t.Endpoint)
|
||||
if l > maxURLLen {
|
||||
maxURLLen = l
|
||||
}
|
||||
if len(t.TargetBucket) > maxTgtLen {
|
||||
maxTgtLen = len(t.TargetBucket)
|
||||
}
|
||||
if len(t.SourceBucket) > maxSrcLen {
|
||||
maxSrcLen = len(t.SourceBucket)
|
||||
}
|
||||
if len(t.Arn) > maxArnLen {
|
||||
maxArnLen = len(t.Arn)
|
||||
}
|
||||
}
|
||||
if maxURLLen > 0 {
|
||||
console.Println(console.Colorize("RemoteListMessage", fmt.Sprintf("%-*.*s %-*.*s->%-*.*s %-*.*s %s %s", maxURLLen+8, maxURLLen+8, "Remote URL", maxSrcLen, maxSrcLen, "Source", maxTgtLen, maxTgtLen, "Target", maxArnLen, maxArnLen, "ARN", "SYNC", "PROXY")))
|
||||
}
|
||||
}
|
||||
for _, target := range targets {
|
||||
targetURL := target.URL().String()
|
||||
if !globalJSON {
|
||||
if maxURLLen > 0 {
|
||||
targetURL = fmt.Sprintf("%-*.*s", maxURLLen+8, maxURLLen+8, target.URL().String())
|
||||
}
|
||||
if maxTgtLen > 0 {
|
||||
target.TargetBucket = fmt.Sprintf("%-*.*s", maxTgtLen, maxTgtLen, target.TargetBucket)
|
||||
}
|
||||
|
||||
if maxSrcLen > 0 {
|
||||
target.SourceBucket = fmt.Sprintf("%-*.*s", maxSrcLen, maxSrcLen, target.SourceBucket)
|
||||
}
|
||||
if maxArnLen > 0 {
|
||||
target.Arn = fmt.Sprintf("%-*.*s", maxArnLen, maxArnLen, target.Arn)
|
||||
}
|
||||
}
|
||||
printMsg(RemoteMessage{
|
||||
op: ctx.Command.Name,
|
||||
AccessKey: target.Credentials.AccessKey,
|
||||
TargetBucket: target.TargetBucket,
|
||||
TargetURL: targetURL,
|
||||
SourceBucket: target.SourceBucket,
|
||||
RemoteARN: target.Arn,
|
||||
ServiceType: string(target.Type),
|
||||
ReplicationSync: target.ReplicationSync,
|
||||
Bandwidth: target.BandwidthLimit,
|
||||
Proxy: !target.DisableProxy,
|
||||
ResetID: target.ResetID,
|
||||
ResetBefore: target.ResetBeforeDate,
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -22,8 +22,8 @@ import "github.com/minio/cli"
|
||||
var adminBucketRemoteSubcommands = []cli.Command{
|
||||
adminBucketRemoteAddCmd,
|
||||
adminBucketRemoteEditCmd,
|
||||
adminBucketRemoteListCmd,
|
||||
adminBucketRemoteRmCmd,
|
||||
|
||||
adminBwInfoCmd,
|
||||
}
|
||||
|
||||
|
||||
@@ -18,76 +18,24 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"github.com/fatih/color"
|
||||
"github.com/minio/cli"
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
"github.com/minio/pkg/console"
|
||||
)
|
||||
|
||||
var adminBucketRemoteRmFlags = []cli.Flag{
|
||||
cli.StringFlag{
|
||||
Name: "arn",
|
||||
Usage: "ARN to be removed",
|
||||
},
|
||||
}
|
||||
|
||||
var adminBucketRemoteRmCmd = cli.Command{
|
||||
Name: "rm",
|
||||
Usage: "remove configured remote target",
|
||||
Action: mainAdminBucketRemoteRemove,
|
||||
OnUsageError: onUsageError,
|
||||
Before: setGlobalsFromContext,
|
||||
Flags: append(globalFlags, adminBucketRemoteRmFlags...),
|
||||
CustomHelpTemplate: `NAME:
|
||||
{{.HelpName}} - {{.Usage}}
|
||||
|
||||
USAGE:
|
||||
{{.HelpName}} TARGET
|
||||
|
||||
FLAGS:
|
||||
{{range .VisibleFlags}}{{.}}
|
||||
{{end}}
|
||||
EXAMPLES:
|
||||
1. Remove existing remote target with arn "arn:minio:replication:us-west-1:993bc6b6-accd-45e3-884f-5f3e652aed2a:dest1"
|
||||
for bucket srcbucket on MinIO server.
|
||||
{{.Prompt}} {{.HelpName}} myminio/srcbucket --arn "arn:minio:replication:us-west-1:993bc6b6-accd-45e3-884f-5f3e652aed2a:dest1"
|
||||
`,
|
||||
}
|
||||
|
||||
// checkAdminBucketRemoteRemoveSyntax - validate all the passed arguments
|
||||
func checkAdminBucketRemoteRemoveSyntax(ctx *cli.Context) {
|
||||
if len(ctx.Args()) != 1 {
|
||||
showCommandHelpAndExit(ctx, 1) // last argument is exit code
|
||||
}
|
||||
Flags: globalFlags,
|
||||
HideHelp: true,
|
||||
Hidden: true,
|
||||
}
|
||||
|
||||
// mainAdminBucketRemoteRemove is the handle for "mc admin bucket remote rm" command.
|
||||
func mainAdminBucketRemoteRemove(ctx *cli.Context) error {
|
||||
checkAdminBucketRemoteRemoveSyntax(ctx)
|
||||
|
||||
console.SetColor("RemoteMessage", color.New(color.FgGreen))
|
||||
|
||||
// Get the alias parameter from cli
|
||||
args := ctx.Args()
|
||||
aliasedURL := args.Get(0)
|
||||
// Create a new MinIO Admin Client
|
||||
client, cerr := newAdminClient(aliasedURL)
|
||||
fatalIf(cerr.Trace(aliasedURL), "Unable to initialize admin connection.")
|
||||
_, sourceBucket := url2Alias(args[0])
|
||||
if sourceBucket == "" {
|
||||
fatalIf(errInvalidArgument(), "Source bucket not specified in `"+args[0]+"`.")
|
||||
}
|
||||
arn := ctx.String("arn")
|
||||
if arn == "" {
|
||||
fatalIf(errInvalidArgument(), "ARN needs to be specified.")
|
||||
}
|
||||
fatalIf(probe.NewError(client.RemoveRemoteTarget(globalContext, sourceBucket, arn)).Trace(args...), "Unable to remove remote target")
|
||||
|
||||
printMsg(RemoteMessage{
|
||||
op: ctx.Command.Name,
|
||||
SourceBucket: sourceBucket,
|
||||
RemoteARN: arn,
|
||||
})
|
||||
console.Infoln("Please use 'mc replicate rm'")
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -421,7 +421,6 @@ var completeCmds = map[string]complete.Predictor{
|
||||
|
||||
"/admin/bucket/remote/add": aliasCompleter,
|
||||
"/admin/bucket/remote/edit": aliasCompleter,
|
||||
"/admin/bucket/remote/ls": aliasCompleter,
|
||||
"/admin/bucket/remote/rm": aliasCompleter,
|
||||
"/admin/bucket/remote/bandwidth": aliasCompleter,
|
||||
"/admin/bucket/quota": aliasCompleter,
|
||||
|
||||
+138
-11
@@ -20,21 +20,28 @@ package cmd
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"path"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/dustin/go-humanize"
|
||||
"github.com/fatih/color"
|
||||
"github.com/minio/cli"
|
||||
json "github.com/minio/colorjson"
|
||||
"github.com/minio/madmin-go/v2"
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
"github.com/minio/minio-go/v7/pkg/replication"
|
||||
"github.com/minio/minio-go/v7/pkg/s3utils"
|
||||
"github.com/minio/pkg/console"
|
||||
)
|
||||
|
||||
var replicateAddFlags = []cli.Flag{
|
||||
cli.StringFlag{
|
||||
Name: "arn",
|
||||
Usage: "unique role ARN",
|
||||
Name: "arn",
|
||||
Usage: "unique role ARN",
|
||||
Hidden: true,
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "id",
|
||||
@@ -65,6 +72,32 @@ var replicateAddFlags = []cli.Flag{
|
||||
Value: `delete-marker,delete,existing-objects,metadata-sync`,
|
||||
Usage: `comma separated list to enable replication of soft deletes, permanent deletes, existing objects and metadata sync`,
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "path",
|
||||
Value: "auto",
|
||||
Usage: "bucket path lookup supported by the server. Valid options are '[on,off,auto]'",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "region",
|
||||
Usage: "region of the destination bucket (optional)",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "bandwidth",
|
||||
Usage: "Set bandwidth limit in bits per second (K,B,G,T for metric and Ki,Bi,Gi,Ti for IEC units)",
|
||||
},
|
||||
cli.BoolFlag{
|
||||
Name: "sync",
|
||||
Usage: "enable synchronous replication for this target. Default is async",
|
||||
},
|
||||
cli.UintFlag{
|
||||
Name: "healthcheck-seconds",
|
||||
Usage: "health check interval in seconds",
|
||||
Value: 60,
|
||||
},
|
||||
cli.BoolFlag{
|
||||
Name: "disable-proxy",
|
||||
Usage: "disable proxying in active-active replication. If unset, default behavior is to proxy",
|
||||
},
|
||||
}
|
||||
|
||||
var replicateAddCmd = cli.Command{
|
||||
@@ -85,23 +118,23 @@ FLAGS:
|
||||
{{end}}
|
||||
EXAMPLES:
|
||||
1. Add replication configuration rule on bucket "mybucket" for alias "myminio" to replicate all operations in an active-active replication setup.
|
||||
{{.Prompt}} {{.HelpName}} myminio/mybucket --remote-bucket "arn:minio:replica::c5be6b16-769d-432a-9ef1-4567081f3566:destbucket" \
|
||||
--priority 1
|
||||
{{.Prompt}} {{.HelpName}} myminio/mybucket --remote-bucket https://foobar:foo12345@minio.siteb.example.com/targetbucket \
|
||||
--priority 1
|
||||
|
||||
2. Add replication configuration rule on bucket "mybucket" for alias "myminio" to replicate all objects with tags
|
||||
"key1=value1, key2=value2" to destbucket.
|
||||
{{.Prompt}} {{.HelpName}} myminio/mybucket --remote-bucket "arn:minio:replica::c5be6b16-769d-432a-9ef1-4567081f3566:destbucket" \
|
||||
--tags "key1=value1&key2=value2" \
|
||||
"key1=value1, key2=value2" to targetbucket synchronously with bandwidth set to 2 gigabits per second.
|
||||
{{.Prompt}} {{.HelpName}} myminio/mybucket --remote-bucket https://foobar:foo12345@minio.siteb.example.com/targetbucket \
|
||||
--tags "key1=value1&key2=value2" --bandwidth "2G" --sync \
|
||||
--priority 1
|
||||
|
||||
3. Disable a replication configuration rule on bucket "mybucket" for alias "myminio".
|
||||
{{.Prompt}} {{.HelpName}} myminio/mybucket --remote-bucket "arn:minio:replica::c5be6b16-769d-432a-9ef1-4567081f3566:destbucket" \
|
||||
{{.Prompt}} {{.HelpName}} myminio/mybucket --remote-bucket https://foobar:foo12345@minio.siteb.example.com/targetbucket \
|
||||
--tags "key1=value1&key2=value2" \
|
||||
--priority 1 --disable
|
||||
|
||||
4. Add replication configuration rule with existing object replication, delete marker replication and versioned deletes
|
||||
enabled on bucket "mybucket" for alias "myminio".
|
||||
{{.Prompt}} {{.HelpName}} myminio/mybucket --remote-bucket "arn:minio:replica::c5be6b16-769d-432a-9ef1-4567081f3566:destbucket" \
|
||||
{{.Prompt}} {{.HelpName}} myminio/mybucket --remote-bucket https://foobar:foo12345@minio.siteb.example.com/targetbucket \
|
||||
--replicate "existing-objects,delete,delete-marker" \
|
||||
--priority 1
|
||||
`,
|
||||
@@ -143,6 +176,91 @@ func (l replicateAddMessage) String() string {
|
||||
return console.Colorize("replicateAddMessage", "Replication configuration rule applied to "+l.URL+" successfully.")
|
||||
}
|
||||
|
||||
func extractCredentialURL(argURL string) (accessKey, secretKey string, u *url.URL) {
|
||||
var parsedURL string
|
||||
if hostKeyTokens.MatchString(argURL) {
|
||||
fatalIf(errInvalidArgument().Trace(argURL), "temporary tokens are not allowed for remote targets")
|
||||
}
|
||||
if hostKeys.MatchString(argURL) {
|
||||
parts := hostKeys.FindStringSubmatch(argURL)
|
||||
if len(parts) != 5 {
|
||||
fatalIf(errInvalidArgument().Trace(argURL), "Unsupported remote target format, please check --help")
|
||||
}
|
||||
accessKey = parts[2]
|
||||
secretKey = parts[3]
|
||||
parsedURL = fmt.Sprintf("%s%s", parts[1], parts[4])
|
||||
}
|
||||
var e error
|
||||
if parsedURL == "" {
|
||||
fatalIf(errInvalidArgument().Trace(argURL), "No valid credentials were detected")
|
||||
}
|
||||
u, e = url.Parse(parsedURL)
|
||||
if e != nil {
|
||||
fatalIf(errInvalidArgument().Trace(parsedURL), "Unsupported URL format %v", e)
|
||||
}
|
||||
|
||||
return accessKey, secretKey, u
|
||||
}
|
||||
|
||||
// fetchRemoteTarget - returns the dest bucket, dest endpoint, access and secret key
|
||||
func fetchRemoteTarget(cli *cli.Context) (sourceBucket string, bktTarget *madmin.BucketTarget) {
|
||||
args := cli.Args()
|
||||
if !cli.IsSet("remote-bucket") {
|
||||
fatalIf(probe.NewError(fmt.Errorf("missing Remote target configuration")), "Unable to parse remote target")
|
||||
}
|
||||
_, sourceBucket = url2Alias(args[0])
|
||||
p := cli.String("path")
|
||||
if !isValidPath(p) {
|
||||
fatalIf(errInvalidArgument().Trace(p),
|
||||
"Unrecognized bucket path style. Valid options are `[on,off, auto]`.")
|
||||
}
|
||||
|
||||
tgtURL := cli.String("remote-bucket")
|
||||
accessKey, secretKey, u := extractCredentialURL(tgtURL)
|
||||
var tgtBucket string
|
||||
if u.Path != "" {
|
||||
tgtBucket = path.Clean(u.Path[1:])
|
||||
}
|
||||
if e := s3utils.CheckValidBucketName(tgtBucket); e != nil {
|
||||
fatalIf(probe.NewError(e).Trace(tgtURL), "Invalid target bucket specified")
|
||||
}
|
||||
|
||||
bandwidthStr := cli.String("bandwidth")
|
||||
bandwidth, err := getBandwidthInBytes(bandwidthStr)
|
||||
if err != nil {
|
||||
fatalIf(errInvalidArgument().Trace(bandwidthStr), "Invalid bandwidth number")
|
||||
}
|
||||
console.SetColor(cred, color.New(color.FgYellow, color.Italic))
|
||||
creds := &madmin.Credentials{AccessKey: accessKey, SecretKey: secretKey}
|
||||
disableproxy := cli.Bool("disable-proxy")
|
||||
bktTarget = &madmin.BucketTarget{
|
||||
TargetBucket: tgtBucket,
|
||||
Secure: u.Scheme == "https",
|
||||
Credentials: creds,
|
||||
Endpoint: u.Host,
|
||||
Path: p,
|
||||
API: "s3v4",
|
||||
Type: madmin.ServiceType("replication"),
|
||||
Region: cli.String("region"),
|
||||
BandwidthLimit: int64(bandwidth),
|
||||
ReplicationSync: cli.Bool("sync"),
|
||||
DisableProxy: disableproxy,
|
||||
HealthCheckDuration: time.Duration(cli.Uint("healthcheck-seconds")) * time.Second,
|
||||
}
|
||||
return sourceBucket, bktTarget
|
||||
}
|
||||
|
||||
func getBandwidthInBytes(bandwidthStr string) (bandwidth uint64, err error) {
|
||||
if bandwidthStr != "" {
|
||||
bandwidth, err = humanize.ParseBytes(bandwidthStr)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
bandwidth = bandwidth / 8
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func mainReplicateAdd(cliCtx *cli.Context) error {
|
||||
ctx, cancelReplicateAdd := context.WithCancel(globalContext)
|
||||
defer cancelReplicateAdd()
|
||||
@@ -154,6 +272,16 @@ func mainReplicateAdd(cliCtx *cli.Context) error {
|
||||
// Get the alias parameter from cli
|
||||
args := cliCtx.Args()
|
||||
aliasedURL := args.Get(0)
|
||||
|
||||
// Create a new MinIO Admin Client
|
||||
admclient, cerr := newAdminClient(aliasedURL)
|
||||
fatalIf(cerr, "Unable to initialize admin connection.")
|
||||
|
||||
sourceBucket, bktTarget := fetchRemoteTarget(cliCtx)
|
||||
arn, e := admclient.SetRemoteTarget(globalContext, sourceBucket, bktTarget)
|
||||
if e != nil {
|
||||
fatalIf(probe.NewError(e).Trace(args...), "Unable to configure remote target")
|
||||
}
|
||||
// Create a new Client
|
||||
client, err := newClient(aliasedURL)
|
||||
fatalIf(err, "Unable to initialize connection.")
|
||||
@@ -185,12 +313,11 @@ func mainReplicateAdd(cliCtx *cli.Context) error {
|
||||
|
||||
opts := replication.Options{
|
||||
TagString: cliCtx.String("tags"),
|
||||
RoleArn: cliCtx.String("arn"),
|
||||
StorageClass: cliCtx.String("storage-class"),
|
||||
Priority: strconv.Itoa(cliCtx.Int("priority")),
|
||||
RuleStatus: ruleStatus,
|
||||
ID: cliCtx.String("id"),
|
||||
DestBucket: cliCtx.String("remote-bucket"),
|
||||
DestBucket: arn,
|
||||
Op: replication.AddOption,
|
||||
ReplicateDeleteMarkers: dmReplicateStatus,
|
||||
ReplicateDeletes: deleteReplicationStatus,
|
||||
|
||||
@@ -140,11 +140,22 @@ func mainReplicateRemove(cliCtx *cli.Context) error {
|
||||
if rmAll && rmForce {
|
||||
fatalIf(client.RemoveReplication(ctx), "Unable to remove replication configuration")
|
||||
} else {
|
||||
var removeArn string
|
||||
for _, rule := range rcfg.Rules {
|
||||
if rule.ID == ruleID {
|
||||
removeArn = rule.Destination.Bucket
|
||||
}
|
||||
}
|
||||
opts := replication.Options{
|
||||
ID: ruleID,
|
||||
Op: replication.RemoveOption,
|
||||
}
|
||||
fatalIf(client.SetReplication(ctx, &rcfg, opts), "Could not remove replication rule")
|
||||
admclient, cerr := newAdminClient(aliasedURL)
|
||||
fatalIf(cerr.Trace(aliasedURL), "Unable to initialize admin connection.")
|
||||
_, sourceBucket := url2Alias(args[0])
|
||||
fatalIf(probe.NewError(admclient.RemoveRemoteTarget(globalContext, sourceBucket, removeArn)).Trace(args...), "Unable to remove remote target")
|
||||
|
||||
}
|
||||
printMsg(replicateRemoveMessage{
|
||||
Op: cliCtx.Command.Name,
|
||||
|
||||
+159
-1
@@ -20,14 +20,18 @@ package cmd
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"path"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/fatih/color"
|
||||
"github.com/minio/cli"
|
||||
json "github.com/minio/colorjson"
|
||||
"github.com/minio/madmin-go/v2"
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
"github.com/minio/minio-go/v7/pkg/replication"
|
||||
"github.com/minio/minio-go/v7/pkg/s3utils"
|
||||
"github.com/minio/pkg/console"
|
||||
)
|
||||
|
||||
@@ -60,6 +64,28 @@ var replicateUpdateFlags = []cli.Flag{
|
||||
Name: "replicate",
|
||||
Usage: `comma separated list to enable replication of soft deletes, permanent deletes, existing objects and metadata sync. Valid options are "delete-marker","delete","existing-objects","metadata-sync" and ""'`,
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "sync",
|
||||
Usage: "enable synchronous replication for this target. Valid values are enable,disable.Defaults to disable if unset",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "proxy",
|
||||
Usage: "enable proxying in active-active replication. Valid values are enable,disable.By default proxying is enabled.",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "bandwidth",
|
||||
Usage: "Set bandwidth limit in bits per second (K,B,G,T for metric and Ki,Bi,Gi,Ti for IEC units)",
|
||||
},
|
||||
cli.UintFlag{
|
||||
Name: "healthcheck-seconds",
|
||||
Usage: "health check duration in seconds",
|
||||
Value: 60,
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "path",
|
||||
Value: "auto",
|
||||
Usage: "bucket path lookup supported by the server. Valid options are '[on,off,auto]'",
|
||||
},
|
||||
}
|
||||
|
||||
var replicateUpdateCmd = cli.Command{
|
||||
@@ -101,6 +127,12 @@ EXAMPLES:
|
||||
|
||||
7. Enable existing object replication on a configuration rule with ID "kxYD.491" on a target myminio/bucket. Rule previously had enabled delete marker and versioned delete replication.
|
||||
{{.Prompt}} {{.HelpName}} myminio/mybucket --id "kxYD.491" --replicate "existing-objects,delete-marker,delete"
|
||||
|
||||
8. Edit credentials for remote target with replication rule ID kxYD.491
|
||||
{{.Prompt}} {{.HelpName}} myminio/mybucket --id "kxYD.491" --remote-bucket https://foobar:newpassword@minio.siteb.example.com/targetbucket
|
||||
|
||||
9 Disable proxying and enable synchronous replication for remote target of bucket mybucket with rule ID kxYD.492
|
||||
{{.Prompt}} {{.HelpName}} myminio/mybucket --id "kxYD.492" --remote-bucket https://foobar:newpassword@minio.siteb.example.com/targetbucket --sync "enable" --proxy "disable"
|
||||
`,
|
||||
}
|
||||
|
||||
@@ -111,6 +143,106 @@ func checkReplicateUpdateSyntax(ctx *cli.Context) {
|
||||
}
|
||||
}
|
||||
|
||||
// modifyRemoteTarget - modifies the dest credentials or updates sync , disable-proxy settings
|
||||
func modifyRemoteTarget(cli *cli.Context, targets []madmin.BucketTarget, arnStr string) (*madmin.BucketTarget, []madmin.TargetUpdateType) {
|
||||
args := cli.Args()
|
||||
foundIdx := -1
|
||||
for i, t := range targets {
|
||||
if t.Arn == arnStr {
|
||||
arn, e := madmin.ParseARN(arnStr)
|
||||
if e != nil {
|
||||
fatalIf(errInvalidArgument().Trace(args...), "Malformed ARN `"+arnStr+"` in replication config")
|
||||
}
|
||||
if arn.Bucket != t.TargetBucket {
|
||||
fatalIf(errInvalidArgument().Trace(args...), "Expected remote bucket %s, got %s for rule id %s", t.TargetBucket, arn.Bucket, cli.String("id"))
|
||||
}
|
||||
foundIdx = i
|
||||
break
|
||||
}
|
||||
}
|
||||
if foundIdx < 0 {
|
||||
fatalIf(errInvalidArgument().Trace(args...), "`"+arnStr+"` not found in replication config")
|
||||
}
|
||||
var ops []madmin.TargetUpdateType
|
||||
bktTarget := targets[foundIdx].Clone()
|
||||
if cli.IsSet("sync") {
|
||||
syncState := strings.ToLower(cli.String("sync"))
|
||||
switch syncState {
|
||||
case "enable", "disable":
|
||||
bktTarget.ReplicationSync = syncState == "enable"
|
||||
ops = append(ops, madmin.SyncUpdateType)
|
||||
default:
|
||||
fatalIf(errInvalidArgument().Trace(args...), "--sync can be either [enable|disable]")
|
||||
}
|
||||
}
|
||||
if cli.IsSet("proxy") {
|
||||
proxyState := strings.ToLower(cli.String("proxy"))
|
||||
switch proxyState {
|
||||
case "enable", "disable":
|
||||
bktTarget.DisableProxy = proxyState == "disable"
|
||||
ops = append(ops, madmin.ProxyUpdateType)
|
||||
|
||||
default:
|
||||
fatalIf(errInvalidArgument().Trace(args...), "--proxy can be either [enable|disable]")
|
||||
}
|
||||
}
|
||||
|
||||
if len(args) == 1 {
|
||||
_, sourceBucket := url2Alias(args[0])
|
||||
|
||||
tgtURL := cli.String("remote-bucket")
|
||||
accessKey, secretKey, u := extractCredentialURL(tgtURL)
|
||||
var tgtBucket string
|
||||
if u.Path != "" {
|
||||
tgtBucket = path.Clean(u.Path[1:])
|
||||
}
|
||||
if e := s3utils.CheckValidBucketName(tgtBucket); e != nil {
|
||||
fatalIf(probe.NewError(e).Trace(tgtURL), "Invalid target bucket specified")
|
||||
}
|
||||
secure := u.Scheme == "https"
|
||||
host := u.Host
|
||||
if u.Port() == "" {
|
||||
port := 80
|
||||
if secure {
|
||||
port = 443
|
||||
}
|
||||
host = host + ":" + strconv.Itoa(port)
|
||||
}
|
||||
console.SetColor(cred, color.New(color.FgYellow, color.Italic))
|
||||
creds := &madmin.Credentials{AccessKey: accessKey, SecretKey: secretKey}
|
||||
if tgtBucket != bktTarget.TargetBucket {
|
||||
fatalIf(errInvalidArgument().Trace(args...), "configured remote target bucket `"+tgtBucket+"` does not match "+bktTarget.TargetBucket+"` for this ARN `"+bktTarget.Arn+"`")
|
||||
}
|
||||
if sourceBucket != bktTarget.SourceBucket {
|
||||
fatalIf(errInvalidArgument().Trace(args...), "configured source bucket `"+sourceBucket+"` does not match "+bktTarget.SourceBucket+"` for this ARN `"+bktTarget.Arn+"`")
|
||||
}
|
||||
bktTarget.TargetBucket = tgtBucket
|
||||
bktTarget.Secure = secure
|
||||
bktTarget.Credentials = creds
|
||||
bktTarget.Endpoint = host
|
||||
ops = append(ops, madmin.CredentialsUpdateType)
|
||||
}
|
||||
if cli.IsSet("bandwidth") {
|
||||
bandwidthStr := cli.String("bandwidth")
|
||||
bandwidth, err := getBandwidthInBytes(bandwidthStr)
|
||||
if err != nil {
|
||||
fatalIf(errInvalidArgument().Trace(bandwidthStr), "Invalid bandwidth number")
|
||||
}
|
||||
bktTarget.BandwidthLimit = int64(bandwidth)
|
||||
ops = append(ops, madmin.BandwidthLimitUpdateType)
|
||||
|
||||
}
|
||||
if cli.IsSet("healthcheck-seconds") {
|
||||
bktTarget.HealthCheckDuration = time.Duration(cli.Uint("healthcheck-seconds")) * time.Second
|
||||
ops = append(ops, madmin.HealthCheckDurationUpdateType)
|
||||
}
|
||||
if cli.IsSet("path") {
|
||||
bktTarget.Path = cli.String("path")
|
||||
ops = append(ops, madmin.PathUpdateType)
|
||||
}
|
||||
return &bktTarget, ops
|
||||
}
|
||||
|
||||
type replicateUpdateMessage struct {
|
||||
Op string `json:"op"`
|
||||
Status string `json:"status"`
|
||||
@@ -159,6 +291,32 @@ func mainReplicateUpdate(cliCtx *cli.Context) error {
|
||||
fatalIf(err.Trace(args...), "--state can be either `enable` or `disable`")
|
||||
}
|
||||
}
|
||||
_, sourceBucket := url2Alias(args[0])
|
||||
// Create a new MinIO Admin Client
|
||||
admClient, cerr := newAdminClient(aliasedURL)
|
||||
fatalIf(cerr, "Unable to initialize admin connection.")
|
||||
|
||||
targets, e := admClient.ListRemoteTargets(globalContext, sourceBucket, "")
|
||||
fatalIf(probe.NewError(e).Trace(args...), "Unable to fetch remote target.")
|
||||
var arn string
|
||||
for _, rule := range rcfg.Rules {
|
||||
if rule.ID == cliCtx.String("id") {
|
||||
arn = rule.Destination.Bucket
|
||||
break
|
||||
}
|
||||
}
|
||||
if cliCtx.IsSet("remote-bucket") {
|
||||
bktTarget, ops := modifyRemoteTarget(cliCtx, targets, arn)
|
||||
_, e = admClient.UpdateRemoteTarget(globalContext, bktTarget, ops...)
|
||||
if e != nil {
|
||||
fatalIf(probe.NewError(e).Trace(args...), "Unable to update remote target `"+bktTarget.Endpoint+"` from `"+bktTarget.SourceBucket+"` -> `"+bktTarget.TargetBucket+"`")
|
||||
}
|
||||
} else {
|
||||
if cliCtx.IsSet("sync") || cliCtx.IsSet("bandwidth") || cliCtx.IsSet("proxy") || cliCtx.IsSet("healthcheck-seconds") || cliCtx.IsSet("path") {
|
||||
fatalIf(errInvalidArgument().Trace(args...), "--remote-bucket is a required flag`")
|
||||
}
|
||||
}
|
||||
|
||||
var vDeleteReplicate, dmReplicate, replicasync, existingReplState string
|
||||
if cliCtx.IsSet("replicate") {
|
||||
replSlice := strings.Split(cliCtx.String("replicate"), ",")
|
||||
@@ -192,7 +350,7 @@ func mainReplicateUpdate(cliCtx *cli.Context) error {
|
||||
RuleStatus: state,
|
||||
ID: cliCtx.String("id"),
|
||||
Op: replication.SetOption,
|
||||
DestBucket: cliCtx.String("remote-bucket"),
|
||||
DestBucket: arn,
|
||||
IsSCSet: cliCtx.IsSet("storage-class"),
|
||||
IsTagSet: cliCtx.IsSet("tags"),
|
||||
}
|
||||
|
||||
@@ -778,58 +778,6 @@ This command is deprecated and will be removed in a future release. Use 'mc quot
|
||||
|
||||
```
|
||||
NAME:
|
||||
mc admin bucket remote - configure remote bucket targets
|
||||
mc admin bucket remote - configure remote bucket targets
|
||||
|
||||
USAGE:
|
||||
mc admin bucket remote COMMAND [COMMAND FLAGS | -h] [ARGUMENTS...]
|
||||
|
||||
COMMANDS:
|
||||
add add a new remote target
|
||||
ls list remote target ARN(s)
|
||||
rm remove configured remote target
|
||||
|
||||
```
|
||||
|
||||
*Example: Add a new replication target `targetbucket` in region `us-west-1` on `https://minio2:9000` for bucket `srcbucket` on MinIO server. `foobar` and `foo12345` are credentials to target endpoint.*
|
||||
|
||||
```
|
||||
mc admin bucket remote add myminio/srcbucket https://foobar:foobar12345@minio2:9000/targetbucket --service "replication" --region "us-west-1"
|
||||
ARN = `arn:minio:replication:us-west-1:1f8712ba-e38f-4429-bcb1-a7bb5aa97447:targetbucket`
|
||||
```
|
||||
|
||||
*Example: Add a new replication target `targetbucket` in region `us-west-1` on `https://minio2:9000` for bucket `srcbucket` on MinIO server. `foobar` and `foo12345` are credentials to target endpoint. The max bandwidth is metric 2G (2*10^9). Enable synchronous replication to this target, set healthcheck duration for checking target availability to 100 seconds*
|
||||
|
||||
```
|
||||
mc admin bucket remote add myminio/srcbucket https://foobar:foobar12345@minio2:9000/targetbucket --service "replication" --region "us-west-1" --bandwidth "2G" --sync --healthcheck-seconds 100
|
||||
ARN = `arn:minio:replication:us-west-1:1f8712ba-e38f-4429-bcb1-a7bb5aa97447:targetbucket`
|
||||
```
|
||||
|
||||
*Example: Add a new replication target `targetbucket` in region `us-west-1` on `https://minio2:9000` for bucket `srcbucket` on MinIO server. `foobar` and `foo12345` are credentials to target endpoint. The max bandwidth is IEC 2Gi (2*2^30)*
|
||||
|
||||
```
|
||||
mc admin bucket remote add myminio/srcbucket https://foobar:foobar12345@minio2:9000/targetbucket --service "replication" --region "us-west-1" --bandwidth "2Gi"
|
||||
```
|
||||
|
||||
*Example: Get remote target for replication on bucket 'srcbucket' in MinIO.*
|
||||
|
||||
```
|
||||
mc admin bucket remote ls myminio/srcbucket --service "replication"
|
||||
```
|
||||
|
||||
*Example: List remote target(s) on bucket 'srcbucket' in MinIO.*
|
||||
|
||||
```
|
||||
mc admin bucket remote ls myminio/srcbucket
|
||||
```
|
||||
|
||||
*Example: List remote target(s) on MinIO.*
|
||||
|
||||
```
|
||||
mc admin bucket remote ls myminio
|
||||
```
|
||||
|
||||
*Example: Remove bucket target configured for bucket 'srcbucket' on MinIO with arn `arn:minio:replication:us-west-1:1f8712ba-e38f-4429-bcb1-a7bb5aa97447:targetbucket`.*
|
||||
|
||||
```
|
||||
mc admin bucket remote rm myminio/srcbucket --arn "arn:minio:replication:us-west-1:1f8712ba-e38f-4429-bcb1-a7bb5aa97447:targetbucket"
|
||||
```
|
||||
This command is deprecated and will be removed in a future release. Use 'mc replicate add|update|rm` commands to manage remote targets
|
||||
|
||||
@@ -1813,11 +1813,14 @@ USAGE:
|
||||
|
||||
COMMANDS:
|
||||
add add a server side replication configuration rule
|
||||
edit modify an existing server side replication cofiguration rule
|
||||
update modify an existing server side replication configuration rule
|
||||
ls list server side replication configuration rules
|
||||
status show server side replication status
|
||||
resync re-replicate all previously replicated objects
|
||||
export export server side replication configuration
|
||||
import import server side replication configuration in JSON format
|
||||
rm remove a server side replication configuration rule(s)
|
||||
rm remove a server side replication configuration rule
|
||||
diff show unreplicated object versions
|
||||
|
||||
FLAGS:
|
||||
--help, -h show help
|
||||
@@ -1826,43 +1829,51 @@ FLAGS:
|
||||
*Example: Add replication configuration rule on `mybucket` on alias `myminio`. Enable delete marker replication and replication of versioned deletes for the configuration*
|
||||
|
||||
```
|
||||
mc replicate add myminio/mybucket/prefix --tags "key1=value1&key2=value2" --storage-class "STANDARD" --remote-bucket 'arn:minio:replication:us-east-1:c5be6b16-769d-432a-9ef1-4567081f3566:destbucket' --priority 1 --replicate "delete-marker,delete"
|
||||
mc replicate add myminio/mybucket/prefix --tags "key1=value1&key2=value2" --storage-class "STANDARD" --remote-bucket "http://minio3:minio123@localhost:9006/bucket" --priority 1
|
||||
Replication configuration rule applied to myminio/mybucket/prefix.
|
||||
```
|
||||
|
||||
*Example: Disable replication configuration rule with rule Id "bsibgh8t874dnjst8hkg" on bucket "mybucket" with prefix "prefix" for alias `myminio`*
|
||||
|
||||
```
|
||||
mc replicate edit myminio/mybucket/prefix --id "bsibgh8t874dnjst8hkg" --state disable
|
||||
mc replicate update myminio/mybucket/prefix --id "bsibgh8t874dnjst8hkg" --state disable
|
||||
Replication configuration rule with ID `bsibgh8t874dnjst8hkg` applied to myminio/mybucket/prefix.
|
||||
```
|
||||
|
||||
*Example: Change priority of rule with rule ID "bsibgh8t874dnjst8hkg" on bucket "mybucket" for alias `myminio`.*
|
||||
|
||||
```
|
||||
mc replicate edit myminio/mybucket/prefix --id "bsibgh8t874dnjst8hkg" --priority 3
|
||||
mc replicate update myminio/mybucket/prefix --id "bsibgh8t874dnjst8hkg" --priority 3
|
||||
Replication configuration rule with ID `bsibgh8t874dnjst8hkg` applied to myminio/mybucket/prefix.
|
||||
```
|
||||
|
||||
*Example: Clear tags on rule ID "bsibgh8t874dnjst8hkg" for target myminio/bucket which has a replication configuration rule with prefix "prefix"*
|
||||
|
||||
```
|
||||
mc replicate edit myminio/mybucket/prefix --id "bsibgh8t874dnjst8hkg" --tags ""
|
||||
mc replicate update myminio/mybucket/prefix --id "bsibgh8t874dnjst8hkg" --tags ""
|
||||
Replication configuration rule with ID `bsibgh8t874dnjst8hkg` applied to myminio/mybucket/prefix successfully.
|
||||
```
|
||||
|
||||
*Example: Enable delete marker replication and versioned delete replication on rule ID "bsibgh8t874dnjst8hkg" for target myminio/bucket which has a replication configuration rule with prefix "prefix"
|
||||
|
||||
```
|
||||
mc replicate edit myminio/mybucket/prefix --id "bsibgh8t874dnjst8hkg" --replicate "delete,delete-marker"
|
||||
mc replicate update myminio/mybucket/prefix --id "bsibgh8t874dnjst8hkg" --replicate "delete,delete-marker"
|
||||
Replication configuration rule with ID `bsibgh8t874dnjst8hkg` applied to myminio/mybucket/prefix successfully.
|
||||
```
|
||||
*Example: Disable delete marker and versioned delete replication on rule ID "bsibgh8t874dnjst8hkg" for target myminio/bucket which has a replication configuration rule with prefix "prefix"
|
||||
|
||||
```
|
||||
mc replicate edit myminio/mybucket/prefix --id "bsibgh8t874dnjst8hkg" --replicate ""
|
||||
mc replicate update myminio/mybucket/prefix --id "bsibgh8t874dnjst8hkg" --replicate ""
|
||||
Replication configuration rule with ID `bsibgh8t874dnjst8hkg` applied to myminio/mybucket/prefix successfully.
|
||||
```
|
||||
|
||||
*Example: Edit credentials for remote target with replication rule ID kxYD.491
|
||||
|
||||
```
|
||||
$ mc replicate update myminio/mybucket --id "kxYD.491" --remote-bucket
|
||||
https://foobar:newpassword@minio.siteb.example.com/targetbucket
|
||||
```
|
||||
|
||||
*Example: List replication configuration rules set on `mybucket` on alias `myminio`*
|
||||
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user