Skip to content

Commit

Permalink
Merge branch 'main' into proj/disk-encryption
Browse files Browse the repository at this point in the history
  • Loading branch information
lgarber-akamai committed Jul 3, 2024
2 parents 6a6014f + a9a7dcf commit 3a6208e
Show file tree
Hide file tree
Showing 193 changed files with 46,785 additions and 27,164 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,4 @@ jobs:
python tod_scripts/test_report_upload_script.py "$REPORT_FILENAME"
env:
LINODE_CLI_OBJ_ACCESS_KEY: ${{ secrets.LINODE_CLI_OBJ_ACCESS_KEY }}
LINODE_CLI_OBJ_SECRET_KEY: ${{ secrets.LINODE_CLI_OBJ_SECRET_KEY }}
LINODE_CLI_OBJ_SECRET_KEY: ${{ secrets.LINODE_CLI_OBJ_SECRET_KEY }}
15 changes: 15 additions & 0 deletions .github/workflows/integration_tests_pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ jobs:
with:
ref: ${{ inputs.sha }}

- name: Download kubectl and calicoctl for LKE clusters
run: |
curl -LO "https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl"
curl -LO "https://github.com/projectcalico/calico/releases/download/v3.25.0/calicoctl-linux-amd64"
chmod +x calicoctl-linux-amd64 kubectl
mv calicoctl-linux-amd64 /usr/local/bin/calicoctl
mv kubectl /usr/local/bin/kubectl
- run: make ARGS="-run ${{ inputs.module }}" fixtures
if: ${{ inputs.module != '' && steps.disallowed-char-check.outputs.match == '' }}
env:
Expand All @@ -44,6 +52,13 @@ jobs:
if: ${{ inputs.module == '' }}
env:
LINODE_TOKEN: ${{ secrets.DX_LINODE_TOKEN }}

- name: Apply Calico Rules to LKE
if: always()
run: |
cd scripts && ./lke_calico_rules_e2e.sh
env:
LINODE_TOKEN: ${{ secrets.DX_LINODE_TOKEN }}

- name: Get the hash value of the latest commit from the PR branch
uses: octokit/graphql-action@v2.x
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ run_fixtures:
LINODE_API_VERSION="v4beta" \
LINODE_URL="$(LINODE_URL)" \
GO111MODULE="on" \
go test -timeout=$(TEST_TIMEOUT) -v $(ARGS)
go test --tags $(TEST_TAGS) -timeout=$(TEST_TIMEOUT) -v $(ARGS)

sanitize:
@echo "* Sanitizing fixtures"
Expand Down
47 changes: 23 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,36 +33,35 @@ package main
import (
"context"
"fmt"

"github.com/linode/linodego"
"golang.org/x/oauth2"

"log"
"net/http"
"os"

"github.com/linode/linodego"
"golang.org/x/oauth2"
)

