-
Notifications
You must be signed in to change notification settings - Fork 841
/
cf_flags.go
106 lines (90 loc) · 4 KB
/
cf_flags.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
102
103
104
105
106
package skycmd
import (
"encoding/json"
"errors"
"fmt"
"github.com/concourse/dex/connector/cloudfoundry"
"github.com/concourse/flag"
multierror "github.com/hashicorp/go-multierror"
)
func init() {
RegisterConnector(&Connector{
id: "cloudfoundry",
config: &CFFlags{},
teamConfig: &CFTeamFlags{},
})
}
type CFFlags struct {
ClientID string `long:"client-id" description:"(Required) Client id"`
ClientSecret string `long:"client-secret" description:"(Required) Client secret"`
APIURL string `long:"api-url" description:"(Required) The base API URL of your CF deployment. It will use this information to discover information about the authentication provider."`
CACerts []flag.File `long:"ca-cert" description:"CA Certificate"`
InsecureSkipVerify bool `long:"skip-ssl-validation" description:"Skip SSL validation"`
}
func (flag *CFFlags) Name() string {
return "CloudFoundry"
}
func (flag *CFFlags) Validate() error {
var errs *multierror.Error
if flag.APIURL == "" {
errs = multierror.Append(errs, errors.New("Missing api-url"))
}
if flag.ClientID == "" {
errs = multierror.Append(errs, errors.New("Missing client-id"))
}
if flag.ClientSecret == "" {
errs = multierror.Append(errs, errors.New("Missing client-secret"))
}
return errs.ErrorOrNil()
}
func (flag *CFFlags) Serialize(redirectURI string) ([]byte, error) {
if err := flag.Validate(); err != nil {
return nil, err
}
caCerts := []string{}
for _, file := range flag.CACerts {
caCerts = append(caCerts, file.Path())
}
return json.Marshal(cloudfoundry.Config{
ClientID: flag.ClientID,
ClientSecret: flag.ClientSecret,
APIURL: flag.APIURL,
RootCAs: caCerts,
InsecureSkipVerify: flag.InsecureSkipVerify,
RedirectURI: redirectURI,
})
}
type CFTeamFlags struct {
Users []string `long:"user" description:"A whitelisted CloudFoundry user" value-name:"USERNAME"`
Orgs []string `long:"org" description:"A whitelisted CloudFoundry org" value-name:"ORG_NAME"`
Spaces []string `long:"space" description:"(Deprecated) A whitelisted CloudFoundry space for users with the 'developer' role" value-name:"ORG_NAME:SPACE_NAME"`
SpacesAll []string `long:"space-with-any-role" description:"A whitelisted CloudFoundry space for users with any role" value-name:"ORG_NAME:SPACE_NAME" mapstructure:"spaces_with_any_role"`
SpacesDeveloper []string `long:"space-with-developer-role" description:"A whitelisted CloudFoundry space for users with the 'developer' role" value-name:"ORG_NAME:SPACE_NAME" mapstructure:"spaces_with_developer_role"`
SpacesAuditor []string `long:"space-with-auditor-role" description:"A whitelisted CloudFoundry space for users with the 'auditor' role" value-name:"ORG_NAME:SPACE_NAME" mapstructure:"spaces_with_auditor_role"`
SpacesManager []string `long:"space-with-manager-role" description:"A whitelisted CloudFoundry space for users with the 'manager' role" value-name:"ORG_NAME:SPACE_NAME" mapstructure:"spaces_with_manager_role"`
SpaceGuids []string `long:"space-guid" description:"A whitelisted CloudFoundry space guid" value-name:"SPACE_GUID" mapstructure:"space_guids"`
SpaceGuidsLegacy []string `mapstructure:"spaceguids"`
}
func (flag *CFTeamFlags) GetUsers() []string {
return flag.Users
}
func (flag *CFTeamFlags) GetGroups() []string {
var groups []string
groups = append(groups, flag.Orgs...)
groups = append(groups, flag.SpacesAll...)
for _, space := range flag.Spaces {
groups = append(groups, fmt.Sprintf("%s:developer", space))
}
for _, space := range flag.SpacesDeveloper {
groups = append(groups, fmt.Sprintf("%s:developer", space))
}
for _, space := range flag.SpacesAuditor {
groups = append(groups, fmt.Sprintf("%s:auditor", space))
}
for _, space := range flag.SpacesManager {
groups = append(groups, fmt.Sprintf("%s:manager", space))
}
groups = append(groups, flag.SpaceGuids...)
groups = append(groups, flag.SpaceGuidsLegacy...)
return groups
}