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