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.

44 lines
1.1 KiB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
  1. package filer
  2. import (
  3. "bytes"
  4. "errors"
  5. "fmt"
  6. "io"
  7. "github.com/chrislusf/seaweedfs/weed/pb/iam_pb"
  8. "github.com/golang/protobuf/jsonpb"
  9. "github.com/golang/protobuf/proto"
  10. )
  11. func ParseS3ConfigurationFromBytes[T proto.Message](content []byte, config T) error {
  12. if err := jsonpb.Unmarshal(bytes.NewBuffer(content), config); err != nil {
  13. return err
  14. }
  15. return nil
  16. }
  17. func ProtoToText(writer io.Writer, config proto.Message) error {
  18. m := jsonpb.Marshaler{
  19. EmitDefaults: false,
  20. Indent: " ",
  21. }
  22. return m.Marshal(writer, config)
  23. }
  24. // CheckDuplicateAccessKey returns an error message when s3cfg has duplicate access keys
  25. func CheckDuplicateAccessKey(s3cfg *iam_pb.S3ApiConfiguration) error {
  26. accessKeySet := make(map[string]string)
  27. for _, ident := range s3cfg.Identities {
  28. for _, cred := range ident.Credentials {
  29. if userName, found := accessKeySet[cred.AccessKey]; !found {
  30. accessKeySet[cred.AccessKey] = ident.Name
  31. } else {
  32. return errors.New(fmt.Sprintf("duplicate accessKey[%s], already configured in user[%s]", cred.AccessKey, userName))
  33. }
  34. }
  35. }
  36. return nil
  37. }