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.

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