generated from cloudoperators/repository-template
-
Notifications
You must be signed in to change notification settings - Fork 1
/
scim_types.go
74 lines (59 loc) · 1.51 KB
/
scim_types.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
// SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Greenhouse contributors
// SPDX-License-Identifier: Apache-2.0
package scim
import (
"encoding/base64"
"net/http"
"net/url"
)
type GroupResponseBody struct {
TotalResults int `json:"totalResults"`
Resources []Resource `json:"resources"`
}
type Resource struct {
ID *string `json:"id"`
DisplayName *string `json:"displayName"`
Members []Member `json:"members"`
}
type Member struct {
Ref string `json:"$ref"`
}
type MemberResponseBody struct {
ID string `json:"id"`
UserName string `json:"userName"`
Emails []Email `json:"emails"`
Name Name `json:"name"`
Active bool `json:"active"`
}
type Email struct {
Value string `json:"value"`
Primary bool `json:"primary"`
}
type Name struct {
FamilyName string `json:"familyName"`
GivenName string `json:"givenname"`
}
type ScimClient struct {
baseURL *url.URL
httpClient httpClient
}
type AuthType byte
const (
Basic AuthType = iota
)
type httpClient interface {
Do(*http.Request) (*http.Response, error)
}
type basicAuthHTTPClient struct {
basicAuthUser string
basicAuthPw string
c http.Client
}
func (c basicAuthHTTPClient) Do(req *http.Request) (*http.Response, error) {
req.Header.Add("Authorization", "Basic "+basicAuth(c.basicAuthUser, c.basicAuthPw))
return c.c.Do(req)
}
func basicAuth(username, password string) string {
auth := username + ":" + password
return base64.StdEncoding.EncodeToString([]byte(auth))
}