Skip to content

Commit 890ff1e

Browse files
new: Add support LKE, Volume, NodeBalancer, and network transfer pricing endpoints (#573)
* Add LKE types endpoints * Support base struct; add NB types endpoints * Add volume types * Add network transfer prices * Add price and region price structs * Revert IPv6 fixtures * Add missing fixtures
1 parent 881108a commit 890ff1e

13 files changed

+650
-0
lines changed

base_types.go

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// This package contains various type-related base classes intended
2+
// to be used in composition across type structures in this project.
3+
4+
package linodego
5+
6+
// baseType is a base struct containing the core fields of a resource type
7+
// returned from the Linode API.
8+
type baseType[PriceType any, RegionPriceType any] struct {
9+
ID string `json:"id"`
10+
Label string `json:"label"`
11+
Price PriceType `json:"price"`
12+
RegionPrices []RegionPriceType `json:"region_prices"`
13+
Transfer int `json:"transfer"`
14+
}
15+
16+
// baseTypePrice is a base struct containing the core fields of a resource type's
17+
// base price.
18+
type baseTypePrice struct {
19+
Hourly float64 `json:"hourly"`
20+
Monthly float64 `json:"monthly"`
21+
}
22+
23+
// baseTypeRegionPrice is a base struct containing the core fields of a resource type's
24+
// region-specific price.
25+
type baseTypeRegionPrice struct {
26+
baseTypePrice
27+
28+
ID string `json:"id"`
29+
}

lke_types.go

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package linodego
2+
3+
import (
4+
"context"
5+
)
6+
7+
// LKEType represents a single valid LKE type.
8+
// NOTE: This typically corresponds to the availability of a cluster's
9+
// control plane.
10+
type LKEType struct {
11+
baseType[LKETypePrice, LKETypeRegionPrice]
12+
}
13+
14+
// LKETypePrice represents the base hourly and monthly prices
15+
// for an LKE type entry.
16+
type LKETypePrice struct {
17+
baseTypePrice
18+
}
19+
20+
// LKETypeRegionPrice represents the regional hourly and monthly prices
21+
// for an LKE type entry.
22+
type LKETypeRegionPrice struct {
23+
baseTypeRegionPrice
24+
}
25+
26+
// ListLKETypes lists LKE types. This endpoint is cached by default.
27+
func (c *Client) ListLKETypes(ctx context.Context, opts *ListOptions) ([]LKEType, error) {
28+
e := "lke/types"
29+
30+
endpoint, err := generateListCacheURL(e, opts)
31+
if err != nil {
32+
return nil, err
33+
}
34+
35+
if result := c.getCachedResponse(endpoint); result != nil {
36+
return result.([]LKEType), nil
37+
}
38+
39+
response, err := getPaginatedResults[LKEType](ctx, c, e, opts)
40+
if err != nil {
41+
return nil, err
42+
}
43+
44+
c.addCachedResponse(endpoint, response, &cacheExpiryTime)
45+
46+
return response, nil
47+
}

network_transfer_prices.go

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package linodego
2+
3+
import (
4+
"context"
5+
)
6+
7+
// NetworkTransferPrice represents a single valid network transfer price.
8+
type NetworkTransferPrice struct {
9+
baseType[NetworkTransferTypePrice, NetworkTransferTypeRegionPrice]
10+
}
11+
12+
// NetworkTransferTypePrice represents the base hourly and monthly prices
13+
// for a network transfer price entry.
14+
type NetworkTransferTypePrice struct {
15+
baseTypePrice
16+
}
17+
18+
// NetworkTransferTypeRegionPrice represents the regional hourly and monthly prices
19+
// for a network transfer price entry.
20+
type NetworkTransferTypeRegionPrice struct {
21+
baseTypeRegionPrice
22+
}
23+
24+
// ListNetworkTransferPrices lists network transfer prices. This endpoint is cached by default.
25+
func (c *Client) ListNetworkTransferPrices(ctx context.Context, opts *ListOptions) ([]NetworkTransferPrice, error) {
26+
e := "network-transfer/prices"
27+
28+
endpoint, err := generateListCacheURL(e, opts)
29+
if err != nil {
30+
return nil, err
31+
}
32+
33+
if result := c.getCachedResponse(endpoint); result != nil {
34+
return result.([]NetworkTransferPrice), nil
35+
}
36+
37+
response, err := getPaginatedResults[NetworkTransferPrice](ctx, c, e, opts)
38+
if err != nil {
39+
return nil, err
40+
}
41+
42+
c.addCachedResponse(endpoint, response, &cacheExpiryTime)
43+
44+
return response, nil
45+
}

nodebalancer_types.go

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package linodego
2+
3+
import (
4+
"context"
5+
)
6+
7+
// NodeBalancerType represents a single valid NodeBalancer type.
8+
type NodeBalancerType struct {
9+
baseType[NodeBalancerTypePrice, NodeBalancerTypeRegionPrice]
10+
}
11+
12+
// NodeBalancerTypePrice represents the base hourly and monthly prices
13+
// for a NodeBalancer type entry.
14+
type NodeBalancerTypePrice struct {
15+
baseTypePrice
16+
}
17+
18+
// NodeBalancerTypeRegionPrice represents the regional hourly and monthly prices
19+
// for a NodeBalancer type entry.
20+
type NodeBalancerTypeRegionPrice struct {
21+
baseTypeRegionPrice
22+
}
23+
24+
// ListNodeBalancerTypes lists NodeBalancer types. This endpoint is cached by default.
25+
func (c *Client) ListNodeBalancerTypes(ctx context.Context, opts *ListOptions) ([]NodeBalancerType, error) {
26+
e := "nodebalancers/types"
27+
28+
endpoint, err := generateListCacheURL(e, opts)
29+
if err != nil {
30+
return nil, err
31+
}
32+
33+
if result := c.getCachedResponse(endpoint); result != nil {
34+
return result.([]NodeBalancerType), nil
35+
}
36+
37+
response, err := getPaginatedResults[NodeBalancerType](ctx, c, e, opts)
38+
if err != nil {
39+
return nil, err
40+
}
41+
42+
c.addCachedResponse(endpoint, response, &cacheExpiryTime)
43+
44+
return response, nil
45+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
---
2+
version: 1
3+
interactions:
4+
- request:
5+
body: ""
6+
form: {}
7+
headers:
8+
Accept:
9+
- application/json
10+
Content-Type:
11+
- application/json
12+
User-Agent:
13+
- linodego/dev https://github.com/linode/linodego
14+
url: https://api.linode.com/v4beta/lke/types?page=1
15+
method: GET
16+
response:
17+
body: '{"data": [{"id": "lke-sa", "label": "LKE Standard Availability", "price":
18+
{"hourly": 0.0, "monthly": 0.0}, "region_prices": [], "transfer": 0}, {"id":
19+
"lke-ha", "label": "LKE High Availability", "price": {"hourly": 0.09, "monthly":
20+
60.0}, "region_prices": [{"id": "id-cgk", "hourly": 0.108, "monthly": 72.0},
21+
{"id": "br-gru", "hourly": 0.126, "monthly": 84.0}], "transfer": 0}], "page":
22+
1, "pages": 1, "results": 2}'
23+
headers:
24+
Access-Control-Allow-Credentials:
25+
- "true"
26+
Access-Control-Allow-Headers:
27+
- Authorization, Origin, X-Requested-With, Content-Type, Accept, X-Filter
28+
Access-Control-Allow-Methods:
29+
- HEAD, GET, OPTIONS, POST, PUT, DELETE
30+
Access-Control-Allow-Origin:
31+
- '*'
32+
Access-Control-Expose-Headers:
33+
- X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Status
34+
Akamai-Internal-Account:
35+
- '*'
36+
Cache-Control:
37+
- max-age=0, no-cache, no-store
38+
Connection:
39+
- keep-alive
40+
Content-Length:
41+
- "415"
42+
Content-Security-Policy:
43+
- default-src 'none'
44+
Content-Type:
45+
- application/json
46+
Expires:
47+
- Thu, 05 Sep 2024 17:47:57 GMT
48+
Pragma:
49+
- no-cache
50+
Strict-Transport-Security:
51+
- max-age=31536000
52+
Vary:
53+
- Authorization, X-Filter
54+
- Authorization, X-Filter
55+
X-Accepted-Oauth-Scopes:
56+
- '*'
57+
X-Content-Type-Options:
58+
- nosniff
59+
X-Frame-Options:
60+
- DENY
61+
- DENY
62+
X-Oauth-Scopes:
63+
- '*'
64+
X-Ratelimit-Limit:
65+
- "400"
66+
X-Xss-Protection:
67+
- 1; mode=block
68+
status: 200 OK
69+
code: 200
70+
duration: ""
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
---
2+
version: 1
3+
interactions:
4+
- request:
5+
body: ""
6+
form: {}
7+
headers:
8+
Accept:
9+
- application/json
10+
Content-Type:
11+
- application/json
12+
User-Agent:
13+
- linodego/dev https://github.com/linode/linodego
14+
url: https://api.linode.com/v4beta/network-transfer/prices?page=1
15+
method: GET
16+
response:
17+
body: '{"data": [{"id": "distributed_network_transfer", "label": "Distributed
18+
Network Transfer", "price": {"hourly": 0.01, "monthly": null}, "region_prices":
19+
[], "transfer": 0}, {"id": "network_transfer", "label": "Network Transfer",
20+
"price": {"hourly": 0.005, "monthly": null}, "region_prices": [{"id": "id-cgk",
21+
"hourly": 0.015, "monthly": null}, {"id": "br-gru", "hourly": 0.007, "monthly":
22+
null}], "transfer": 0}], "page": 1, "pages": 1, "results": 2}'
23+
headers:
24+
Access-Control-Allow-Credentials:
25+
- "true"
26+
Access-Control-Allow-Headers:
27+
- Authorization, Origin, X-Requested-With, Content-Type, Accept, X-Filter
28+
Access-Control-Allow-Methods:
29+
- HEAD, GET, OPTIONS, POST, PUT, DELETE
30+
Access-Control-Allow-Origin:
31+
- '*'
32+
Access-Control-Expose-Headers:
33+
- X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Status
34+
Akamai-Internal-Account:
35+
- '*'
36+
Cache-Control:
37+
- max-age=0, no-cache, no-store
38+
Connection:
39+
- keep-alive
40+
Content-Length:
41+
- "448"
42+
Content-Security-Policy:
43+
- default-src 'none'
44+
Content-Type:
45+
- application/json
46+
Expires:
47+
- Wed, 04 Sep 2024 18:06:01 GMT
48+
Pragma:
49+
- no-cache
50+
Strict-Transport-Security:
51+
- max-age=31536000
52+
Vary:
53+
- Authorization, X-Filter
54+
- Authorization, X-Filter
55+
X-Accepted-Oauth-Scopes:
56+
- '*'
57+
X-Content-Type-Options:
58+
- nosniff
59+
X-Frame-Options:
60+
- DENY
61+
- DENY
62+
X-Oauth-Scopes:
63+
- '*'
64+
X-Ratelimit-Limit:
65+
- "400"
66+
X-Xss-Protection:
67+
- 1; mode=block
68+
status: 200 OK
69+
code: 200
70+
duration: ""
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
---
2+
version: 1
3+
interactions:
4+
- request:
5+
body: ""
6+
form: {}
7+
headers:
8+
Accept:
9+
- application/json
10+
Content-Type:
11+
- application/json
12+
User-Agent:
13+
- linodego/dev https://github.com/linode/linodego
14+
url: https://api.linode.com/v4beta/nodebalancers/types?page=1
15+
method: GET
16+
response:
17+
body: '{"data": [{"id": "nodebalancer", "label": "NodeBalancer", "price": {"hourly":
18+
0.015, "monthly": 10.0}, "region_prices": [{"id": "id-cgk", "hourly": 0.018,
19+
"monthly": 12.0}, {"id": "br-gru", "hourly": 0.021, "monthly": 14.0}], "transfer":
20+
0}], "page": 1, "pages": 1, "results": 1}'
21+
headers:
22+
Access-Control-Allow-Credentials:
23+
- "true"
24+
Access-Control-Allow-Headers:
25+
- Authorization, Origin, X-Requested-With, Content-Type, Accept, X-Filter
26+
Access-Control-Allow-Methods:
27+
- HEAD, GET, OPTIONS, POST, PUT, DELETE
28+
Access-Control-Allow-Origin:
29+
- '*'
30+
Access-Control-Expose-Headers:
31+
- X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Status
32+
Akamai-Internal-Account:
33+
- '*'
34+
Cache-Control:
35+
- max-age=0, no-cache, no-store
36+
Connection:
37+
- keep-alive
38+
Content-Length:
39+
- "279"
40+
Content-Security-Policy:
41+
- default-src 'none'
42+
Content-Type:
43+
- application/json
44+
Expires:
45+
- Wed, 04 Sep 2024 17:52:02 GMT
46+
Pragma:
47+
- no-cache
48+
Strict-Transport-Security:
49+
- max-age=31536000
50+
Vary:
51+
- Authorization, X-Filter
52+
- Authorization, X-Filter
53+
X-Accepted-Oauth-Scopes:
54+
- '*'
55+
X-Content-Type-Options:
56+
- nosniff
57+
X-Frame-Options:
58+
- DENY
59+
- DENY
60+
X-Oauth-Scopes:
61+
- '*'
62+
X-Ratelimit-Limit:
63+
- "400"
64+
X-Xss-Protection:
65+
- 1; mode=block
66+
status: 200 OK
67+
code: 200
68+
duration: ""

0 commit comments

Comments
 (0)