-
Notifications
You must be signed in to change notification settings - Fork 114
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
[A2-572] Add 'viewer' and 'editor' users to local-dev and dev/acceptance envs, add --skip-policy-migration
to upgrade-to-v2
#403
Changes from all commits
fd53817
5d928c9
e66dde3
d448ad2
6f084f7
7230d15
35e1d6e
a3f140b
1fee8f2
2861676
d0bedb7
a94090c
5cbf498
1ce7045
2501bfe
f745c68
c65a147
a2add7b
613f37f
7fa7955
49ce217
aeeed92
8c2849f
61ccc53
922ebd0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,8 @@ import ( | |
dc "github.com/chef/automate/api/config/deployment" | ||
w "github.com/chef/automate/api/config/shared/wrappers" | ||
api "github.com/chef/automate/api/interservice/deployment" | ||
"github.com/chef/automate/components/automate-cli/pkg/adminmgmt" | ||
"github.com/chef/automate/components/automate-cli/pkg/client/apiclient" | ||
"github.com/chef/automate/components/automate-cli/pkg/dev/hab" | ||
"github.com/chef/automate/components/automate-cli/pkg/docs" | ||
"github.com/chef/automate/components/automate-cli/pkg/status" | ||
|
@@ -81,6 +83,7 @@ func init() { | |
devCmd.AddCommand(newVerifyPackagesCmd()) | ||
devCmd.AddCommand(newEnablePrometheusCmd()) | ||
devCmd.AddCommand(newDisablePrometheusCmd()) | ||
devCmd.AddCommand(newCreateIAMDevUsersCmd()) | ||
RootCmd.AddCommand(devCmd) | ||
} | ||
|
||
|
@@ -940,6 +943,15 @@ func newDisablePrometheusCmd() *cobra.Command { | |
} | ||
} | ||
|
||
func newCreateIAMDevUsersCmd() *cobra.Command { | ||
return &cobra.Command{ | ||
Use: "create-iam-dev-users", | ||
RunE: runCreateIAMDevUsersCmd, | ||
Short: `Create IAM v2 dev users ("viewer" and "editor") idempotently`, | ||
Args: cobra.NoArgs, | ||
} | ||
} | ||
|
||
// Equivalent to patching the config with the following toml: | ||
// [deployment.v1.svc] | ||
// enable_dev_monitoring = true | ||
|
@@ -974,3 +986,35 @@ func runDisablePrometheusCmd(*cobra.Command, []string) error { | |
} | ||
return nil | ||
} | ||
|
||
func runCreateIAMDevUsersCmd(*cobra.Command, []string) error { | ||
ctx := context.TODO() | ||
apiClient, err := apiclient.OpenConnection(ctx) | ||
if err != nil { | ||
return err | ||
} | ||
for username, data := range map[string]struct { | ||
displayName, password, team string | ||
}{ | ||
"viewer": {"Viewer User", "chefautomate", "viewers"}, | ||
"editor": {"Editor User", "chefautomate", "editors"}, | ||
} { | ||
userID, _, err := adminmgmt.CreateUserOrUpdatePassword(ctx, | ||
apiClient, username, data.displayName, data.password, false /* dry run */) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Personal style thing for sure, but just my 2 cents: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hehe I didn't mean to convey that much -- I really just meant "this |
||
if err != nil { | ||
return err | ||
} | ||
// Note: the teams SHOULD exist. But since you never know what happens in a | ||
// long running acceptance env, we'll better ensure them: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. s/we'll/we'd/ |
||
teamID, _, err := adminmgmt.EnsureTeam(ctx, data.team, data.team /* description */, apiClient, false /* dry run */) | ||
if err != nil { | ||
return err | ||
} | ||
_, err = adminmgmt.AddUserToTeam(ctx, apiClient, teamID, userID, false /* dry run */) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
|
||
return nil | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ import ( | |
"strings" | ||
|
||
"github.com/spf13/cobra" | ||
"github.com/spf13/pflag" | ||
"google.golang.org/grpc/codes" | ||
grpc_status "google.golang.org/grpc/status" | ||
|
||
|
@@ -20,10 +21,11 @@ import ( | |
) | ||
|
||
var iamCmdFlags = struct { | ||
dryRun bool | ||
adminToken bool | ||
tokenID string | ||
betaVersion bool | ||
dryRun bool | ||
adminToken bool | ||
tokenID string | ||
betaVersion bool | ||
skipLegacyUpgrade bool | ||
}{} | ||
|
||
func newIAMCommand() *cobra.Command { | ||
|
@@ -93,17 +95,20 @@ func newIAMUpgradeToV2Cmd() *cobra.Command { | |
RunE: runIAMUpgradeToV2Cmd, | ||
Args: cobra.ExactArgs(0), | ||
} | ||
cmd.PersistentFlags().BoolVar( | ||
&iamCmdFlags.skipLegacyUpgrade, | ||
"skip-policy-migration", | ||
false, | ||
"Do not migrate policies from IAM v1.") | ||
cmd.PersistentFlags().BoolVar( | ||
&iamCmdFlags.betaVersion, | ||
"beta2.1", | ||
false, | ||
"Upgrade to version 2.1 with beta project authorization.") | ||
err := cmd.PersistentFlags().MarkHidden("beta2.1") | ||
// we could also ignore the lint error :shrug: | ||
if err != nil { | ||
fmt.Printf("failed configuring cobra: %s\n", err.Error()) | ||
panic(err.Error()) | ||
} | ||
|
||
// all flags are hidden right now | ||
cmd.PersistentFlags().VisitAll(func(f *pflag.Flag) { f.Hidden = !isDevMode() }) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought the team consensus was that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i believe that consensus convo happened last friday during subtasking and i wasnt there. if we do make it public we should have a corresponding docs update, so id like to do that in a separate pr if possible. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm all in favour of not adding anything here π |
||
|
||
return cmd | ||
} | ||
|
||
|
@@ -153,18 +158,27 @@ const alreadyMigratedMessage = `You have already upgraded to IAM %s. | |
Then re-run this command.` | ||
|
||
func runIAMUpgradeToV2Cmd(cmd *cobra.Command, args []string) error { | ||
label := map[bool]string{ | ||
true: "v2.1", | ||
false: "v2", | ||
} | ||
|
||
upgradeReq := &policies_req.UpgradeToV2Req{ | ||
Flag: policies_common.Flag_VERSION_2_0, | ||
Flag: policies_common.Flag_VERSION_2_0, | ||
SkipV1Policies: iamCmdFlags.skipLegacyUpgrade, | ||
} | ||
isBetaVersion := iamCmdFlags.betaVersion | ||
|
||
isBetaVersion := iamCmdFlags.betaVersion | ||
if isBetaVersion { | ||
upgradeReq.Flag = policies_common.Flag_VERSION_2_1 | ||
writer.Title("Enabling IAM v2.1") | ||
} else { | ||
writer.Title("Upgrading to IAM v2") | ||
} | ||
writer.Println("Migrating v1 policies...") | ||
|
||
if !iamCmdFlags.skipLegacyUpgrade { | ||
writer.Println("Migrating v1 policies...") | ||
} | ||
|
||
ctx := context.Background() | ||
apiClient, err := apiclient.OpenConnection(ctx) | ||
|
@@ -188,11 +202,7 @@ func runIAMUpgradeToV2Cmd(cmd *cobra.Command, args []string) error { | |
return status.Wrap(err, status.IAMUpgradeV2DatabaseError, | ||
"Migration to IAM v2 already in progress") | ||
case codes.AlreadyExists: | ||
if isBetaVersion { | ||
writer.Failf(alreadyMigratedMessage, "v2.1") | ||
} else { | ||
writer.Failf(alreadyMigratedMessage, "v2") | ||
} | ||
writer.Failf(alreadyMigratedMessage, label[isBetaVersion]) | ||
return nil | ||
default: // something else: fail | ||
return status.Wrap(err, status.IAMUpgradeV2DatabaseError, | ||
|
@@ -222,10 +232,6 @@ func runIAMUpgradeToV2Cmd(cmd *cobra.Command, args []string) error { | |
"Failed to migrate teams service") | ||
} | ||
|
||
label := map[bool]string{ | ||
true: "v2.1", | ||
false: "v2", | ||
} | ||
writer.Successf("Enabled IAM %s", label[isBetaVersion]) | ||
return nil | ||
} | ||
|
@@ -234,7 +240,7 @@ func outputReport(report string) { | |
// if it's got ":" in it, split on the first | ||
parts := strings.SplitN(report, ":", 2) | ||
writer.Body(parts[0]) | ||
if parts[1] != "" { | ||
if len(parts) >= 2 { | ||
writer.Body(strings.TrimSpace(parts[1])) | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider "%d v1 policies found -- skipping"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The output, in the end, will be
(see PR message) -- I'd rather not use skipped twice there
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@srenatus do you mind if we have a single line with
Skipped: %d v1 policies
, then a newline before the teams output?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right now, that's shared between a migration and no migration (see https://github.com/chef/a2/pull/4120#issuecomment-433389839), so it's a little more work than just the formatting. But yeah, we can do that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh i see.... nah, just leave it as is for now.