func main() {
apiKey, ok := os.LookupEnv("LINODE_TOKEN")
if !ok {
log.Fatal("Could not find LINODE_TOKEN, please assert it is set.")
}
tokenSource := oauth2.StaticTokenSource(&oauth2.Token{AccessToken: apiKey})

oauth2Client := &http.Client{
Transport: &oauth2.Transport{
Source: tokenSource,
},
}

linodeClient := linodego.NewClient(oauth2Client)
linodeClient.SetDebug(true)
res, err := linodeClient.GetInstance(context.Background(), 4090913)
if err != nil {
log.Fatal(err)
}
fmt.Printf("%v", res)
apiKey, ok := os.LookupEnv("LINODE_TOKEN")
if !ok {
log.Fatal("Could not find LINODE_TOKEN, please assert it is set.")
}
tokenSource := oauth2.StaticTokenSource(&oauth2.Token{AccessToken: apiKey})

oauth2Client := &http.Client{
Transport: &oauth2.Transport{
Source: tokenSource,
},
}

linodeClient := linodego.NewClient(oauth2Client)
linodeClient.SetDebug(true)

res, err := linodeClient.GetInstance(context.Background(), 4090913)
if err != nil {
log.Fatal(err)
}
fmt.Printf("%v", res)
}
```

Expand Down
36 changes: 32 additions & 4 deletions account.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
package linodego

import "context"
import (
"context"
"encoding/json"
"time"

"github.com/linode/linodego/internal/parseabletime"
)

// Account associated with the token in use.
type Account struct {
Expand All @@ -20,6 +26,29 @@ type Account struct {
Phone string `json:"phone"`
CreditCard *CreditCard `json:"credit_card"`
EUUID string `json:"euuid"`
BillingSource string `json:"billing_source"`
Capabilities []string `json:"capabilities"`
ActiveSince *time.Time `json:"-"`
}

// UnmarshalJSON implements the json.Unmarshaler interface
func (account *Account) UnmarshalJSON(b []byte) error {
type Mask Account

p := struct {
*Mask
ActiveSince *parseabletime.ParseableTime `json:"active_since"`
}{
Mask: (*Mask)(account),
}

if err := json.Unmarshal(b, &p); err != nil {
return err
}

account.ActiveSince = (*time.Time)(p.ActiveSince)

return nil
}

// CreditCard information associated with the Account.
Expand All @@ -31,11 +60,10 @@ type CreditCard struct {
// GetAccount gets the contact and billing information related to the Account.
func (c *Client) GetAccount(ctx context.Context) (*Account, error) {
e := "account"
req := c.R(ctx).SetResult(&Account{})
r, err := coupleAPIErrors(req.Get(e))
response, err := doGETRequest[Account](ctx, c, e)
if err != nil {
return nil, err
}

return r.Result().(*Account), nil
return response, nil
}
39 changes: 6 additions & 33 deletions account_availability.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ package linodego

import (
"context"
"fmt"
"net/url"

"github.com/go-resty/resty/v2"
)

// AccountAvailability returns the resources availability in a region to an account.
Expand All @@ -20,46 +16,23 @@ type AccountAvailability struct {
Available []string `json:"available"`
}

// AccountAvailabilityPagedResponse represents a paginated Account Availability API response
type AccountAvailabilityPagedResponse struct {
*PageOptions
Data []AccountAvailability `json:"data"`
}

// endpoint gets the endpoint URL for AccountAvailability
func (AccountAvailabilityPagedResponse) endpoint(_ ...any) string {
return "/account/availability"
}

func (resp *AccountAvailabilityPagedResponse) castResult(r *resty.Request, e string) (int, int, error) {
res, err := coupleAPIErrors(r.SetResult(AccountAvailabilityPagedResponse{}).Get(e))
if err != nil {
return 0, 0, err
}
castedRes := res.Result().(*AccountAvailabilityPagedResponse)
resp.Data = append(resp.Data, castedRes.Data...)
return castedRes.Pages, castedRes.Results, nil
}

// ListAccountAvailabilities lists all regions and the resource availabilities to the account.
func (c *Client) ListAccountAvailabilities(ctx context.Context, opts *ListOptions) ([]AccountAvailability, error) {
response := AccountAvailabilityPagedResponse{}
err := c.listHelper(ctx, &response, opts)
response, err := getPaginatedResults[AccountAvailability](ctx, c, "account/availability", opts)
if err != nil {
return nil, err
}
return response.Data, nil

return response, nil
}

// GetAccountAvailability gets the resources availability in a region to the customer.
func (c *Client) GetAccountAvailability(ctx context.Context, regionID string) (*AccountAvailability, error) {
req := c.R(ctx).SetResult(&AccountAvailability{})
regionID = url.PathEscape(regionID)
b := fmt.Sprintf("account/availability/%s", regionID)
r, err := coupleAPIErrors(req.Get(b))
b := formatAPIPath("account/availability/%s", regionID)
response, err := doGETRequest[AccountAvailability](ctx, c, b)
if err != nil {
return nil, err
}

return r.Result().(*AccountAvailability), nil
return response, nil
}
49 changes: 9 additions & 40 deletions account_betas.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@ package linodego
import (
"context"
"encoding/json"
"fmt"
"net/url"
"time"

"github.com/go-resty/resty/v2"
"github.com/linode/linodego/internal/parseabletime"
)

Expand All @@ -28,17 +25,6 @@ type AccountBetaProgramCreateOpts struct {
ID string `json:"id"`
}

// AccountBetasPagedResponse represents a paginated Account Beta Programs API response
type AccountBetasPagedResponse struct {
*PageOptions
Data []AccountBetaProgram `json:"data"`
}

// endpoint gets the endpoint URL for AccountBetaProgram
func (AccountBetasPagedResponse) endpoint(_ ...any) string {
return "/account/betas"
}

// UnmarshalJSON implements the json.Unmarshaler interface
func (cBeta *AccountBetaProgram) UnmarshalJSON(b []byte) error {
type Mask AccountBetaProgram
Expand All @@ -63,52 +49,35 @@ func (cBeta *AccountBetaProgram) UnmarshalJSON(b []byte) error {
return nil
}

func (resp *AccountBetasPagedResponse) castResult(r *resty.Request, e string) (int, int, error) {
res, err := coupleAPIErrors(r.SetResult(AccountBetasPagedResponse{}).Get(e))
if err != nil {
return 0, 0, err
}
castedRes := res.Result().(*AccountBetasPagedResponse)
resp.Data = append(resp.Data, castedRes.Data...)
return castedRes.Pages, castedRes.Results, nil
}

// ListAccountBetaPrograms lists all beta programs an account is enrolled in.
func (c *Client) ListAccountBetaPrograms(ctx context.Context, opts *ListOptions) ([]AccountBetaProgram, error) {
response := AccountBetasPagedResponse{}
err := c.listHelper(ctx, &response, opts)
response, err := getPaginatedResults[AccountBetaProgram](ctx, c, "/account/betas", opts)
if err != nil {
return nil, err
}
return response.Data, nil

return response, nil
}

// GetAccountBetaProgram gets the details of a beta program an account is enrolled in.
func (c *Client) GetAccountBetaProgram(ctx context.Context, betaID string) (*AccountBetaProgram, error) {
req := c.R(ctx).SetResult(&AccountBetaProgram{})
betaID = url.PathEscape(betaID)
b := fmt.Sprintf("/account/betas/%s", betaID)
r, err := coupleAPIErrors(req.Get(b))
b := formatAPIPath("/account/betas/%s", betaID)

response, err := doGETRequest[AccountBetaProgram](ctx, c, b)
if err != nil {
return nil, err
}

return r.Result().(*AccountBetaProgram), nil
return response, nil
}

// JoinBetaProgram enrolls an account into a beta program.
func (c *Client) JoinBetaProgram(ctx context.Context, opts AccountBetaProgramCreateOpts) (*AccountBetaProgram, error) {
body, err := json.Marshal(opts)
if err != nil {
return nil, err
}

e := "account/betas"
req := c.R(ctx).SetResult(&AccountBetaProgram{}).SetBody(string(body))
r, err := coupleAPIErrors(req.Post(e))
response, err := doPOSTRequest[AccountBetaProgram](ctx, c, e, opts)
if err != nil {
return nil, err
}

return r.Result().(*AccountBetaProgram), nil
return response, nil
}
47 changes: 47 additions & 0 deletions account_child.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package linodego

import (
"context"
)

// ChildAccount represents an account under the current account.
// NOTE: This is an alias to prevent any future breaking changes.
type ChildAccount = Account

// ChildAccountToken represents a short-lived token created using
// the CreateChildAccountToken(...) function.
// NOTE: This is an alias to prevent any future breaking changes.
type ChildAccountToken = Token

// ListChildAccounts lists child accounts under the current account.
// NOTE: Parent/Child related features may not be generally available.
func (c *Client) ListChildAccounts(ctx context.Context, opts *ListOptions) ([]ChildAccount, error) {
return getPaginatedResults[ChildAccount](
ctx,
c,
"account/child-accounts",
opts,
)
}

// GetChildAccount gets a single child accounts under the current account.
// NOTE: Parent/Child related features may not be generally available.
func (c *Client) GetChildAccount(ctx context.Context, euuid string) (*ChildAccount, error) {
return doGETRequest[ChildAccount](
ctx,
c,
formatAPIPath("account/child-accounts/%s", euuid),
)
}

// CreateChildAccountToken creates a short-lived token that can be used to
// access the Linode API under a child account.
// The attributes of this token are not currently configurable.
// NOTE: Parent/Child related features may not be generally available.
func (c *Client) CreateChildAccountToken(ctx context.Context, euuid string) (*ChildAccountToken, error) {
return doPOSTRequest[ChildAccountToken, any](
ctx,
c,
formatAPIPath("account/child-accounts/%s/token", euuid),
)
}
Loading

0 comments on commit 3a6208e

Please sign in to comment.