-
Notifications
You must be signed in to change notification settings - Fork 4
/
config.go
72 lines (64 loc) · 1.67 KB
/
config.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
package centrify
import (
"fmt"
"github.com/marcozj/golang-sdk/dmc"
"github.com/marcozj/golang-sdk/oauth"
)
// Config - Centrify Vault client struct
type Config struct {
URL string
AppID string
Scope string
Username string
Password string
Token string
UseDMC bool
LogLevel string
LogPath string
SkipCertVerify bool
}
// Valid - Validate provider configuration
func (c *Config) Valid() error {
if c.URL == "" {
return fmt.Errorf("Tenant URL must be provided for the CentrifyVault provider")
}
if c.Scope == "" {
return fmt.Errorf("Scope must be provided for the CentrifyVault provider")
}
if !c.UseDMC && c.Token == "" {
// If DMC isn't used and token isn't supplied, make sure appid user username is provided
if c.AppID == "" {
return fmt.Errorf("AppID must be provided for the CentrifyVault provider")
}
if c.Username == "" {
return fmt.Errorf("Username or token must be provided for the CentrifyVault provider")
}
}
return nil
}
func (c *Config) getClient() (interface{}, error) {
var client interface{}
var err error
if c.UseDMC {
// use DMC to return authenticated Rest client
call := dmc.DMC{}
call.Service = c.URL
call.Scope = c.Scope
call.Token = c.Token
call.SkipCertVerify = c.SkipCertVerify
client, err = call.GetClient()
} else {
// use OAuth authentication
call := oauth.OauthClient{
Service: c.URL,
AppID: c.AppID,
Scope: c.Scope,
Token: c.Token,
ClientID: c.Username,
ClientSecret: c.Password,
SkipCertVerify: c.SkipCertVerify,
}
client, err = call.GetClient()
}
return client, err
}