You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

72 lines
2.1 KiB

  1. package iamapi
  2. // https://docs.aws.amazon.com/cli/latest/reference/iam/list-roles.html
  3. // https://docs.aws.amazon.com/IAM/latest/APIReference/API_CreateRole.html
  4. import (
  5. "bytes"
  6. "github.com/chrislusf/seaweedfs/weed/filer"
  7. "github.com/chrislusf/seaweedfs/weed/pb"
  8. "github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
  9. "github.com/chrislusf/seaweedfs/weed/pb/iam_pb"
  10. "github.com/chrislusf/seaweedfs/weed/wdclient"
  11. "github.com/gorilla/mux"
  12. "google.golang.org/grpc"
  13. "net/http"
  14. "strings"
  15. )
  16. type IamServerOption struct {
  17. Masters string
  18. Filer string
  19. Port int
  20. FilerGrpcAddress string
  21. GrpcDialOption grpc.DialOption
  22. }
  23. type IamApiServer struct {
  24. option *IamServerOption
  25. masterClient *wdclient.MasterClient
  26. filerclient *filer_pb.SeaweedFilerClient
  27. }
  28. func NewIamApiServer(router *mux.Router, option *IamServerOption) (iamApiServer *IamApiServer, err error) {
  29. iamApiServer = &IamApiServer{
  30. option: option,
  31. masterClient: wdclient.NewMasterClient(option.GrpcDialOption, pb.AdminShellClient, "", 0, "", strings.Split(option.Masters, ",")),
  32. }
  33. iamApiServer.registerRouter(router)
  34. return iamApiServer, nil
  35. }
  36. func (iama *IamApiServer) registerRouter(router *mux.Router) {
  37. // API Router
  38. apiRouter := router.PathPrefix("/").Subrouter()
  39. // ListBuckets
  40. // apiRouter.Methods("GET").Path("/").HandlerFunc(track(s3a.iam.Auth(s3a.ListBucketsHandler, ACTION_ADMIN), "LIST"))
  41. apiRouter.Path("/").Methods("POST").HandlerFunc(iama.DoActions)
  42. // NotFound
  43. apiRouter.NotFoundHandler = http.HandlerFunc(notFoundHandler)
  44. }
  45. func (iama *IamApiServer) GetS3ApiConfiguration(s3cfg *iam_pb.S3ApiConfiguration) (err error) {
  46. var buf bytes.Buffer
  47. err = pb.WithGrpcFilerClient(iama.option.FilerGrpcAddress, iama.option.GrpcDialOption, func(client filer_pb.SeaweedFilerClient) error {
  48. if err = filer.ReadEntry(iama.masterClient, client, filer.IamConfigDirecotry, filer.IamIdentityFile, &buf); err != nil {
  49. return err
  50. }
  51. return nil
  52. })
  53. if err != nil {
  54. return err
  55. }
  56. if buf.Len() > 0 {
  57. if err = filer.ParseS3ConfigurationFromBytes(buf.Bytes(), s3cfg); err != nil {
  58. return err
  59. }
  60. }
  61. return nil
  62. }