Create human users from teams api

This commit is contained in:
Murat Kabilov
2017-05-12 11:37:09 +02:00
parent 58506634c4
commit 6e2d64bd50
11 changed files with 287 additions and 117 deletions
+6 -3
View File
@@ -15,9 +15,12 @@ const (
ResourceName = TPRName + "s"
ResyncPeriod = 5 * time.Minute
EtcdHost = "etcd-client.default.svc.cluster.local:2379" //TODO: move to the operator spec
SpiloImage = "registry.opensource.zalan.do/acid/spilo-9.6:1.2-p11"
PamRoleName = "zalandos"
//TODO: move to the operator spec
EtcdHost = "etcd-client.default.svc.cluster.local:2379"
SpiloImage = "registry.opensource.zalan.do/acid/spilo-9.6:1.2-p12"
PamRoleName = "zalandos"
PamConfiguration = "https://info.example.com/oauth2/tokeninfo?access_token= uid realm=/employees"
PasswordLength = 64
TeamsAPIUrl = "https://teams.example.com/api/"
)
+76
View File
@@ -0,0 +1,76 @@
package teams
import (
"encoding/json"
"fmt"
"net/http"
"strings"
)
type InfrastructureAccount struct {
Id string `json:"id"`
Name string `json:"name"`
Provider string `json:"provider"`
Type string `json:"type"`
Description string `json:"description"`
Owner string `json:"owner"`
OwnerDn string `json:"owner_dn"`
Disabled bool `json:"disabled"`
}
type Team struct {
Dn string `json:"dn"`
Id string `json:"id"`
TeamName string `json:"id_name"`
TeamId string `json:"team_id"`
Type string `json:"official"`
FullName string `json:"name"`
Aliases []string `json:"alias"`
Mails []string `json:"mail"`
Members []string `json:"member"`
CostCenter string `json:"cost_center"`
DeliveryLead string `json:"delivery_lead"`
ParentTeamId string `json:"parent_team_id"`
InfrastructureAccounts []InfrastructureAccount `json:"infrastructure-accounts"`
}
type TeamsAPI struct {
url string
httpClient *http.Client
OauthToken string
}
func NewTeamsAPI(url string) *TeamsAPI {
t := TeamsAPI{
url: strings.TrimRight(url, "/"),
httpClient: &http.Client{},
}
return &t
}
func (t *TeamsAPI) TeamInfo(teamId string) (*Team, error) {
url := fmt.Sprintf("%s/teams/%s", t.url, teamId)
req, err := http.NewRequest("GET", url, nil)
if err != nil {
return nil, err
}
req.Header.Add("Authorization", "Bearer "+t.OauthToken)
resp, err := t.httpClient.Do(req)
if err != nil {
return nil, err
}
defer resp.Body.Close()
teamInfo := &Team{}
d := json.NewDecoder(resp.Body)
err = d.Decode(teamInfo)
if err != nil {
return nil, err
}
return teamInfo, nil
}
+16
View File
@@ -1,8 +1,11 @@
package util
import (
"fmt"
"math/rand"
"time"
"k8s.io/client-go/pkg/api/v1"
)
var passwordChars = []byte("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")
@@ -19,3 +22,16 @@ func RandomPassword(n int) string {
return string(b)
}
func FullObjectNameFromMeta(meta v1.ObjectMeta) string {
return FullObjectName(meta.Namespace, meta.Name)
}
//TODO: Remove in favour of FullObjectNameFromMeta
func FullObjectName(ns, name string) string {
if ns == "" {
ns = "default"
}
return fmt.Sprintf("%s / %s", ns, name)
}