-
Notifications
You must be signed in to change notification settings - Fork 19
/
iam_org_policy_reset.go
57 lines (43 loc) · 1.62 KB
/
iam_org_policy_reset.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package cmd
import (
"github.com/spf13/cobra"
"github.com/exoscale/cli/pkg/account"
"github.com/exoscale/cli/pkg/globalstate"
exoscale "github.com/exoscale/egoscale/v2"
exoapi "github.com/exoscale/egoscale/v2/api"
)
type iamOrgPolicyResetCmd struct {
cliCommandSettings `cli-cmd:"-"`
Force bool `cli-short:"f" cli-usage:"don't prompt for confirmation"`
_ bool `cli-cmd:"reset"`
}
func (c *iamOrgPolicyResetCmd) cmdAliases() []string { return nil }
func (c *iamOrgPolicyResetCmd) cmdShort() string {
return "Reset Org policy to default"
}
func (c *iamOrgPolicyResetCmd) cmdLong() string {
return `This command resets the IAM Organization Policy to the default (allow all).
This will remove any constraints that were set in the Org Policy.`
}
func (c *iamOrgPolicyResetCmd) cmdPreRun(cmd *cobra.Command, args []string) error {
return cliCommandDefaultPreRun(c, cmd, args)
}
func (c *iamOrgPolicyResetCmd) cmdRun(cmd *cobra.Command, _ []string) error {
if !c.Force {
if !askQuestion("This action will reset your Org Policy to the default, removing any constraints that were set in the Org Policy. Proceed?") {
return nil
}
}
zone := account.CurrentAccount.DefaultZone
ctx := exoapi.WithEndpoint(gContext, exoapi.NewReqEndpoint(account.CurrentAccount.Environment, zone))
policy := &exoscale.IAMPolicy{
DefaultServiceStrategy: "allow",
Services: map[string]exoscale.IAMPolicyService{},
}
return globalstate.EgoscaleClient.UpdateIAMOrgPolicy(ctx, zone, policy)
}
func init() {
cobra.CheckErr(registerCLICommand(iamOrgPolicyCmd, &iamOrgPolicyResetCmd{
cliCommandSettings: defaultCLICmdSettings(),
}))
}