Skip to content

Commit fb0a239

Browse files
committed
Merge branch 'main' into proj/frontend-vpcs
2 parents ba8bc59 + 59230a7 commit fb0a239

28 files changed

Lines changed: 2749 additions & 31 deletions

.golangci.yml

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,9 @@ linters:
55
default: all
66
disable:
77
- bodyclose
8-
- contextcheck
98
- cyclop
109
- depguard
1110
- dupl
12-
- durationcheck
1311
- err113
1412
- errcheck
1513
- errname
@@ -19,30 +17,20 @@ linters:
1917
- forcetypeassert
2018
- gochecknoglobals
2119
- gochecknoinits
22-
- gocyclo
2320
- godot
24-
- gosec
2521
- inamedparam
2622
- lll
2723
- musttag
28-
- nakedret
2924
- nilerr
3025
- nlreturn
31-
- noctx
3226
- noinlineerr
3327
- nolintlint
3428
- nonamedreturns
3529
- perfsprint
3630
- recvcheck
37-
- rowserrcheck
38-
- sqlclosecheck
3931
- staticcheck
40-
- tagalign
4132
- tagliatelle
42-
- tparallel
43-
- unparam
4433
- varnamelen
45-
- wastedassign
4634
- wrapcheck
4735
- wsl
4836
settings:

alert_channels.go

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
package linodego
2+
3+
import (
4+
"context"
5+
"encoding/json"
6+
"time"
7+
8+
"github.com/linode/linodego/internal/parseabletime"
9+
)
10+
11+
type AlertNotificationType string
12+
13+
const (
14+
EmailAlertNotification AlertNotificationType = "email"
15+
)
16+
17+
type AlertChannelType string
18+
19+
const (
20+
SystemAlertChannel AlertChannelType = "system"
21+
UserAlertChannel AlertChannelType = "user"
22+
)
23+
24+
// AlertChannelEnvelope represents a single alert channel entry returned inside alert definition
25+
type AlertChannelEnvelope struct {
26+
ID int `json:"id"`
27+
Label string `json:"label"`
28+
Type string `json:"type"`
29+
URL string `json:"url"`
30+
}
31+
32+
// AlertChannel represents a Monitor Channel object.
33+
type AlertChannel struct {
34+
Alerts []AlertChannelEnvelope `json:"alerts"`
35+
ChannelType AlertNotificationType `json:"channel_type"`
36+
Content ChannelContent `json:"content"`
37+
Created *time.Time `json:"-"`
38+
CreatedBy string `json:"created_by"`
39+
Updated *time.Time `json:"-"`
40+
UpdatedBy string `json:"updated_by"`
41+
ID int `json:"id"`
42+
Label string `json:"label"`
43+
Type AlertChannelType `json:"type"`
44+
}
45+
46+
type EmailChannelContent struct {
47+
EmailAddresses []string `json:"email_addresses"`
48+
}
49+
50+
// ChannelContent represents the content block for an AlertChannel, which varies by channel type.
51+
type ChannelContent struct {
52+
Email *EmailChannelContent `json:"email"`
53+
// Other channel types like 'webhook', 'slack' could be added here as optional fields.
54+
}
55+
56+
// UnmarshalJSON implements the json.Unmarshaler interface
57+
func (a *AlertChannel) UnmarshalJSON(b []byte) error {
58+
type Mask AlertChannel
59+
60+
p := struct {
61+
*Mask
62+
63+
Updated *parseabletime.ParseableTime `json:"updated"`
64+
Created *parseabletime.ParseableTime `json:"created"`
65+
}{
66+
Mask: (*Mask)(a),
67+
}
68+
69+
if err := json.Unmarshal(b, &p); err != nil {
70+
return err
71+
}
72+
73+
a.Updated = (*time.Time)(p.Updated)
74+
a.Created = (*time.Time)(p.Created)
75+
76+
return nil
77+
}
78+
79+
// ListAlertChannels gets a paginated list of Alert Channels.
80+
func (c *Client) ListAlertChannels(ctx context.Context, opts *ListOptions) ([]AlertChannel, error) {
81+
endpoint := formatAPIPath("monitor/alert-channels")
82+
return getPaginatedResults[AlertChannel](ctx, c, endpoint, opts)
83+
}

