-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.go
53 lines (45 loc) · 1.31 KB
/
util.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
package hdfs
import (
"fmt"
"github.com/colinmarc/hdfs"
krb "gopkg.in/jcmturner/gokrb5.v5/client"
"gopkg.in/jcmturner/gokrb5.v5/config"
)
func createHDFSClient(addresses []string, user string, krbOptions *KrbOptions) (*hdfs.Client, error) {
options := hdfs.ClientOptions{
Addresses: addresses,
}
if krbOptions != nil {
krbClient, err := createKrbClient(krbOptions)
if err != nil {
return nil, err
}
options.KerberosClient = krbClient
options.KerberosServicePrincipleName = krbOptions.ServicePrincipalName
} else {
options.User = user
}
return hdfs.NewClient(options)
}
func createKrbClient(krbOptions *KrbOptions) (*krb.Client, error) {
krbConfig, err := config.NewConfigFromString(krbOptions.Config)
if err != nil {
return nil, err
}
if krbOptions.CCacheOptions != nil {
client, err := krb.NewClientFromCCache(krbOptions.CCacheOptions.CCache)
if err != nil {
return nil, err
}
return client.WithConfig(krbConfig), nil
} else if krbOptions.KeytabOptions != nil {
client := krb.NewClientWithKeytab(krbOptions.KeytabOptions.Username, krbOptions.KeytabOptions.Realm, krbOptions.KeytabOptions.Keytab)
client = *client.WithConfig(krbConfig)
err = client.Login()
if err != nil {
return nil, err
}
return &client, nil
}
return nil, fmt.Errorf("Failed to get a Kerberos client")
}