forked from concourse/concourse
-
Notifications
You must be signed in to change notification settings - Fork 0
/
github_flags.go
73 lines (59 loc) · 1.93 KB
/
github_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
package skycmd
import (
"encoding/json"
"errors"
"github.com/concourse/dex/connector/github"
"github.com/concourse/flag"
multierror "github.com/hashicorp/go-multierror"
)
func init() {
RegisterConnector(&Connector{
id: "github",
config: &GithubFlags{},
teamConfig: &GithubTeamFlags{},
})
}
type GithubFlags struct {
ClientID string `long:"client-id" description:"(Required) Client id"`
ClientSecret string `long:"client-secret" description:"(Required) Client secret"`
Host string `long:"host" description:"Hostname of GitHub Enterprise deployment (No scheme, No trailing slash)"`
CACert flag.File `long:"ca-cert" description:"CA certificate of GitHub Enterprise deployment"`
}
func (flag *GithubFlags) Name() string {
return "GitHub"
}
func (flag *GithubFlags) Validate() error {
var errs *multierror.Error
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 *GithubFlags) Serialize(redirectURI string) ([]byte, error) {
if err := flag.Validate(); err != nil {
return nil, err
}
return json.Marshal(github.Config{
ClientID: flag.ClientID,
ClientSecret: flag.ClientSecret,
RedirectURI: redirectURI,
HostName: flag.Host,
RootCA: flag.CACert.Path(),
TeamNameField: "both",
LoadAllGroups: true,
})
}
type GithubTeamFlags struct {
Users []string `long:"user" description:"A whitelisted GitHub user" value-name:"USERNAME"`
Orgs []string `long:"org" description:"A whitelisted GitHub org" value-name:"ORG_NAME"`
Teams []string `long:"team" description:"A whitelisted GitHub team" value-name:"ORG_NAME:TEAM_NAME"`
}
func (flag *GithubTeamFlags) GetUsers() []string {
return flag.Users
}
func (flag *GithubTeamFlags) GetGroups() []string {
return append(flag.Orgs, flag.Teams...)
}