This repository has been archived by the owner on Apr 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
github.go
59 lines (51 loc) · 1.56 KB
/
github.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
package auth
import (
"github.com/caos/orbos/internal/operator/boom/api/v1beta2/reconciling/auth/github"
helper2 "github.com/caos/orbos/internal/utils/helper"
)
type githubConnector struct {
ClientID string `yaml:"clientID,omitempty"`
ClientSecret string `yaml:"clientSecret,omitempty"`
RedirectURI string `yaml:"redirectURI,omitempty"`
Orgs []*org `yaml:"orgs,omitempty"`
LoadAllGroups bool `yaml:"loadAllGroups,omitempty"`
TeamNameField string `yaml:"teamNameField,omitempty"`
UseLoginAsID bool `yaml:"useLoginAsID,omitempty"`
}
type org struct {
Name string `yaml:"name,omitempty"`
Teams []string `yaml:"teams,omitempty"`
}
func getGithub(spec *github.Connector, redirect string) (interface{}, error) {
clientID, err := helper2.GetSecretValue(spec.Config.ClientID, spec.Config.ExistingClientIDSecret)
if err != nil {
return nil, err
}
clientSecret, err := helper2.GetSecretValue(spec.Config.ClientSecret, spec.Config.ExistingClientSecretSecret)
if err != nil {
return nil, err
}
if clientID == "" || clientSecret == "" {
return nil, nil
}
var orgs []*org
if len(spec.Config.Orgs) > 0 {
orgs = make([]*org, len(spec.Config.Orgs))
for k, v := range spec.Config.Orgs {
orgs[k] = &org{
Name: v.Name,
Teams: v.Teams,
}
}
}
github := &githubConnector{
ClientID: clientID,
ClientSecret: clientSecret,
RedirectURI: redirect,
Orgs: orgs,
LoadAllGroups: spec.Config.LoadAllGroups,
TeamNameField: spec.Config.TeamNameField,
UseLoginAsID: spec.Config.UseLoginAsID,
}
return github, nil
}