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.

69 lines
1.7 KiB

  1. package s3api
  2. import (
  3. "sync"
  4. )
  5. //Predefined Accounts
  6. var (
  7. // AccountAdmin is used as the default account for IAM-Credentials access without Account configured
  8. AccountAdmin = Account{
  9. Name: "admin",
  10. EmailAddress: "admin@example.com",
  11. Id: "admin",
  12. }
  13. // AccountAnonymous is used to represent the account for anonymous access
  14. AccountAnonymous = Account{
  15. Name: "anonymous",
  16. EmailAddress: "anonymous@example.com",
  17. Id: "anonymous",
  18. }
  19. )
  20. //Account represents a system user, a system user can
  21. //configure multiple IAM-Users, IAM-Users can configure
  22. //permissions respectively, and each IAM-User can
  23. //configure multiple security credentials
  24. type Account struct {
  25. //Name is also used to display the "DisplayName" as the owner of the bucket or object
  26. Name string
  27. EmailAddress string
  28. //Id is used to identify an Account when granting cross-account access(ACLs) to buckets and objects
  29. Id string
  30. }
  31. type AccountManager struct {
  32. sync.Mutex
  33. s3a *S3ApiServer
  34. IdNameMapping map[string]string
  35. EmailIdMapping map[string]string
  36. }
  37. func NewAccountManager(s3a *S3ApiServer) *AccountManager {
  38. am := &AccountManager{
  39. s3a: s3a,
  40. IdNameMapping: make(map[string]string),
  41. EmailIdMapping: make(map[string]string),
  42. }
  43. am.initialize()
  44. return am
  45. }
  46. func (am *AccountManager) GetAccountNameById(canonicalId string) string {
  47. return am.IdNameMapping[canonicalId]
  48. }
  49. func (am *AccountManager) GetAccountIdByEmail(email string) string {
  50. return am.EmailIdMapping[email]
  51. }
  52. func (am *AccountManager) initialize() {
  53. // load predefined Accounts
  54. for _, account := range []Account{AccountAdmin, AccountAnonymous} {
  55. am.IdNameMapping[account.Id] = account.Name
  56. am.EmailIdMapping[account.EmailAddress] = account.Id
  57. }
  58. }