-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.go
67 lines (57 loc) · 1.57 KB
/
client.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
// Package uaa is a GoLang library that interacts with CloudFoundry User
// Account and Authentication (UAA) Server.
//
// It is currently designed to support UAA API X.X.X. However, it may include
// features and endpoints of later API versions.
package uaa
import (
"fmt"
"runtime"
"time"
"code.cloudfoundry.org/cli/api/uaa/internal"
"github.com/tedsuo/rata"
)
//go:generate counterfeiter . AuthenticationStore
// AuthenticationStore represents the storage the UAA client
type AuthenticationStore interface {
UAAOAuthClient() string
UAAOAuthClientSecret() string
AccessToken() string
RefreshToken() string
SetAccessToken(token string)
SetRefreshToken(token string)
}
// Client is the UAA client
type Client struct {
URL string
store AuthenticationStore
userAgent string
router *rata.RequestGenerator
connection Connection
}
// Config allows the Client to be configured
type Config struct {
AppName string
AppVersion string
DialTimeout time.Duration
SkipSSLValidation bool
Store AuthenticationStore
URL string
}
// NewClient returns a new UAA Client with the provided configuration
func NewClient(config Config) *Client {
userAgent := fmt.Sprintf("%s/%s (%s; %s %s)",
config.AppName,
config.AppVersion,
runtime.Version(),
runtime.GOARCH,
runtime.GOOS,
)
return &Client{
URL: config.URL,
store: config.Store,
userAgent: userAgent,
router: rata.NewRequestGenerator(config.URL, internal.Routes),
connection: NewConnection(config.SkipSSLValidation, config.DialTimeout),
}
}