github.com/caos/orbos@v1.5.14-0.20221103111702-e6cd0cea7ad4/internal/operator/boom/application/applications/reconciling/config/auth/github.go (about)

     1  package auth
     2  
     3  import (
     4  	"github.com/caos/orbos/internal/operator/boom/api/latest/reconciling/auth/github"
     5  	"github.com/caos/orbos/pkg/secret/read"
     6  )
     7  
     8  type githubConnector struct {
     9  	ClientID      string `yaml:"clientID,omitempty"`
    10  	ClientSecret  string `yaml:"clientSecret,omitempty"`
    11  	RedirectURI   string `yaml:"redirectURI,omitempty"`
    12  	Orgs          []*org `yaml:"orgs,omitempty"`
    13  	LoadAllGroups bool   `yaml:"loadAllGroups,omitempty"`
    14  	TeamNameField string `yaml:"teamNameField,omitempty"`
    15  	UseLoginAsID  bool   `yaml:"useLoginAsID,omitempty"`
    16  }
    17  type org struct {
    18  	Name  string   `yaml:"name,omitempty"`
    19  	Teams []string `yaml:"teams,omitempty"`
    20  }
    21  
    22  func getGithub(spec *github.Connector, redirect string) (interface{}, error) {
    23  	clientID, err := read.GetSecretValueOnlyIncluster(spec.Config.ClientID, spec.Config.ExistingClientIDSecret)
    24  	if err != nil {
    25  		return nil, err
    26  	}
    27  
    28  	clientSecret, err := read.GetSecretValueOnlyIncluster(spec.Config.ClientSecret, spec.Config.ExistingClientSecretSecret)
    29  	if err != nil {
    30  		return nil, err
    31  	}
    32  
    33  	if clientID == "" || clientSecret == "" {
    34  		return nil, nil
    35  	}
    36  
    37  	var orgs []*org
    38  	if len(spec.Config.Orgs) > 0 {
    39  		orgs = make([]*org, len(spec.Config.Orgs))
    40  		for k, v := range spec.Config.Orgs {
    41  			orgs[k] = &org{
    42  				Name:  v.Name,
    43  				Teams: v.Teams,
    44  			}
    45  		}
    46  	}
    47  
    48  	github := &githubConnector{
    49  		ClientID:      clientID,
    50  		ClientSecret:  clientSecret,
    51  		RedirectURI:   redirect,
    52  		Orgs:          orgs,
    53  		LoadAllGroups: spec.Config.LoadAllGroups,
    54  		TeamNameField: spec.Config.TeamNameField,
    55  		UseLoginAsID:  spec.Config.UseLoginAsID,
    56  	}
    57  
    58  	return github, nil
    59  }