/
management_option.go
102 lines (89 loc) · 2.72 KB
/
management_option.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package management
import (
"context"
"net/http"
"github.com/authok/authok-go/internal/client"
)
// Option is used for passing options to the Management client.
type Option func(*Management)
// WithDebug configures the management client to dump http requests and
// responses to stdout.
func WithDebug(d bool) Option {
return func(m *Management) {
m.debug = d
}
}
// WithContext configures the management client to use the provided context
// instead of the provided one.
func WithContext(ctx context.Context) Option {
return func(m *Management) {
m.ctx = ctx
}
}
// WithUserAgent configures the management client to use the provided user agent
// string instead of the default one.
func WithUserAgent(userAgent string) Option {
return func(m *Management) {
m.userAgent = userAgent
}
}
// WithClientCredentials configures management to authenticate using the client
// credentials authentication flow.
func WithClientCredentials(clientID, clientSecret string) Option {
return func(m *Management) {
m.tokenSource = client.OAuth2ClientCredentials(m.ctx, m.url.String(), clientID, clientSecret)
}
}
// WithClientCredentialsAndAudience configures management to authenticate using the client
// credentials authentication flow and a custom audience.
func WithClientCredentialsAndAudience(clientID, clientSecret, audience string) Option {
return func(m *Management) {
m.tokenSource = client.OAuth2ClientCredentialsAndAudience(
m.ctx,
m.url.String(),
clientID,
clientSecret,
audience,
)
}
}
// WithStaticToken configures management to authenticate using a static
// authentication token.
func WithStaticToken(token string) Option {
return func(m *Management) {
m.tokenSource = client.StaticToken(token)
}
}
// WithInsecure configures management to not use an authentication token and
// use HTTP instead of HTTPS.
//
// This option is available for testing purposes and should not be used in
// production.
func WithInsecure() Option {
return func(m *Management) {
m.tokenSource = client.StaticToken("insecure")
m.url.Scheme = "http"
}
}
// WithClient configures management to use the provided client.
func WithClient(client *http.Client) Option {
return func(m *Management) {
m.http = client
}
}
// WithAuthokClientInfo configures the management client to use the provided client information
// instead of the default one.
func WithAuthokClientInfo(authokClientInfo client.AuthokClientInfo) Option {
return func(m *Management) {
if !authokClientInfo.IsEmpty() {
m.authokClientInfo = &authokClientInfo
}
}
}
// WithNoAuthokClientInfo configures the management client to not send the "Authok-Client" header
// at all.
func WithNoAuthokClientInfo() Option {
return func(m *Management) {
m.authokClientInfo = nil
}
}