forked from vmware-archive/atc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
team.go
84 lines (71 loc) · 2.27 KB
/
team.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package db
import (
"encoding/json"
"golang.org/x/crypto/bcrypt"
)
type Team struct {
Name string
Admin bool
BasicAuth *BasicAuth `json:"basic_auth"`
GitHubAuth *GitHubAuth `json:"github_auth"`
UAAAuth *UAAAuth `json:"uaa_auth"`
GenericOAuth *GenericOAuth `json:"genericoauth_auth"`
}
func (t Team) IsAuthConfigured() bool {
return t.BasicAuth != nil || t.GitHubAuth != nil || t.UAAAuth != nil
}
type BasicAuth struct {
BasicAuthUsername string `json:"basic_auth_username"`
BasicAuthPassword string `json:"basic_auth_password"`
}
func (auth *BasicAuth) EncryptedJSON() (string, error) {
var result *BasicAuth
if auth != nil && auth.BasicAuthUsername != "" && auth.BasicAuthPassword != "" {
encryptedPw, err := bcrypt.GenerateFromPassword([]byte(auth.BasicAuthPassword), 4)
if err != nil {
return "", err
}
result = &BasicAuth{
BasicAuthPassword: string(encryptedPw),
BasicAuthUsername: auth.BasicAuthUsername,
}
}
json, err := json.Marshal(result)
return string(json), err
}
type GitHubAuth struct {
ClientID string `json:"client_id"`
ClientSecret string `json:"client_secret"`
Organizations []string `json:"organizations"`
Teams []GitHubTeam `json:"teams"`
Users []string `json:"users"`
AuthURL string `json:"auth_url"`
TokenURL string `json:"token_url"`
APIURL string `json:"api_url"`
}
type GitHubTeam struct {
OrganizationName string `json:"organization_name"`
TeamName string `json:"team_name"`
}
type SavedTeam struct {
ID int
Team
}
type UAAAuth struct {
ClientID string `json:"client_id"`
ClientSecret string `json:"client_secret"`
AuthURL string `json:"auth_url"`
TokenURL string `json:"token_url"`
CFSpaces []string `json:"cf_spaces"`
CFURL string `json:"cf_url"`
CFCACert string `json:"cf_ca_cert"`
}
type GenericOAuth struct {
AuthURL string `json:"auth_url"`
AuthURLParams map[string]string `json:"auth_url_params"`
TokenURL string `json:"token_url"`
ClientID string `json:"client_id"`
ClientSecret string `json:"client_secret"`
DisplayName string `json:"display_name"`
Scope string `json:"scope"`
}