diff options
Diffstat (limited to 'weed/shell/command_s3_configure.go')
| -rw-r--r-- | weed/shell/command_s3_configure.go | 39 |
1 files changed, 24 insertions, 15 deletions
diff --git a/weed/shell/command_s3_configure.go b/weed/shell/command_s3_configure.go index c1ac1ce74..869949a25 100644 --- a/weed/shell/command_s3_configure.go +++ b/weed/shell/command_s3_configure.go @@ -1,15 +1,16 @@ package shell import ( + "bytes" "flag" "fmt" + "github.com/chrislusf/seaweedfs/weed/filer" "io" "sort" "strings" "github.com/chrislusf/seaweedfs/weed/pb/filer_pb" "github.com/chrislusf/seaweedfs/weed/pb/iam_pb" - "github.com/chrislusf/seaweedfs/weed/s3iam" ) func init() { @@ -24,15 +25,17 @@ func (c *commandS3Configure) Name() string { } func (c *commandS3Configure) Help() string { - return `configure and apply s3 options for each bucket + return `<WIP> configure and apply s3 options for each bucket + # see the current configuration file content s3.configure ` } func (c *commandS3Configure) Do(args []string, commandEnv *CommandEnv, writer io.Writer) (err error) { + s3ConfigureCommand := flag.NewFlagSet(c.Name(), flag.ContinueOnError) - actions := s3ConfigureCommand.String("actions", "", "actions names") + actions := s3ConfigureCommand.String("actions", "", "comma separated actions names: Read,Write,List,Tagging,Admin") user := s3ConfigureCommand.String("user", "", "user name") buckets := s3ConfigureCommand.String("buckets", "", "bucket name") accessKey := s3ConfigureCommand.String("access_key", "", "specify the access key") @@ -44,18 +47,20 @@ func (c *commandS3Configure) Do(args []string, commandEnv *CommandEnv, writer io return nil } - s3cfg := &iam_pb.S3ApiConfiguration{} - ifs := &s3iam.IAMFilerStore{} + var buf bytes.Buffer if err = commandEnv.WithFilerClient(func(client filer_pb.SeaweedFilerClient) error { - ifs = s3iam.NewIAMFilerStore(&client) - if err := ifs.LoadIAMConfig(s3cfg); err != nil { - return nil - } - return nil - }); err != nil { + return filer.ReadEntry(commandEnv.MasterClient, client, filer.IamConfigDirecotry, filer.IamIdentityFile, &buf) + }); err != nil && err != filer_pb.ErrNotFound { return err } + s3cfg := &iam_pb.S3ApiConfiguration{} + if buf.Len() > 0 { + if err = filer.ParseS3ConfigurationFromBytes(buf.Bytes(), s3cfg); err != nil { + return err + } + } + idx := 0 changed := false if *user != "" { @@ -158,16 +163,20 @@ func (c *commandS3Configure) Do(args []string, commandEnv *CommandEnv, writer io s3cfg.Identities = append(s3cfg.Identities, &identity) } - for _, identity := range s3cfg.Identities { - fmt.Fprintf(writer, fmt.Sprintf("%+v\n", identity)) - } + buf.Reset() + filer.S3ConfigurationToText(&buf, s3cfg) + fmt.Fprintf(writer, string(buf.Bytes())) fmt.Fprintln(writer) if *apply { - if err := ifs.SaveIAMConfig(s3cfg); err != nil { + + if err := commandEnv.WithFilerClient(func(client filer_pb.SeaweedFilerClient) error { + return filer.SaveInsideFiler(client, filer.IamConfigDirecotry, filer.IamIdentityFile, buf.Bytes()) + }); err != nil { return err } + } return nil |
