-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
new: Add support LKE, Volume, NodeBalancer, and network transfer pric…
…ing 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
- Loading branch information
1 parent
881108a
commit 890ff1e
Showing
13 changed files
with
650 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// This package contains various type-related base classes intended | ||
// to be used in composition across type structures in this project. | ||
|
||
package linodego | ||
|
||
// baseType is a base struct containing the core fields of a resource type | ||
// returned from the Linode API. | ||
type baseType[PriceType any, RegionPriceType any] struct { | ||
ID string `json:"id"` | ||
Label string `json:"label"` | ||
Price PriceType `json:"price"` | ||
RegionPrices []RegionPriceType `json:"region_prices"` | ||
Transfer int `json:"transfer"` | ||
} | ||
|
||
// baseTypePrice is a base struct containing the core fields of a resource type's | ||
// base price. | ||
type baseTypePrice struct { | ||
Hourly float64 `json:"hourly"` | ||
Monthly float64 `json:"monthly"` | ||
} | ||
|
||
// baseTypeRegionPrice is a base struct containing the core fields of a resource type's | ||
// region-specific price. | ||
type baseTypeRegionPrice struct { | ||
baseTypePrice | ||
|
||
ID string `json:"id"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package linodego | ||
|
||
import ( | ||
"context" | ||
) | ||
|
||
// LKEType represents a single valid LKE type. | ||
// NOTE: This typically corresponds to the availability of a cluster's | ||
// control plane. | ||
type LKEType struct { | ||
baseType[LKETypePrice, LKETypeRegionPrice] | ||
} | ||
|
||
// LKETypePrice represents the base hourly and monthly prices | ||
// for an LKE type entry. | ||
type LKETypePrice struct { | ||
baseTypePrice | ||
} | ||
|
||
// LKETypeRegionPrice represents the regional hourly and monthly prices | ||
// for an LKE type entry. | ||
type LKETypeRegionPrice struct { | ||
baseTypeRegionPrice | ||
} | ||
|
||
// ListLKETypes lists LKE types. This endpoint is cached by default. | ||
func (c *Client) ListLKETypes(ctx context.Context, opts *ListOptions) ([]LKEType, error) { | ||
e := "lke/types" | ||
|
||
endpoint, err := generateListCacheURL(e, opts) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if result := c.getCachedResponse(endpoint); result != nil { | ||
return result.([]LKEType), nil | ||
} | ||
|
||
response, err := getPaginatedResults[LKEType](ctx, c, e, opts) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
c.addCachedResponse(endpoint, response, &cacheExpiryTime) | ||
|
||
return response, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package linodego | ||
|
||
import ( | ||
"context" | ||
) | ||
|
||
// NetworkTransferPrice represents a single valid network transfer price. | ||
type NetworkTransferPrice struct { | ||
baseType[NetworkTransferTypePrice, NetworkTransferTypeRegionPrice] | ||
} | ||
|
||
// NetworkTransferTypePrice represents the base hourly and monthly prices | ||
// for a network transfer price entry. | ||
type NetworkTransferTypePrice struct { | ||
baseTypePrice | ||
} | ||
|
||
// NetworkTransferTypeRegionPrice represents the regional hourly and monthly prices | ||
// for a network transfer price entry. | ||
type NetworkTransferTypeRegionPrice struct { | ||
baseTypeRegionPrice | ||
} | ||
|
||
// ListNetworkTransferPrices lists network transfer prices. This endpoint is cached by default. | ||
func (c *Client) ListNetworkTransferPrices(ctx context.Context, opts *ListOptions) ([]NetworkTransferPrice, error) { | ||
e := "network-transfer/prices" | ||
|
||
endpoint, err := generateListCacheURL(e, opts) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if result := c.getCachedResponse(endpoint); result != nil { | ||
return result.([]NetworkTransferPrice), nil | ||
} | ||
|
||
response, err := getPaginatedResults[NetworkTransferPrice](ctx, c, e, opts) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
c.addCachedResponse(endpoint, response, &cacheExpiryTime) | ||
|
||
return response, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package linodego | ||
|
||
import ( | ||
"context" | ||
) | ||
|
||
// NodeBalancerType represents a single valid NodeBalancer type. | ||
type NodeBalancerType struct { | ||
baseType[NodeBalancerTypePrice, NodeBalancerTypeRegionPrice] | ||
} | ||
|
||
// NodeBalancerTypePrice represents the base hourly and monthly prices | ||
// for a NodeBalancer type entry. | ||
type NodeBalancerTypePrice struct { | ||
baseTypePrice | ||
} | ||
|
||
// NodeBalancerTypeRegionPrice represents the regional hourly and monthly prices | ||
// for a NodeBalancer type entry. | ||
type NodeBalancerTypeRegionPrice struct { | ||
baseTypeRegionPrice | ||
} | ||
|
||
// ListNodeBalancerTypes lists NodeBalancer types. This endpoint is cached by default. | ||
func (c *Client) ListNodeBalancerTypes(ctx context.Context, opts *ListOptions) ([]NodeBalancerType, error) { | ||
e := "nodebalancers/types" | ||
|
||
endpoint, err := generateListCacheURL(e, opts) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if result := c.getCachedResponse(endpoint); result != nil { | ||
return result.([]NodeBalancerType), nil | ||
} | ||
|
||
response, err := getPaginatedResults[NodeBalancerType](ctx, c, e, opts) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
c.addCachedResponse(endpoint, response, &cacheExpiryTime) | ||
|
||
return response, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
--- | ||
version: 1 | ||
interactions: | ||
- request: | ||
body: "" | ||
form: {} | ||
headers: | ||
Accept: | ||
- application/json | ||
Content-Type: | ||
- application/json | ||
User-Agent: | ||
- linodego/dev https://github.com/linode/linodego | ||
url: https://api.linode.com/v4beta/lke/types?page=1 | ||
method: GET | ||
response: | ||
body: '{"data": [{"id": "lke-sa", "label": "LKE Standard Availability", "price": | ||
{"hourly": 0.0, "monthly": 0.0}, "region_prices": [], "transfer": 0}, {"id": | ||
"lke-ha", "label": "LKE High Availability", "price": {"hourly": 0.09, "monthly": | ||
60.0}, "region_prices": [{"id": "id-cgk", "hourly": 0.108, "monthly": 72.0}, | ||
{"id": "br-gru", "hourly": 0.126, "monthly": 84.0}], "transfer": 0}], "page": | ||
1, "pages": 1, "results": 2}' | ||
headers: | ||
Access-Control-Allow-Credentials: | ||
- "true" | ||
Access-Control-Allow-Headers: | ||
- Authorization, Origin, X-Requested-With, Content-Type, Accept, X-Filter | ||
Access-Control-Allow-Methods: | ||
- HEAD, GET, OPTIONS, POST, PUT, DELETE | ||
Access-Control-Allow-Origin: | ||
- '*' | ||
Access-Control-Expose-Headers: | ||
- X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Status | ||
Akamai-Internal-Account: | ||
- '*' | ||
Cache-Control: | ||
- max-age=0, no-cache, no-store | ||
Connection: | ||
- keep-alive | ||
Content-Length: | ||
- "415" | ||
Content-Security-Policy: | ||
- default-src 'none' | ||
Content-Type: | ||
- application/json | ||
Expires: | ||
- Thu, 05 Sep 2024 17:47:57 GMT | ||
Pragma: | ||
- no-cache | ||
Strict-Transport-Security: | ||
- max-age=31536000 | ||
Vary: | ||
- Authorization, X-Filter | ||
- Authorization, X-Filter | ||
X-Accepted-Oauth-Scopes: | ||
- '*' | ||
X-Content-Type-Options: | ||
- nosniff | ||
X-Frame-Options: | ||
- DENY | ||
- DENY | ||
X-Oauth-Scopes: | ||
- '*' | ||
X-Ratelimit-Limit: | ||
- "400" | ||
X-Xss-Protection: | ||
- 1; mode=block | ||
status: 200 OK | ||
code: 200 | ||
duration: "" |
70 changes: 70 additions & 0 deletions
70
test/integration/fixtures/TestNetworkTransferPrice_List.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
--- | ||
version: 1 | ||
interactions: | ||
- request: | ||
body: "" | ||
form: {} | ||
headers: | ||
Accept: | ||
- application/json | ||
Content-Type: | ||
- application/json | ||
User-Agent: | ||
- linodego/dev https://github.com/linode/linodego | ||
url: https://api.linode.com/v4beta/network-transfer/prices?page=1 | ||
method: GET | ||
response: | ||
body: '{"data": [{"id": "distributed_network_transfer", "label": "Distributed | ||
Network Transfer", "price": {"hourly": 0.01, "monthly": null}, "region_prices": | ||
[], "transfer": 0}, {"id": "network_transfer", "label": "Network Transfer", | ||
"price": {"hourly": 0.005, "monthly": null}, "region_prices": [{"id": "id-cgk", | ||
"hourly": 0.015, "monthly": null}, {"id": "br-gru", "hourly": 0.007, "monthly": | ||
null}], "transfer": 0}], "page": 1, "pages": 1, "results": 2}' | ||
headers: | ||
Access-Control-Allow-Credentials: | ||
- "true" | ||
Access-Control-Allow-Headers: | ||
- Authorization, Origin, X-Requested-With, Content-Type, Accept, X-Filter | ||
Access-Control-Allow-Methods: | ||
- HEAD, GET, OPTIONS, POST, PUT, DELETE | ||
Access-Control-Allow-Origin: | ||
- '*' | ||
Access-Control-Expose-Headers: | ||
- X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Status | ||
Akamai-Internal-Account: | ||
- '*' | ||
Cache-Control: | ||
- max-age=0, no-cache, no-store | ||
Connection: | ||
- keep-alive | ||
Content-Length: | ||
- "448" | ||
Content-Security-Policy: | ||
- default-src 'none' | ||
Content-Type: | ||
- application/json | ||
Expires: | ||
- Wed, 04 Sep 2024 18:06:01 GMT | ||
Pragma: | ||
- no-cache | ||
Strict-Transport-Security: | ||
- max-age=31536000 | ||
Vary: | ||
- Authorization, X-Filter | ||
- Authorization, X-Filter | ||
X-Accepted-Oauth-Scopes: | ||
- '*' | ||
X-Content-Type-Options: | ||
- nosniff | ||
X-Frame-Options: | ||
- DENY | ||
- DENY | ||
X-Oauth-Scopes: | ||
- '*' | ||
X-Ratelimit-Limit: | ||
- "400" | ||
X-Xss-Protection: | ||
- 1; mode=block | ||
status: 200 OK | ||
code: 200 | ||
duration: "" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
--- | ||
version: 1 | ||
interactions: | ||
- request: | ||
body: "" | ||
form: {} | ||
headers: | ||
Accept: | ||
- application/json | ||
Content-Type: | ||
- application/json | ||
User-Agent: | ||
- linodego/dev https://github.com/linode/linodego | ||
url: https://api.linode.com/v4beta/nodebalancers/types?page=1 | ||
method: GET | ||
response: | ||
body: '{"data": [{"id": "nodebalancer", "label": "NodeBalancer", "price": {"hourly": | ||
0.015, "monthly": 10.0}, "region_prices": [{"id": "id-cgk", "hourly": 0.018, | ||
"monthly": 12.0}, {"id": "br-gru", "hourly": 0.021, "monthly": 14.0}], "transfer": | ||
0}], "page": 1, "pages": 1, "results": 1}' | ||
headers: | ||
Access-Control-Allow-Credentials: | ||
- "true" | ||
Access-Control-Allow-Headers: | ||
- Authorization, Origin, X-Requested-With, Content-Type, Accept, X-Filter | ||
Access-Control-Allow-Methods: | ||
- HEAD, GET, OPTIONS, POST, PUT, DELETE | ||
Access-Control-Allow-Origin: | ||
- '*' | ||
Access-Control-Expose-Headers: | ||
- X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Status | ||
Akamai-Internal-Account: | ||
- '*' | ||
Cache-Control: | ||
- max-age=0, no-cache, no-store | ||
Connection: | ||
- keep-alive | ||
Content-Length: | ||
- "279" | ||
Content-Security-Policy: | ||
- default-src 'none' | ||
Content-Type: | ||
- application/json | ||
Expires: | ||
- Wed, 04 Sep 2024 17:52:02 GMT | ||
Pragma: | ||
- no-cache | ||
Strict-Transport-Security: | ||
- max-age=31536000 | ||
Vary: | ||
- Authorization, X-Filter | ||
- Authorization, X-Filter | ||
X-Accepted-Oauth-Scopes: | ||
- '*' | ||
X-Content-Type-Options: | ||
- nosniff | ||
X-Frame-Options: | ||
- DENY | ||
- DENY | ||
X-Oauth-Scopes: | ||
- '*' | ||
X-Ratelimit-Limit: | ||
- "400" | ||
X-Xss-Protection: | ||
- 1; mode=block | ||
status: 200 OK | ||
code: 200 | ||
duration: "" |
Oops, something went wrong.