-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathclient.options.go
107 lines (92 loc) · 2.9 KB
/
client.options.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
103
104
105
106
107
// Copyright 2022 The searKing Author. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package webhdfs
import (
"net/http"
"strings"
"github.com/go-playground/validator/v10"
"github.com/searKing/golang/go/exp/types"
"github.com/searKing/webhdfs/kerberos"
)
func withEndpoint(endpoint string) ClientOption {
return ClientOptionFunc(func(c *Client) {
c.opts.Addresses = strings.Split(endpoint, ",")
})
}
func withUsername(username string) ClientOption {
return ClientOptionFunc(func(c *Client) {
c.opts.Username = types.Pointer(username)
})
}
func WithDisableSSL(disableSSL bool) ClientOption {
return ClientOptionFunc(func(c *Client) {
c.opts.DisableSSL = disableSSL
})
}
func WithValidator(v *validator.Validate) ClientOption {
return ClientOptionFunc(func(c *Client) {
c.opts.Validator = v
})
}
func WithHttpClient(httpCli *http.Client) ClientOption {
return ClientOptionFunc(func(c *Client) {
if c.opts == nil {
c.opts = NewConfig()
}
c.opts.HttpConfig.HttpClient = httpCli
})
}
func WithKerberosConfig(kerberosConfig *kerberos.Config) ClientOption {
return ClientOptionFunc(func(c *Client) {
if c.opts == nil {
c.opts = NewConfig()
}
c.opts.HttpConfig.KerberosConfig = kerberosConfig
})
}
func WithKerberosPassword(username string, spn string, realm string, password string, krb5Con string) ClientOption {
return WithKerberosConfig(&kerberos.Config{
UserName: username,
ServicePrincipleName: spn,
Realm: realm,
Password: password,
ConfigString: krb5Con,
})
}
func WithKerberosKeytab(username string, spn string, realm string, keytab string, krb5Con string) ClientOption {
return WithKerberosConfig(&kerberos.Config{
UserName: username,
ServicePrincipleName: spn,
Realm: realm,
KeyTabString: keytab,
ConfigString: krb5Con,
})
}
func WithKerberosCCache(username string, spn string, realm string, cc string, krb5Con string) ClientOption {
return WithKerberosConfig(&kerberos.Config{
UserName: username,
ServicePrincipleName: spn,
Realm: realm,
CCacheString: cc,
ConfigString: krb5Con,
})
}
func WithKerberosKeytabFile(username string, spn string, realm string, keytabFile string, krb5ConFile string) ClientOption {
return WithKerberosConfig(&kerberos.Config{
UserName: username,
ServicePrincipleName: spn,
Realm: realm,
KeyTabFile: keytabFile,
ConfigFile: krb5ConFile,
})
}
func WithKerberosCCacheFile(username string, spn string, realm string, ccFile string, krb5ConFile string) ClientOption {
return WithKerberosConfig(&kerberos.Config{
UserName: username,
ServicePrincipleName: spn,
Realm: realm,
CCacheString: ccFile,
ConfigString: krb5ConFile,
})
}