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

bootstrapping does not ask for ssh password key if empty is introduced by the user #3738

Merged
merged 3 commits into from
Dec 19, 2023

Conversation

enekofb
Copy link
Contributor

@enekofb enekofb commented Dec 19, 2023

Closes #3737

What changed?

  • Supports use case for flags with default valid value empty string via using flags.changed cobra func

Why was this change made?

  • Cause we were not able during configuration whether the empty string was default or coming from user.

How was this change implemented?

intially tested that the expected behaviour

func TestBootstrapCmdConfig(t *testing.T) {

	tests := []struct {
		name        string
		flags       []string
		wantErr     assert.ErrorAssertionFunc
		wantChanged bool
	}{
		{
			name: "should detect user introduced value for private-key-password",
			flags: []string{
				"--private-key-password=\"\"",
			},
			wantErr:     assert.NoError,
			wantChanged: true,
		},
		{
			name:        "should detect user introduced value for private-key-password",
			flags:       []string{},
			wantErr:     assert.NoError,
			wantChanged: false,
		},
	}
	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			var options = &config.Options{}
			cmd := Command(options)

			err := cmd.ParseFlags(tt.flags)

			if tt.wantErr != nil {
				tt.wantErr(t, err, "unexpected error ")
				return
			}
			assert.Equal(t, tt.wantChanged, cmd.Flags().Changed("private-key-password"), "invalid value for private-key-password")
		})
	}
}

How did you validate the change?

  • Explain how a reviewer can verify the change themselves

run the command and will see that no longer is asking when introduced empty

➜  weave-gitops-enterprise git:(wge-3737-support-empty-ssh-password-key) ✗ go run cmd/gitops/main.go bootstrap --bootstrap-flux --components-extra=none --private-key=/Users/enekofb/.ssh/weaveworks/dev  --private-key-password="" --version="0.37.0" --git-username="$GITHUB_USER" --git-password="$GITHUB_TOKEN" \\n     --repo-url=https://github.com/enekofb/cli-dev.git --branch="main"  --repo-path=clusters/management
► creating client to cluster
✔ created client to cluster: https://127.0.0.1:62313
► verifying flux installation
✔ flux is installed
► verifying flux reconciliation
✔ flux is bootstrapped
✔ detected git scheme: ssh
► Weave GitOps Enterprise is already installed in namespace flux-system
◎ bootstrap flux
◎ flux repository configuration
◎ git credentials
◎ checking entitlement

asking when no introduced

➜  weave-gitops-enterprise git:(wge-3737-support-empty-ssh-password-key) ✗ go run cmd/gitops/main.go bootstrap --bootstrap-flux --components-extra=none --private-key=/Users/enekofb/.ssh/weaveworks/dev  --version="0.37.0" --git-username="$GITHUB_USER" --git-password="$GITHUB_TOKEN" \\n     --repo-url=https://github.com/enekofb/cli-dev.git --branch="main"  --repo-path=clusters/management
► creating client to cluster
✔ created client to cluster: https://127.0.0.1:62313
► verifying flux installation
✔ flux is installed
► verifying flux reconciliation
✔ flux is bootstrapped
✔ detected git scheme: ssh
► Weave GitOps Enterprise is already installed in namespace flux-system
◎ bootstrap flux
◎ flux repository configuration
◎ git credentials
✔ private key password: █

  • Integration tests -- what is covered, what cannot be covered;
    or, explain why there are no new tests
  • Unit tests -- what is covered, what cannot be covered; are
    there tests that fail without the change?

Release notes

Documentation Changes

Updated internal style guide

Other follow ups

No

@enekofb enekofb added the bug Something isn't working label Dec 19, 2023
@enekofb enekofb force-pushed the wge-3737-support-empty-ssh-password-key branch from 4dcedc1 to ba63d54 Compare December 19, 2023 08:39
@enekofb enekofb marked this pull request as ready for review December 19, 2023 08:40
@enekofb enekofb force-pushed the wge-3737-support-empty-ssh-password-key branch from ba63d54 to d0e07f5 Compare December 19, 2023 08:55
@enekofb enekofb changed the title Wge 3737 support empty ssh password key bootstrapping does not ask for ssh password key if empty is introduced by the user Dec 19, 2023
Copy link
Member

@Samra10 Samra10 left a comment

Choose a reason for hiding this comment

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

LGTM.
Tested and working as expected ✅

@enekofb enekofb force-pushed the wge-3737-support-empty-ssh-password-key branch from d0e07f5 to 9f782e7 Compare December 19, 2023 09:33
@enekofb enekofb merged commit bfe1cc1 into main Dec 19, 2023
10 checks passed
@enekofb enekofb deleted the wge-3737-support-empty-ssh-password-key branch December 19, 2023 09:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cannot bootstrap non-interactive with ssh and empty password key
2 participants