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
/
generic.go
62 lines (57 loc) · 2.16 KB
/
generic.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
package generic
import (
"github.com/caos/orbos/internal/secret"
"reflect"
)
type Auth struct {
ClientID *secret.Secret `yaml:"clientID,omitempty"`
//Existing secret with the clientID
ExistingClientIDSecret *secret.Existing `json:"existingClientIDSecret,omitempty" yaml:"existingClientIDSecret,omitempty"`
ClientSecret *secret.Secret `yaml:"clientSecret,omitempty"`
//Existing secret with the clientSecret
ExistingClientSecretSecret *secret.Existing `json:"existingClientSecretSecret,omitempty" yaml:"existingClientSecretSecret,omitempty"`
//Used scopes for the OAuth-flow
Scopes []string `json:"scopes,omitempty" yaml:"scopes,omitempty"`
//Auth-endpoint
AuthURL string `json:"authURL,omitempty" yaml:"authURL,omitempty"`
//Token-endpoint
TokenURL string `json:"tokenURL,omitempty" yaml:"tokenURL,omitempty"`
//Userinfo-endpoint
APIURL string `json:"apiURL,omitempty" yaml:"apiURL,omitempty"`
//Domains allowed to login
AllowedDomains []string `json:"allowedDomains,omitempty" yaml:"allowedDomains,omitempty"`
}
func ClearEmpty(g *Auth) *Auth {
if g == nil {
return nil
}
marshaled := Auth{
ClientID: secret.ClearEmpty(g.ClientID),
ExistingClientIDSecret: g.ExistingClientIDSecret,
ClientSecret: secret.ClearEmpty(g.ClientSecret),
ExistingClientSecretSecret: g.ExistingClientSecretSecret,
Scopes: g.Scopes,
AuthURL: g.AuthURL,
TokenURL: g.TokenURL,
APIURL: g.APIURL,
AllowedDomains: g.AllowedDomains,
}
if reflect.DeepEqual(marshaled, Auth{}) {
return nil
}
return &marshaled
}
func (g *Auth) MarshalYAML() (interface{}, error) {
type Alias Auth
return &Alias{
ClientID: secret.ClearEmpty(g.ClientID),
ExistingClientIDSecret: g.ExistingClientIDSecret,
ClientSecret: secret.ClearEmpty(g.ClientSecret),
ExistingClientSecretSecret: g.ExistingClientSecretSecret,
Scopes: g.Scopes,
AuthURL: g.AuthURL,
TokenURL: g.TokenURL,
APIURL: g.APIURL,
AllowedDomains: g.AllowedDomains,
}, nil
}