Skip to content

Commit 8210b02

Browse files
authored
Merge pull request #503 from jcvrabo/add-info-endpoints
implement the info resource
2 parents 5619c66 + 8fbb0fd commit 8210b02

7 files changed

Lines changed: 171 additions & 0 deletions

File tree

client/client.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ type Client struct {
3333
Droplets *DropletClient
3434
EnvVarGroups *EnvVarGroupClient
3535
FeatureFlags *FeatureFlagClient
36+
Info *InfoClient
3637
IsolationSegments *IsolationSegmentClient
3738
Jobs *JobClient
3839
Manifests *ManifestClient
@@ -96,6 +97,7 @@ func New(config *config.Config) (*Client, error) {
9697
client.Droplets = (*DropletClient)(&client.common)
9798
client.EnvVarGroups = (*EnvVarGroupClient)(&client.common)
9899
client.FeatureFlags = (*FeatureFlagClient)(&client.common)
100+
client.Info = (*InfoClient)(&client.common)
99101
client.IsolationSegments = (*IsolationSegmentClient)(&client.common)
100102
client.Jobs = (*JobClient)(&client.common)
101103
client.Manifests = (*ManifestClient)(&client.common)

client/info.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package client
2+
3+
import (
4+
"context"
5+
6+
"github.com/cloudfoundry/go-cfclient/v3/resource"
7+
)
8+
9+
type InfoClient commonClient
10+
11+
// Get retrieves information about the Cloud Foundry deployment
12+
//
13+
// This endpoint returns metadata about the Cloud Foundry deployment including
14+
// version, build info, CLI version requirements, and operator-configured custom metadata.
15+
//
16+
// Authentication: No authentication required
17+
func (c *InfoClient) Get(ctx context.Context) (*resource.Info, error) {
18+
var info resource.Info
19+
err := c.client.get(ctx, "/v3/info", &info)
20+
if err != nil {
21+
return nil, err
22+
}
23+
return &info, nil
24+
}
25+
26+
// GetUsageSummary retrieves platform-wide usage statistics
27+
//
28+
// This endpoint returns usage information across the entire Cloud Foundry deployment
29+
// including started instances, memory usage, routes, service instances, and more.
30+
//
31+
// Authentication: Requires authentication with cloud_controller.admin or cloud_controller.admin_read_only scope
32+
func (c *InfoClient) GetUsageSummary(ctx context.Context) (*resource.InfoUsageSummary, error) {
33+
var usageSummary resource.InfoUsageSummary
34+
err := c.client.get(ctx, "/v3/info/usage_summary", &usageSummary)
35+
if err != nil {
36+
return nil, err
37+
}
38+
return &usageSummary, nil
39+
}

client/info_test.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package client
2+
3+
import (
4+
"context"
5+
"net/http"
6+
"testing"
7+
8+
"github.com/cloudfoundry/go-cfclient/v3/testutil"
9+
)
10+
11+
func TestInfo(t *testing.T) {
12+
g := testutil.NewObjectJSONGenerator()
13+
info := g.Info().JSON
14+
usageSummary := g.InfoUsageSummary().JSON
15+
16+
tests := []RouteTest{
17+
{
18+
Description: "Get platform info",
19+
Route: testutil.MockRoute{
20+
Method: "GET",
21+
Endpoint: "/v3/info",
22+
Output: g.Single(info),
23+
Status: http.StatusOK},
24+
Expected: info,
25+
Action: func(c *Client, t *testing.T) (any, error) {
26+
return c.Info.Get(context.Background())
27+
},
28+
},
29+
{
30+
Description: "Get platform usage summary",
31+
Route: testutil.MockRoute{
32+
Method: "GET",
33+
Endpoint: "/v3/info/usage_summary",
34+
Output: g.Single(usageSummary),
35+
Status: http.StatusOK},
36+
Expected: usageSummary,
37+
Action: func(c *Client, t *testing.T) (any, error) {
38+
return c.Info.GetUsageSummary(context.Background())
39+
},
40+
},
41+
}
42+
ExecuteTests(tests, t)
43+
}

resource/info.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package resource
2+
3+
// Info represents platform information about the Cloud Foundry deployment
4+
type Info struct {
5+
Build string `json:"build"` // The build number of the Cloud Controller API, ends up showing the full version of the api.
6+
CLIVersion InfoCLIVersion `json:"cli_version"` // Recommended and minimum CLI versions
7+
Custom map[string]any `json:"custom"` // Custom metadata set by the operator
8+
Description string `json:"description"` // Description of the Cloud Foundry deployment
9+
Name string `json:"name"` // Name of the Cloud Foundry deployment
10+
Version int `json:"version"` // Version of the Cloud Controller API (Major version number)
11+
OSBAPIVersion string `json:"osbapi_version"` // Version of the Open Service Broker API in use
12+
RateLimits InfoRateLimits `json:"rate_limits"` // Rate limiting configuration
13+
Links Links `json:"links"`
14+
}
15+
16+
// InfoCLIVersion contains the minimum CLI version supported and the recommend version
17+
type InfoCLIVersion struct {
18+
Minimum string `json:"minimum"` // Minimum supported CLI version
19+
Recommended string `json:"recommended"` // Recommended CLI version
20+
}
21+
22+
// InfoRateLimits contains rate limiting configuration
23+
type InfoRateLimits struct {
24+
Enabled bool `json:"enabled"` // Whether rate limiting is enabled
25+
GeneralLimit int `json:"general_limit"` // Number of requests allowed per reset interval
26+
ResetIntervalInMinutes int `json:"reset_interval_in_minutes"` // Time in minutes before rate limit counter resets
27+
}
28+
29+
// InfoUsageSummary represents platform-wide usage statistics
30+
type InfoUsageSummary struct {
31+
UsageSummary UsageSummary `json:"usage_summary"` // Platform usage statistics
32+
Links Links `json:"links"`
33+
}

testutil/object_generator.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,16 @@ func (o ObjectJSONGenerator) FeatureFlag() *JSONResource {
202202
return o.renderTemplate(r, "feature_flag.json")
203203
}
204204

205+
func (o ObjectJSONGenerator) Info() *JSONResource {
206+
r := &JSONResource{}
207+
return o.renderTemplate(r, "info.json")
208+
}
209+
210+
func (o ObjectJSONGenerator) InfoUsageSummary() *JSONResource {
211+
r := &JSONResource{}
212+
return o.renderTemplate(r, "info_usage_summary.json")
213+
}
214+
205215
func (o ObjectJSONGenerator) IsolationSegment() *JSONResource {
206216
r := &JSONResource{
207217
GUID: RandomGUID(),

testutil/template/info.json

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"build": "afa73e3fe",
3+
"cli_version": {
4+
"minimum": "6.22.0",
5+
"recommended": "latest"
6+
},
7+
"custom": {
8+
"arbitrary": "stuff"
9+
},
10+
"description": "Put your apps here!",
11+
"name": "Cloud Foundry",
12+
"version": 123,
13+
"osbapi_version": "2.15",
14+
"rate_limits": {
15+
"enabled": true,
16+
"general_limit": 2000,
17+
"reset_interval_in_minutes": 30
18+
},
19+
"links": {
20+
"self": {
21+
"href": "https://api.example.org/v3/info"
22+
},
23+
"support": {
24+
"href": "https://support.example.com"
25+
}
26+
}
27+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"usage_summary": {
3+
"started_instances": 294,
4+
"memory_in_mb": 123945,
5+
"routes": 300,
6+
"service_instances": 50,
7+
"reserved_ports": 10,
8+
"domains": 5,
9+
"per_app_tasks": 0,
10+
"service_keys": 20
11+
},
12+
"links": {
13+
"self": {
14+
"href": "https://api.example.org/v3/info/usage_summary"
15+
}
16+
}
17+
}

0 commit comments

Comments
 (0)