Skip to content
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

[VC-24828] Fixed initialization of the config object #106

Merged
merged 1 commit into from
Jul 11, 2023

Conversation

wzurek
Copy link
Contributor

@wzurek wzurek commented Jul 5, 2023

Fixed initialization of the config object, it was causing nil pointer dereference on the first run:

Opening browser to: https://auth.jetstack.io/authorize?access_type=offline&audience=https%3A%2F%2Fpreflight.jetstack.io%2Fapi%2Fv1&client_id=jmQwDGl86WAevq6K6zZo6hJ4WUvp14yD&redirect_uri=http%3A%2F%2Flocalhost%3A9999%2Foauth%2Fcallback&response_type=code&scope=openid+profile+offline_access&state=2402307c-15ab-425b-a2fb-712b5037edf9
You will be taken to your browser for authentication
Login succeeded

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x2 addr=0x8 pc=0x100981ac0]

goroutine 1 [running]:
github.com/jetstack/jsctl/internal/command/auth.Login.func1({0x1017b7ca0, 0x14000189980}, {0x1017a0160?, 0x14000184f40?, 0x101654ba0?})
	github.com/jetstack/jsctl/internal/command/auth/login.go:68 +0x430
github.com/jetstack/jsctl/internal/command.run.func1(0x1400003cf00?, {0x102296278, 0x0, 0x0})
	github.com/jetstack/jsctl/internal/command/run.go:69 +0x358
github.com/spf13/cobra.(*Command).execute(0x1400003cf00, {0x102296278, 0x0, 0x0})
	github.com/spf13/[email protected]/command.go:920 +0x5b0
github.com/spf13/cobra.(*Command).ExecuteC(0x1400003c900)
	github.com/spf13/[email protected]/command.go:1044 +0x35c
github.com/spf13/cobra.(*Command).Execute(...)
	github.com/spf13/[email protected]/command.go:968
github.com/spf13/cobra.(*Command).ExecuteContext(...)
	github.com/spf13/[email protected]/command.go:961
main.main()
	github.com/jetstack/jsctl/main.go:26 +0x1dc

The situation only occurred if the user is part of only one organization and run jsctl for the first time.

Testing procedure (tested manually only):

  • ensure my user is part of single org
  • delete ~/.jsctl/config.json
  • launch jsctl auth
  • observe the crash described above
  • apply workaround (create config.json with following content: {"organization":""})
  • observe correct behavior
  • delete ~/.jsctl/config.json
  • apply the path
  • launch jsctl auth
  • observe correct behavior


// if the user already has an organization selected, we don't need to do anything
cnf, ok := config.FromContext(ctx)
if ok && cnf.Organization != "" {
return nil
}
// initiate empty config
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// initiate empty config
// initiate empty config for missing config

Copy link
Contributor

@tfadeyi tfadeyi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LTGM

@wzurek wzurek merged commit f9b6349 into main Jul 11, 2023
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants