github.com/chenbh/concourse/v6@v6.4.2/skymarshal/skycmd/microsoft_flags.go (about) 1 package skycmd 2 3 import ( 4 "encoding/json" 5 "errors" 6 7 "github.com/concourse/dex/connector/microsoft" 8 multierror "github.com/hashicorp/go-multierror" 9 ) 10 11 func init() { 12 RegisterConnector(&Connector{ 13 id: "microsoft", 14 config: &MicrosoftFlags{}, 15 teamConfig: &MicrosoftTeamFlags{}, 16 }) 17 } 18 19 type MicrosoftFlags struct { 20 ClientID string `long:"client-id" description:"(Required) Client id"` 21 ClientSecret string `long:"client-secret" description:"(Required) Client secret"` 22 Tenant string `long:"tenant" description:"Microsoft Tenant limitation (common, consumers, organizations, tenant name or tenant uuid)"` 23 Groups []string `long:"groups" description:"Allowed Active Directory Groups"` 24 OnlySecurityGroups bool `long:"only-security-groups" description:"Only fetch security groups"` 25 } 26 27 func (flag *MicrosoftFlags) Name() string { 28 return "Microsoft" 29 } 30 31 func (flag *MicrosoftFlags) Validate() error { 32 var errs *multierror.Error 33 34 if flag.ClientID == "" { 35 errs = multierror.Append(errs, errors.New("Missing client-id")) 36 } 37 38 if flag.ClientSecret == "" { 39 errs = multierror.Append(errs, errors.New("Missing client-secret")) 40 } 41 42 return errs.ErrorOrNil() 43 } 44 45 func (flag *MicrosoftFlags) Serialize(redirectURI string) ([]byte, error) { 46 if err := flag.Validate(); err != nil { 47 return nil, err 48 } 49 50 return json.Marshal(microsoft.Config{ 51 ClientID: flag.ClientID, 52 ClientSecret: flag.ClientSecret, 53 RedirectURI: redirectURI, 54 Tenant: flag.Tenant, 55 Groups: flag.Groups, 56 OnlySecurityGroups: flag.OnlySecurityGroups, 57 }) 58 } 59 60 type MicrosoftTeamFlags struct { 61 Users []string `long:"user" description:"A whitelisted Microsoft user" value-name:"USERNAME"` 62 Groups []string `long:"group" description:"A whitelisted Microsoft group" value-name:"GROUP_NAME"` 63 } 64 65 func (flag *MicrosoftTeamFlags) GetUsers() []string { 66 return flag.Users 67 } 68 69 func (flag *MicrosoftTeamFlags) GetGroups() []string { 70 return flag.Groups 71 }