entities.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package linodego
2+
3+
import "context"
4+
5+
// LinodeEntity is anything in Linode with IAM Permissions
6+
type LinodeEntity struct {
7+
ID int `json:"id"`
8+
Label string `json:"label"`
9+
Type string `json:"type"`
10+
}
11+
12+
// ListEntities returns a paginated list of all entities
13+
func (c *Client) ListEntities(ctx context.Context, opts *ListOptions) ([]LinodeEntity, error) {
14+
return getPaginatedResults[LinodeEntity](ctx, c, "entities", opts)
15+
}
16+
17+
// GetEntityRoles returns a list of roles for the entity and user
18+
func (c *Client) GetEntityRoles(ctx context.Context, username string, entityType string, entityID int) ([]string, error) {
19+
perms, err := doGETRequest[[]string](ctx, c,
20+
formatAPIPath("iam/users/%s/permissions/%s/%d", username, entityType, entityID))
21+
if err != nil || perms == nil {
22+
return nil, err
23+
}
24+
25+
return (*perms), err
26+
}

iam.go

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
package linodego
2+
3+
import "context"
4+
5+
// UserRolePermissions are the account and entity permissions for the User
6+
type UserRolePermissions struct {
7+
AccountAccess []string `json:"account_access"`
8+
EntityAccess []UserAccess `json:"entity_access"`
9+
}
10+
11+
// GetUpdateOptions converts UserRolePermissions for use in UpdateUserRolePermissions
12+
func (p *UserRolePermissions) GetUpdateOptions() UserRolePermissionsUpdateOptions {
13+
return UserRolePermissionsUpdateOptions{
14+
AccountAccess: p.AccountAccess,
15+
EntityAccess: p.EntityAccess,
16+
}
17+
}
18+
19+
// UserRolePermissionsUpdateOptions are fields accepted by UpdateUserRolePermissions
20+
type UserRolePermissionsUpdateOptions struct {
21+
AccountAccess []string `json:"account_access"`
22+
EntityAccess []UserAccess `json:"entity_access"`
23+
}
24+
25+
// UserAccess is the breakdown of entities Roles
26+
type UserAccess struct {
27+
ID int `json:"id"`
28+
Type string `json:"type"`
29+
Roles []string `json:"roles"`
30+
}
31+
32+
// AccountRolePermissions are the account and entity roles for the Account
33+
type AccountRolePermissions struct {
34+
AccountAccess []AccountAccess `json:"account_access"`
35+
EntityAccess []AccountAccess `json:"entity_access"`
36+
}
37+
38+
// AccountAccess is the Roles for each Type for the Account
39+
type AccountAccess struct {
40+
Type string `json:"type"`
41+
Roles []Role `json:"roles"`
42+
}
43+
44+
// Role is the IAM Role and its Permissions
45+
type Role struct {
46+
Name string `json:"name"`
47+
Description string `json:"description"`
48+
Permissions []string `json:"permissions"`
49+
}
50+
51+
// GetUserRolePermissions returns any role permissions for username
52+
func (c *Client) GetUserRolePermissions(ctx context.Context, username string) (*UserRolePermissions, error) {
53+
return doGETRequest[UserRolePermissions](ctx, c,
54+
formatAPIPath("iam/users/%s/role-permissions", username),
55+
)
56+
}
57+
58+
// UpdateUserRolePermissions updates any role permissions for username
59+
func (c *Client) UpdateUserRolePermissions(ctx context.Context, username string, opts UserRolePermissionsUpdateOptions) (*UserRolePermissions, error) {
60+
return doPUTRequest[UserRolePermissions](ctx, c,
61+
formatAPIPath("iam/users/%s/role-permissions", username),
62+
opts,
63+
)
64+
}
65+
66+
// GetAccountRolePermissions returns the role permissions for this Account
67+
func (c *Client) GetAccountRolePermissions(ctx context.Context) (*AccountRolePermissions, error) {
68+
return doGETRequest[AccountRolePermissions](ctx, c, "iam/role-permissions")
69+
}
70+
71+
// GetUserAccountPermissions returns the account permissions for username
72+
func (c *Client) GetUserAccountPermissions(ctx context.Context, username string) ([]string, error) {
73+
perms, err := doGETRequest[[]string](ctx, c,
74+
formatAPIPath("iam/users/%s/permissions/account", username))
75+
if err != nil || perms == nil {
76+
return nil, err
77+
}
78+
79+
return (*perms), err
80+
}

0 commit comments

Comments
 (0)