Skip to content

Commit

Permalink
Added support for missing User-related fields (#622)
Browse files Browse the repository at this point in the history
* Added support for missing user fields

* Reran GetMonthlyTransfer fixture
  • Loading branch information
ezilber-akamai authored Dec 2, 2024
1 parent 6106012 commit 95e95bd
Show file tree
Hide file tree
Showing 14 changed files with 822 additions and 380 deletions.
43 changes: 25 additions & 18 deletions account_user_grants.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,12 @@ type GlobalUserGrants struct {
AddLinodes bool `json:"add_linodes"`
AddLongview bool `json:"add_longview"`
AddNodeBalancers bool `json:"add_nodebalancers"`
AddPlacementGroups bool `json:"add_placement_groups"`
AddStackScripts bool `json:"add_stackscripts"`
AddVolumes bool `json:"add_volumes"`
AddVPCs bool `json:"add_vpcs"`
CancelAccount bool `json:"cancel_account"`
ChildAccountAccess bool `json:"child_account_access"`
LongviewSubscription bool `json:"longview_subscription"`
}

Expand All @@ -38,29 +41,33 @@ type GrantedEntity struct {
}

type UserGrants struct {
Database []GrantedEntity `json:"database"`
Domain []GrantedEntity `json:"domain"`
Firewall []GrantedEntity `json:"firewall"`
Image []GrantedEntity `json:"image"`
Linode []GrantedEntity `json:"linode"`
Longview []GrantedEntity `json:"longview"`
NodeBalancer []GrantedEntity `json:"nodebalancer"`
StackScript []GrantedEntity `json:"stackscript"`
Volume []GrantedEntity `json:"volume"`
Database []GrantedEntity `json:"database"`
Domain []GrantedEntity `json:"domain"`
Firewall []GrantedEntity `json:"firewall"`
Image []GrantedEntity `json:"image"`
Linode []GrantedEntity `json:"linode"`
Longview []GrantedEntity `json:"longview"`
NodeBalancer []GrantedEntity `json:"nodebalancer"`
PlacementGroup []GrantedEntity `json:"placement_group"`
StackScript []GrantedEntity `json:"stackscript"`
Volume []GrantedEntity `json:"volume"`
VPC []GrantedEntity `json:"vpc"`

Global GlobalUserGrants `json:"global"`
}

type UserGrantsUpdateOptions struct {
Database []GrantedEntity `json:"database,omitempty"`
Domain []EntityUserGrant `json:"domain,omitempty"`
Firewall []EntityUserGrant `json:"firewall,omitempty"`
Image []EntityUserGrant `json:"image,omitempty"`
Linode []EntityUserGrant `json:"linode,omitempty"`
Longview []EntityUserGrant `json:"longview,omitempty"`
NodeBalancer []EntityUserGrant `json:"nodebalancer,omitempty"`
StackScript []EntityUserGrant `json:"stackscript,omitempty"`
Volume []EntityUserGrant `json:"volume,omitempty"`
Database []GrantedEntity `json:"database,omitempty"`
Domain []EntityUserGrant `json:"domain,omitempty"`
Firewall []EntityUserGrant `json:"firewall,omitempty"`
Image []EntityUserGrant `json:"image,omitempty"`
Linode []EntityUserGrant `json:"linode,omitempty"`
Longview []EntityUserGrant `json:"longview,omitempty"`
NodeBalancer []EntityUserGrant `json:"nodebalancer,omitempty"`
PlacementGroup []EntityUserGrant `json:"placement_group,omitempty"`
StackScript []EntityUserGrant `json:"stackscript,omitempty"`
Volume []EntityUserGrant `json:"volume,omitempty"`
VPC []EntityUserGrant `json:"vpc,omitempty"`

Global GlobalUserGrants `json:"global"`
}
Expand Down
2 changes: 2 additions & 0 deletions account_users.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ type UserCreateOptions struct {
type UserUpdateOptions struct {
Username string `json:"username,omitempty"`
Restricted *bool `json:"restricted,omitempty"`
Email string `json:"email,omitempty"`
}

// UnmarshalJSON implements the json.Unmarshaler interface
Expand Down Expand Up @@ -102,6 +103,7 @@ func (i User) GetCreateOptions() (o UserCreateOptions) {
func (i User) GetUpdateOptions() (o UserUpdateOptions) {
o.Username = i.Username
o.Restricted = copyBool(&i.Restricted)
o.Email = i.Email

return
}
Expand Down
26 changes: 15 additions & 11 deletions test/integration/account_user_grants_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,19 @@ func TestUserGrants_Update(t *testing.T) {
accessLevel := linodego.AccessLevelReadOnly

globalGrants := linodego.GlobalUserGrants{
AccountAccess: &accessLevel,
AddDomains: false,
AddDatabases: true,
AddFirewalls: true,
AddImages: true,
AddLinodes: false,
AddLongview: true,
AddNodeBalancers: false,
AddStackScripts: true,
AddVolumes: true,
CancelAccount: false,
AccountAccess: &accessLevel,
AddDomains: false,
AddDatabases: true,
AddFirewalls: true,
AddImages: true,
AddLinodes: false,
AddLongview: true,
AddNodeBalancers: false,
AddPlacementGroups: false,
AddStackScripts: true,
AddVolumes: true,
AddVPCs: true,
CancelAccount: false,
}

grants, err := client.UpdateUserGrants(context.TODO(), username, linodego.UserGrantsUpdateOptions{
Expand Down Expand Up @@ -83,8 +85,10 @@ func TestUserGrants_UpdateNoAccess(t *testing.T) {
grants.Linode,
grants.Longview,
grants.NodeBalancer,
grants.PlacementGroup,
grants.StackScript,
grants.Volume,
grants.VPC,
}

for _, grantField := range grantFields {
Expand Down
Loading

0 comments on commit 95e95bd

Please sign in to comment.