diff options
Diffstat (limited to 'weed/shell')
| -rw-r--r-- | weed/shell/command_fs_configure.go | 38 | ||||
| -rw-r--r-- | weed/shell/command_s3_configure.go | 39 |
2 files changed, 31 insertions, 46 deletions
diff --git a/weed/shell/command_fs_configure.go b/weed/shell/command_fs_configure.go index d530b2585..497ef4f9e 100644 --- a/weed/shell/command_fs_configure.go +++ b/weed/shell/command_fs_configure.go @@ -5,14 +5,11 @@ import ( "flag" "fmt" "io" - "math" - "net/http" "strings" "github.com/chrislusf/seaweedfs/weed/filer" "github.com/chrislusf/seaweedfs/weed/pb/filer_pb" "github.com/chrislusf/seaweedfs/weed/storage/super_block" - "github.com/chrislusf/seaweedfs/weed/util" ) func init() { @@ -65,25 +62,16 @@ func (c *commandFsConfigure) Do(args []string, commandEnv *CommandEnv, writer io var buf bytes.Buffer if err = commandEnv.WithFilerClient(func(client filer_pb.SeaweedFilerClient) error { - - request := &filer_pb.LookupDirectoryEntryRequest{ - Directory: filer.DirectoryEtc, - Name: filer.FilerConfName, - } - respLookupEntry, err := filer_pb.LookupEntry(client, request) - if err != nil { - return err - } - - return filer.StreamContent(commandEnv.MasterClient, &buf, respLookupEntry.Entry.Chunks, 0, math.MaxInt64) - - }); err != nil { + return filer.ReadEntry(commandEnv.MasterClient, client, filer.DirectoryEtcSeaweedFS, filer.FilerConfName, &buf) + }); err != nil && err != filer_pb.ErrNotFound { return err } fc := filer.NewFilerConf() - if err = fc.LoadFromBytes(buf.Bytes()); err != nil { - return err + if buf.Len() > 0 { + if err = fc.LoadFromBytes(buf.Bytes()); err != nil { + return err + } } if *locationPrefix != "" { @@ -128,21 +116,9 @@ func (c *commandFsConfigure) Do(args []string, commandEnv *CommandEnv, writer io if *apply { - target := fmt.Sprintf("http://%s:%d%s/%s", commandEnv.option.FilerHost, commandEnv.option.FilerPort, filer.DirectoryEtc, filer.FilerConfName) - - // set the HTTP method, url, and request body - req, err := http.NewRequest(http.MethodPut, target, &buf) - if err != nil { - return err - } - - // set the request header Content-Type for json - req.Header.Set("Content-Type", "text/plain; charset=utf-8") - resp, err := http.DefaultClient.Do(req) - if err != nil { + if err := filer.SaveAs(commandEnv.option.FilerHost, int(commandEnv.option.FilerPort), filer.DirectoryEtcSeaweedFS, filer.FilerConfName, "text/plain; charset=utf-8", &buf); err != nil { return err } - util.CloseResponse(resp) } 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 |
