-
Notifications
You must be signed in to change notification settings - Fork 69
/
contracts.go
51 lines (42 loc) · 1.32 KB
/
contracts.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
package edgeworkers
import (
"context"
"errors"
"fmt"
"net/http"
)
type (
// Contracts is an edgeworkers contracts API interface
Contracts interface {
// ListContracts lists contract IDs that can be used to list resource tiers
//
// See: https://techdocs.akamai.com/edgeworkers/reference/get-contracts-1
ListContracts(context.Context) (*ListContractsResponse, error)
}
// ListContractsResponse represents a response object returned by ListContracts
ListContractsResponse struct {
ContractIDs []string `json:"contractIds"`
}
)
var (
// ErrListContracts is returned in case an error occurs on ListContracts operation
ErrListContracts = errors.New("list contracts")
)
func (e *edgeworkers) ListContracts(ctx context.Context) (*ListContractsResponse, error) {
logger := e.Log(ctx)
logger.Debug("ListContracts")
uri := "/edgeworkers/v1/contracts"
req, err := http.NewRequestWithContext(ctx, http.MethodGet, uri, nil)
if err != nil {
return nil, fmt.Errorf("%w: failed to create request: %s", ErrListContracts, err)
}
var result ListContractsResponse
resp, err := e.Exec(req, &result)
if err != nil {
return nil, fmt.Errorf("%w: request failed: %s", ErrListContracts, err)
}
if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("%s: %w", ErrListContracts, e.Error(resp))
}
return &result, nil
}