diff options
| author | Konstantin Lebedev <lebedev_k@tochka.com> | 2021-04-06 13:43:08 +0500 |
|---|---|---|
| committer | Konstantin Lebedev <lebedev_k@tochka.com> | 2021-04-06 13:43:08 +0500 |
| commit | ed79baa30fe5687a35a9a61e2dcf3b4750064d36 (patch) | |
| tree | 538fa799a24a9ed2cc148d9ab4bf95f3ad5d8b04 /weed/iamapi/iamapi_server.go | |
| parent | 8a95f9c10c3d4c9e1f6761f5620da3e5253398f5 (diff) | |
| download | seaweedfs-ed79baa30fe5687a35a9a61e2dcf3b4750064d36.tar.xz seaweedfs-ed79baa30fe5687a35a9a61e2dcf3b4750064d36.zip | |
add tests
Diffstat (limited to 'weed/iamapi/iamapi_server.go')
| -rw-r--r-- | weed/iamapi/iamapi_server.go | 48 |
1 files changed, 40 insertions, 8 deletions
diff --git a/weed/iamapi/iamapi_server.go b/weed/iamapi/iamapi_server.go index 00c4a69a2..7698fab71 100644 --- a/weed/iamapi/iamapi_server.go +++ b/weed/iamapi/iamapi_server.go @@ -1,10 +1,10 @@ package iamapi // https://docs.aws.amazon.com/cli/latest/reference/iam/list-roles.html -// https://docs.aws.amazon.com/IAM/latest/APIReference/API_CreateRole.html import ( "bytes" + "fmt" "github.com/chrislusf/seaweedfs/weed/filer" "github.com/chrislusf/seaweedfs/weed/pb" "github.com/chrislusf/seaweedfs/weed/pb/filer_pb" @@ -16,6 +16,16 @@ import ( "strings" ) +type IamS3ApiConfig interface { + GetS3ApiConfiguration(s3cfg *iam_pb.S3ApiConfiguration) (err error) + PutS3ApiConfiguration(s3cfg *iam_pb.S3ApiConfiguration) (err error) +} + +type IamS3ApiConfigure struct { + option *IamServerOption + masterClient *wdclient.MasterClient +} + type IamServerOption struct { Masters string Filer string @@ -25,17 +35,22 @@ type IamServerOption struct { } type IamApiServer struct { - option *IamServerOption - masterClient *wdclient.MasterClient - filerclient *filer_pb.SeaweedFilerClient + s3ApiConfig IamS3ApiConfig + filerclient *filer_pb.SeaweedFilerClient } +var s3ApiConfigure IamS3ApiConfig + func NewIamApiServer(router *mux.Router, option *IamServerOption) (iamApiServer *IamApiServer, err error) { - iamApiServer = &IamApiServer{ + s3ApiConfigure = IamS3ApiConfigure{ option: option, masterClient: wdclient.NewMasterClient(option.GrpcDialOption, pb.AdminShellClient, "", 0, "", strings.Split(option.Masters, ",")), } + iamApiServer = &IamApiServer{ + s3ApiConfig: s3ApiConfigure, + } + iamApiServer.registerRouter(router) return iamApiServer, nil @@ -52,10 +67,10 @@ func (iama *IamApiServer) registerRouter(router *mux.Router) { apiRouter.NotFoundHandler = http.HandlerFunc(notFoundHandler) } -func (iama *IamApiServer) GetS3ApiConfiguration(s3cfg *iam_pb.S3ApiConfiguration) (err error) { +func (iam IamS3ApiConfigure) GetS3ApiConfiguration(s3cfg *iam_pb.S3ApiConfiguration) (err error) { var buf bytes.Buffer - err = pb.WithGrpcFilerClient(iama.option.FilerGrpcAddress, iama.option.GrpcDialOption, func(client filer_pb.SeaweedFilerClient) error { - if err = filer.ReadEntry(iama.masterClient, client, filer.IamConfigDirecotry, filer.IamIdentityFile, &buf); err != nil { + err = pb.WithGrpcFilerClient(iam.option.FilerGrpcAddress, iam.option.GrpcDialOption, func(client filer_pb.SeaweedFilerClient) error { + if err = filer.ReadEntry(iam.masterClient, client, filer.IamConfigDirecotry, filer.IamIdentityFile, &buf); err != nil { return err } return nil @@ -70,3 +85,20 @@ func (iama *IamApiServer) GetS3ApiConfiguration(s3cfg *iam_pb.S3ApiConfiguration } return nil } + +func (iam IamS3ApiConfigure) PutS3ApiConfiguration(s3cfg *iam_pb.S3ApiConfiguration) (err error) { + buf := bytes.Buffer{} + if err := filer.S3ConfigurationToText(&buf, s3cfg); err != nil { + return fmt.Errorf("S3ConfigurationToText: %s", err) + } + return pb.WithGrpcFilerClient( + iam.option.FilerGrpcAddress, + iam.option.GrpcDialOption, + func(client filer_pb.SeaweedFilerClient) error { + if err := filer.SaveInsideFiler(client, filer.IamConfigDirecotry, filer.IamIdentityFile, buf.Bytes()); err != nil { + return err + } + return nil + }, + ) +} |
