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.
 
 
 

118 lines
2.9 KiB

  1. package auth
  2. import (
  3. "gitlab.ecloud.com/ecloud/ecloudsdkcore/utils"
  4. )
  5. type CredentialType string
  6. const (
  7. CredentialAkSk CredentialType = "ECLOUD_AKSK"
  8. CredentialMop = "MOP"
  9. CredentialS3 = "ECLOUD_S3"
  10. CredentialNone = "NONE"
  11. )
  12. type EncryptionType string
  13. const (
  14. EncrytMopRsa EncryptionType = "MOP_RSA"
  15. EncrytNone = "NONE"
  16. )
  17. type Credential struct {
  18. AccessKey *string
  19. SecretKey *string
  20. SecurityToken *string
  21. PrivateKey *string
  22. PublicKey *string
  23. CredentialType *CredentialType
  24. EncryptionType *EncryptionType
  25. }
  26. func NewCredential() *Credential {
  27. return &Credential{
  28. CredentialType: CredentialTypePointer(CredentialAkSk),
  29. EncryptionType: EncryptionTypePointer(EncrytNone),
  30. }
  31. }
  32. func (c *Credential) CopyValues(other *Credential) {
  33. if utils.IsUnSet(c.AccessKey) && utils.IsSet(other.AccessKey) {
  34. c.AccessKey = other.AccessKey
  35. }
  36. if utils.IsUnSet(c.SecretKey) && utils.IsSet(other.SecretKey) {
  37. c.SecretKey = other.SecretKey
  38. }
  39. if utils.IsUnSet(c.SecurityToken) && utils.IsSet(other.SecurityToken) {
  40. c.SecurityToken = other.SecurityToken
  41. }
  42. if utils.IsUnSet(c.PrivateKey) && utils.IsSet(other.PrivateKey) {
  43. c.PrivateKey = other.PrivateKey
  44. }
  45. if utils.IsUnSet(c.PublicKey) && utils.IsSet(other.PublicKey) {
  46. c.PublicKey = other.PublicKey
  47. }
  48. }
  49. func (c *Credential) String() string {
  50. return utils.Beautify(c)
  51. }
  52. func (c *Credential) GoString() string {
  53. return c.String()
  54. }
  55. func (c *Credential) ToJsonString() string {
  56. return utils.ToJsonString(c)
  57. }
  58. type CredentialBuilder struct {
  59. credential *Credential
  60. }
  61. func NewCredentialBuilder() *CredentialBuilder {
  62. credential := NewCredential()
  63. c := &CredentialBuilder{credential: credential}
  64. return c
  65. }
  66. func (c *CredentialBuilder) AccessKey(accessKey string) *CredentialBuilder {
  67. c.credential.AccessKey = utils.String(accessKey)
  68. return c
  69. }
  70. func (c *CredentialBuilder) SecretKey(secretKey string) *CredentialBuilder {
  71. c.credential.SecretKey = utils.String(secretKey)
  72. return c
  73. }
  74. func (c *CredentialBuilder) PrivateKey(privateKey string) *CredentialBuilder {
  75. c.credential.PrivateKey = utils.String(privateKey)
  76. return c
  77. }
  78. func (c *CredentialBuilder) PublicKey(publicKey string) *CredentialBuilder {
  79. c.credential.PublicKey = utils.String(publicKey)
  80. return c
  81. }
  82. func (c *CredentialBuilder) SecurityToken(securityToken string) *CredentialBuilder {
  83. c.credential.SecurityToken = utils.String(securityToken)
  84. return c
  85. }
  86. func (c *CredentialBuilder) CredentialType(credentialType CredentialType) *CredentialBuilder {
  87. c.credential.CredentialType = CredentialTypePointer(credentialType)
  88. return c
  89. }
  90. func (c *CredentialBuilder) EncryptionType(encryptionType EncryptionType) *CredentialBuilder {
  91. c.credential.EncryptionType = EncryptionTypePointer(encryptionType)
  92. return c
  93. }
  94. func (c *CredentialBuilder) Build() *Credential {
  95. return c.credential
  96. }