github.com/caos/orbos@v1.5.14-0.20221103111702-e6cd0cea7ad4/internal/operator/boom/api/latest/monitoring/auth/auth.go (about)

     1  package auth
     2  
     3  import (
     4  	generic "github.com/caos/orbos/internal/operator/boom/api/latest/monitoring/auth/Generic"
     5  	github "github.com/caos/orbos/internal/operator/boom/api/latest/monitoring/auth/Github"
     6  	gitlab "github.com/caos/orbos/internal/operator/boom/api/latest/monitoring/auth/Gitlab"
     7  	google "github.com/caos/orbos/internal/operator/boom/api/latest/monitoring/auth/Google"
     8  	"github.com/caos/orbos/pkg/secret"
     9  )
    10  
    11  type Auth struct {
    12  	//Configuration for SSO with Google
    13  	Google *google.Auth `json:"google,omitempty" yaml:"google,omitempty"`
    14  	//Configuration for SSO with Github
    15  	Github *github.Auth `json:"github,omitempty" yaml:"github,omitempty"`
    16  	//Configuration for SSO with Gitlab
    17  	Gitlab *gitlab.Auth `json:"gitlab,omitempty" yaml:"gitlab,omitempty"`
    18  	//Configuration for SSO with an generic OAuth provider
    19  	GenericOAuth *generic.Auth `json:"genericOAuth,omitempty" yaml:"genericOAuth,omitempty"`
    20  }
    21  
    22  func (a *Auth) IsZero() bool {
    23  	if (a.GenericOAuth == nil || a.GenericOAuth.IsZero()) &&
    24  		(a.Github == nil || a.Github.IsZero()) &&
    25  		(a.Gitlab == nil || a.Gitlab.IsZero()) &&
    26  		(a.Google == nil || a.Google.IsZero()) {
    27  		return true
    28  	}
    29  
    30  	return false
    31  }
    32  
    33  func (a *Auth) InitSecrets() {
    34  	if a.GenericOAuth == nil {
    35  		a.GenericOAuth = &generic.Auth{}
    36  	}
    37  	if a.GenericOAuth.ClientID == nil {
    38  		a.GenericOAuth.ClientID = &secret.Secret{}
    39  	}
    40  	if a.GenericOAuth.ClientSecret == nil {
    41  		a.GenericOAuth.ClientSecret = &secret.Secret{}
    42  	}
    43  	if a.GenericOAuth.ExistingClientIDSecret == nil {
    44  		a.GenericOAuth.ExistingClientIDSecret = &secret.Existing{}
    45  	}
    46  	if a.GenericOAuth.ExistingClientSecretSecret == nil {
    47  		a.GenericOAuth.ExistingClientSecretSecret = &secret.Existing{}
    48  	}
    49  
    50  	if a.Google == nil {
    51  		a.Google = &google.Auth{}
    52  	}
    53  	if a.Google.ClientID == nil {
    54  		a.Google.ClientID = &secret.Secret{}
    55  	}
    56  	if a.Google.ClientSecret == nil {
    57  		a.Google.ClientSecret = &secret.Secret{}
    58  	}
    59  	if a.Google.ExistingClientIDSecret == nil {
    60  		a.Google.ExistingClientIDSecret = &secret.Existing{}
    61  	}
    62  	if a.Google.ExistingClientSecretSecret == nil {
    63  		a.Google.ExistingClientSecretSecret = &secret.Existing{}
    64  	}
    65  
    66  	if a.Github == nil {
    67  		a.Github = &github.Auth{}
    68  	}
    69  	if a.Github.ClientID == nil {
    70  		a.Github.ClientID = &secret.Secret{}
    71  	}
    72  	if a.Github.ClientSecret == nil {
    73  		a.Github.ClientSecret = &secret.Secret{}
    74  	}
    75  	if a.Github.ExistingClientIDSecret == nil {
    76  		a.Github.ExistingClientIDSecret = &secret.Existing{}
    77  	}
    78  	if a.Github.ExistingClientSecretSecret == nil {
    79  		a.Github.ExistingClientSecretSecret = &secret.Existing{}
    80  	}
    81  
    82  	if a.Gitlab == nil {
    83  		a.Gitlab = &gitlab.Auth{}
    84  	}
    85  	if a.Gitlab.ClientID == nil {
    86  		a.Gitlab.ClientID = &secret.Secret{}
    87  	}
    88  	if a.Gitlab.ClientSecret == nil {
    89  		a.Gitlab.ClientSecret = &secret.Secret{}
    90  	}
    91  	if a.Gitlab.ExistingClientIDSecret == nil {
    92  		a.Gitlab.ExistingClientIDSecret = &secret.Existing{}
    93  	}
    94  	if a.Gitlab.ExistingClientSecretSecret == nil {
    95  		a.Gitlab.ExistingClientSecretSecret = &secret.Existing{}
    96  	}
    97  }