-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.go
84 lines (78 loc) · 2.44 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// Package ccv2 represents a Cloud Controller V2 client.
//
// It is currently designed to support Cloud Controller API 2.29.0. However, it
// may include features and endpoints of later API versions.
//
// For more information on the Cloud Controller API see
// https://apidocs.cloudfoundry.org/
//
// Method Naming Conventions
//
// The client takes a '<Action Name><Top Level Endpoint><Return Value>'
// approach to method names. If the <Top Level Endpoint> and <Return Value>
// are similar, they do not need to be repeated. If a GUID is required for the
// <Top Level Endpoint>, the pluralization is removed from said endpoint in the
// method name.
//
// For Example:
// Method Name: GetApplication
// Endpoint: /v2/applications/:guid
// Action Name: Get
// Top Level Endpoint: applications
// Return Value: Application
//
// Method Name: GetServiceInstances
// Endpoint: /v2/service_instances
// Action Name: Get
// Top Level Endpoint: service_instances
// Return Value: []ServiceInstance
//
// Method Name: GetSpaceServiceInstances
// Endpoint: /v2/spaces/:guid/service_instances
// Action Name: Get
// Top Level Endpoint: spaces
// Return Value: []ServiceInstance
//
// Use the following table to determine which HTTP Command equates to which
// Action Name:
// HTTP Command -> Action Name
// POST -> New
// GET -> Get
// PUT -> Update
// DELETE -> Delete
//
// Method Locations
//
// Methods exist in the same file as their return type, regardless of which
// endpoint they use.
package ccv2
import (
"fmt"
"runtime"
"code.cloudfoundry.org/cli/api/cloudcontroller"
"github.com/tedsuo/rata"
)
// Warnings are a collection of warnings that the Cloud Controller can return
// back from an API request.
type Warnings []string
// Client is a client that can be used to talk to a Cloud Controller's V2
// Endpoints.
type Client struct {
authorizationEndpoint string
cloudControllerAPIVersion string
cloudControllerURL string
dopplerEndpoint string
loggregatorEndpoint string
routingEndpoint string
tokenEndpoint string
router *rata.RequestGenerator
connection cloudcontroller.Connection
userAgent string
}
// NewClient returns a new Cloud Controller Client.
func NewClient(appName string, appVersion string) *Client {
userAgent := fmt.Sprintf("%s/%s (%s; %s %s)", appName, appVersion, runtime.Version(), runtime.GOARCH, runtime.GOOS)
return &Client{
userAgent: userAgent,
}
}