Skip to content

Commit

Permalink
Merge branch 'main' into TPT-3246/support-missing-instance-lke
Browse files Browse the repository at this point in the history
  • Loading branch information
yec-akamai authored Nov 19, 2024
2 parents 744b32e + d7dbe30 commit 1126407
Show file tree
Hide file tree
Showing 23 changed files with 1,989 additions and 13 deletions.
27 changes: 20 additions & 7 deletions placement_groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,26 @@ type PlacementGroupMember struct {

// PlacementGroup represents a Linode placement group.
type PlacementGroup struct {
ID int `json:"id"`
Label string `json:"label"`
Region string `json:"region"`
PlacementGroupType PlacementGroupType `json:"placement_group_type"`
PlacementGroupPolicy PlacementGroupPolicy `json:"placement_group_policy"`
IsCompliant bool `json:"is_compliant"`
Members []PlacementGroupMember `json:"members"`
ID int `json:"id"`
Label string `json:"label"`
Region string `json:"region"`
PlacementGroupType PlacementGroupType `json:"placement_group_type"`
PlacementGroupPolicy PlacementGroupPolicy `json:"placement_group_policy"`
IsCompliant bool `json:"is_compliant"`
Members []PlacementGroupMember `json:"members"`
Migrations PlacementGroupMigrations `json:"migrations"`
}

// PlacementGroupMigrations represent the instances that are being migrated to or from the placement group.
type PlacementGroupMigrations struct {
Inbound []struct {
// The unique identifier for a compute instance being migrated into the placement group.
LinodeID int `json:"linode_id"`
} `json:"inbound"`
Outbound []struct {
// The unique identifier for a compute instance being migrated out of the placement group.
LinodeID int `json:"linode_id"`
} `json:"outbound"`
}

// PlacementGroupCreateOptions represents the options to use
Expand Down
73 changes: 73 additions & 0 deletions profile_apps.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package linodego

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

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

// ProfileApp represents a ProfileApp object
type ProfileApp struct {
// When this app was authorized.
Created *time.Time `json:"-"`

// When the app's access to your account expires.
Expiry *time.Time `json:"-"`

// This authorization's ID, used for revoking access.
ID int `json:"id"`

// The name of the application you've authorized.
Label string `json:"label"`

// The OAuth scopes this app was authorized with.
Scopes string `json:"scopes"`

// The URL at which this app's thumbnail may be accessed.
ThumbnailURL string `json:"thumbnail_url"`

// The website where you can get more information about this app.
Website string `json:"website"`
}

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

l := struct {
*Mask
Created *parseabletime.ParseableTime `json:"created"`
Expiry *parseabletime.ParseableTime `json:"expiry"`
}{
Mask: (*Mask)(pa),
}

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

pa.Created = (*time.Time)(l.Created)
pa.Expiry = (*time.Time)(l.Expiry)

return nil
}

// GetProfileApp returns the ProfileApp with the provided id
func (c *Client) GetProfileApp(ctx context.Context, appID int) (*ProfileApp, error) {
e := formatAPIPath("profile/apps/%d", appID)
return doGETRequest[ProfileApp](ctx, c, e)
}

// ListProfileApps lists ProfileApps that have access to the Account
func (c *Client) ListProfileApps(ctx context.Context, opts *ListOptions) ([]ProfileApp, error) {
return getPaginatedResults[ProfileApp](ctx, c, "profile/apps", opts)
}

// DeleteProfileApp revokes the given ProfileApp's access to the account
func (c *Client) DeleteProfileApp(ctx context.Context, appID int) error {
e := formatAPIPath("profile/apps/%d", appID)
err := doDELETERequest(ctx, c, e)
return err
}
72 changes: 72 additions & 0 deletions profile_devices.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package linodego

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

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

// ProfileDevice represents a ProfileDevice object
type ProfileDevice struct {
// When this Remember Me session was started.
Created *time.Time `json:"-"`

// When this TrustedDevice session expires. Sessions typically last 30 days.
Expiry *time.Time `json:"-"`

// The unique ID for this TrustedDevice.
ID int `json:"id"`

// he last time this TrustedDevice was successfully used to authenticate to login.linode.com
LastAuthenticated *time.Time `json:"-"`

// The last IP Address to successfully authenticate with this TrustedDevice.
LastRemoteAddr string `json:"last_remote_addr"`

// The User Agent of the browser that created this TrustedDevice session.
UserAgent string `json:"user_agent"`
}

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

l := struct {
*Mask
Created *parseabletime.ParseableTime `json:"created"`
Expiry *parseabletime.ParseableTime `json:"expiry"`
LastAuthenticated *parseabletime.ParseableTime `json:"last_authenticated"`
}{
Mask: (*Mask)(pd),
}

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

pd.Created = (*time.Time)(l.Created)
pd.Expiry = (*time.Time)(l.Expiry)
pd.LastAuthenticated = (*time.Time)(l.LastAuthenticated)

return nil
}

// GetProfileDevice returns the ProfileDevice with the provided id
func (c *Client) GetProfileDevice(ctx context.Context, deviceID int) (*ProfileDevice, error) {
e := formatAPIPath("profile/devices/%d", deviceID)
return doGETRequest[ProfileDevice](ctx, c, e)
}

// ListProfileDevices lists ProfileDevices for the User
func (c *Client) ListProfileDevices(ctx context.Context, opts *ListOptions) ([]ProfileDevice, error) {
return getPaginatedResults[ProfileDevice](ctx, c, "profile/devices", opts)
}

// DeleteProfileDevice revokes the given ProfileDevice's status as a trusted device
func (c *Client) DeleteProfileDevice(ctx context.Context, deviceID int) error {
e := formatAPIPath("profile/devices/%d", deviceID)
err := doDELETERequest(ctx, c, e)
return err
}
32 changes: 32 additions & 0 deletions profile_preferences.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package linodego

import (
"context"
"encoding/json"
)

// ProfilePreferences represents the user's preferences.
// The user preferences endpoints allow consumers of the API to store arbitrary JSON data,
// such as a user's font size preference or preferred display name.
type ProfilePreferences map[string]interface{}

// UnmarshalJSON implements the json.Unmarshaler interface
func (p *ProfilePreferences) UnmarshalJSON(b []byte) error {
var data map[string]interface{}
if err := json.Unmarshal(b, &data); err != nil {
return err
}

*p = data
return nil
}

// GetProfilePreferences retrieves the user preferences for the current User
func (c *Client) GetProfilePreferences(ctx context.Context) (*ProfilePreferences, error) {
return doGETRequest[ProfilePreferences](ctx, c, "profile/preferences")
}

// UpdateProfilePreferences updates the user's preferences with the provided data
func (c *Client) UpdateProfilePreferences(ctx context.Context, opts ProfilePreferences) (*ProfilePreferences, error) {
return doPUTRequest[ProfilePreferences](ctx, c, "profile/preferences", opts)
}
Loading

0 comments on commit 1126407

Please sign in to comment.