github.com/Axway/agent-sdk@v1.1.101/pkg/apic/provisioning/credentials.go (about) 1 package provisioning 2 3 import "time" 4 5 const ( 6 oauth = "oauth" 7 other = "other" 8 ) 9 10 // Credential - holds the details about the credential to send to encrypt and send to platform 11 type Credential interface { 12 GetData() map[string]interface{} 13 GetExpirationTime() time.Time 14 } 15 16 type credential struct { 17 Credential 18 credentialType string 19 data map[string]interface{} 20 expTime time.Time 21 } 22 23 func (c credential) GetData() map[string]interface{} { 24 return c.data 25 } 26 27 func (c credential) GetExpirationTime() time.Time { 28 return c.expTime 29 } 30 31 // CredentialBuilder - builder to create new credentials to send to Central 32 type CredentialBuilder interface { 33 SetExpirationTime(expTime time.Time) CredentialBuilder 34 SetOAuthID(id string) Credential 35 SetOAuthIDAndSecret(id, secret string) Credential 36 SetAPIKey(key string) Credential 37 SetHTTPBasic(username, password string) Credential 38 SetCredential(data map[string]interface{}) Credential 39 } 40 41 type credentialBuilder struct { 42 credential *credential 43 } 44 45 // NewCredentialBuilder - create a credential builder 46 func NewCredentialBuilder() CredentialBuilder { 47 return &credentialBuilder{ 48 credential: &credential{}, 49 } 50 } 51 52 // SetOAuthID - set the credential as an Oauth type 53 func (c *credentialBuilder) SetOAuthID(id string) Credential { 54 c.credential.credentialType = oauth 55 c.credential.data = map[string]interface{}{ 56 OauthClientID: id, 57 } 58 return c.credential 59 } 60 61 // SetOAuthIDAndSecret - set the credential as an Oauth type 62 func (c *credentialBuilder) SetOAuthIDAndSecret(id, secret string) Credential { 63 c.credential.credentialType = oauth 64 c.credential.data = map[string]interface{}{ 65 OauthClientID: id, 66 OauthClientSecret: secret, 67 } 68 return c.credential 69 } 70 71 // SetAPIKey - set the credential as an API Key type 72 func (c *credentialBuilder) SetAPIKey(key string) Credential { 73 c.credential.credentialType = APIKeyCRD 74 c.credential.data = map[string]interface{}{ 75 APIKey: key, 76 } 77 return c.credential 78 } 79 80 // SetHTTPBasic - set the credential as an API Key type 81 func (c *credentialBuilder) SetHTTPBasic(username, password string) Credential { 82 c.credential.credentialType = BasicAuthCRD 83 c.credential.data = map[string]interface{}{ 84 BasicAuthUsername: username, 85 BasicAuthPassword: password, 86 } 87 return c.credential 88 } 89 90 // SetExpirationTime - set the credential expiration time 91 func (c *credentialBuilder) SetExpirationTime(expTime time.Time) CredentialBuilder { 92 c.credential.expTime = expTime 93 return c 94 } 95 96 // SetCredential - set the credential 97 func (c *credentialBuilder) SetCredential(data map[string]interface{}) Credential { 98 c.credential.credentialType = other 99 c.credential.data = data 100 return c.credential 101 }