Skip to content

Commit

Permalink
Smart logic for service account persistence (#433)
Browse files Browse the repository at this point in the history
We should only persist these on explicit login commands (init should persist the root users creds and use auto-assume from there).
  • Loading branch information
michaeljguarino committed Aug 21, 2023
1 parent 8a614ee commit 85cbbd7
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions cmd/plural/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,13 @@ func handleLogin(c *cli.Context) error {
conf.Token = ""
conf.Endpoint = c.String("endpoint")
client := api.FromConfig(conf)
persist := c.Command.Name == "login"

if config.Exists() {
conf := config.Read()
if affirm(fmt.Sprintf("It looks like your current Plural user is %s, use this profile?", conf.Email), "PLURAL_LOGIN_AFFIRM_CURRENT_USER") {
client = api.FromConfig(&conf)
return postLogin(&conf, client, c)
return postLogin(&conf, client, c, persist)
}
}

Expand Down Expand Up @@ -152,7 +153,7 @@ func handleLogin(c *cli.Context) error {
conf.Token = jwt
conf.ReportErrors = affirm("Would you be willing to report any errors to Plural to help with debugging?", "PLURAL_LOGIN_AFFIRM_REPORT_ERRORS")
client = api.FromConfig(conf)
return postLogin(conf, client, c)
return postLogin(conf, client, c, persist)
}

func handleClone(c *cli.Context) error {
Expand Down Expand Up @@ -182,7 +183,7 @@ func downloadReadme(c *cli.Context) error {
return wkspace.DownloadReadme()
}

func postLogin(conf *config.Config, client api.Client, c *cli.Context) error {
func postLogin(conf *config.Config, client api.Client, c *cli.Context, persist bool) error {
me, err := client.Me()
if err != nil {
return api.GetErrorResponse(err, "Me")
Expand All @@ -203,6 +204,9 @@ func postLogin(conf *config.Config, client api.Client, c *cli.Context) error {
fmt.Printf("Assumed service account %s\n", saEmail)
config.SetConfig(conf)
client = api.FromConfig(conf)
if !persist {
return nil
}
}

accessToken, err := client.GrabAccessToken()
Expand Down

0 comments on commit 85cbbd7

Please sign in to comment.