Skip to content

Don't Propagate Attributes on Disabled Instance Policy #125

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 21 additions & 10 deletions instances.go
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,7 @@ func (c *Client) SetInstancePolicies(ctx context.Context, policies MultiplePolic
PolicyType: AllowedNetwork,
PolicyData: PolicyData{
Enabled: &(policies.AllowedNetwork.Enabled),
// due to legacy reasons, the allowed_network policy requires attribute to always be specified
Attributes: &Attributes{
AllowedNetwork: &(policies.AllowedNetwork.Network),
},
Expand All @@ -505,11 +506,16 @@ func (c *Client) SetInstancePolicies(ctx context.Context, policies MultiplePolic
PolicyType: AllowedIP,
PolicyData: PolicyData{
Enabled: &(policies.AllowedIP.Enabled),
Attributes: &Attributes{
AllowedIP: policies.AllowedIP.IPAddresses,
},
},
}

// attributes can only be provided if policy is being enabled
// ignore any attribute inputs if provided during a disable
if policies.AllowedIP.Enabled {
policy.PolicyData.Attributes = &Attributes{
AllowedIP: policies.AllowedIP.IPAddresses,
}
}
resPolicies = append(resPolicies, policy)
}

Expand All @@ -527,16 +533,21 @@ func (c *Client) SetInstancePolicies(ctx context.Context, policies MultiplePolic
policy := InstancePolicy{
PolicyType: KeyCreateImportAccess,
PolicyData: PolicyData{
Enabled: &(policies.KeyCreateImportAccess.Enabled),
Attributes: &Attributes{},
Enabled: &(policies.KeyCreateImportAccess.Enabled),
},
}

policy.PolicyData.Attributes.CreateRootKey = &policies.KeyCreateImportAccess.CreateRootKey
policy.PolicyData.Attributes.CreateStandardKey = &policies.KeyCreateImportAccess.CreateStandardKey
policy.PolicyData.Attributes.ImportRootKey = &policies.KeyCreateImportAccess.ImportRootKey
policy.PolicyData.Attributes.ImportStandardKey = &policies.KeyCreateImportAccess.ImportStandardKey
policy.PolicyData.Attributes.EnforceToken = &policies.KeyCreateImportAccess.EnforceToken
// attributes can only be provided if policy is being enabled
// ignore any attribute inputs if provided during a disable
if policies.KeyCreateImportAccess.Enabled {
policy.PolicyData.Attributes = &Attributes{
CreateRootKey: &policies.KeyCreateImportAccess.CreateRootKey,
CreateStandardKey: &policies.KeyCreateImportAccess.CreateStandardKey,
ImportRootKey: &policies.KeyCreateImportAccess.ImportRootKey,
ImportStandardKey: &policies.KeyCreateImportAccess.ImportStandardKey,
EnforceToken: &policies.KeyCreateImportAccess.EnforceToken,
}
}

resPolicies = append(resPolicies, policy)
}
Expand Down