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
Pass user token to API via an HTTP header #1112
Conversation
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.
Looks good. The only thing holding me up is the unsetting of an env variable.
cmd/gitops/add/clusters/cmd_test.go
Outdated
@@ -141,3 +143,77 @@ func TestEndpointNotSet(t *testing.T) { | |||
err := cmd.Execute() | |||
assert.EqualError(t, err, "the Weave GitOps Enterprise HTTP API endpoint flag (--endpoint) has not been set") | |||
} | |||
|
|||
func TestGitProviderToken(t *testing.T) { | |||
os.Setenv("GITHUB_TOKEN", "test-token") |
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.
Do we need to "reset" this back to the old value? Might cause some weird bugs in a user's environment otherwise.
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.
So I've tested this with my own GITHUB_TOKEN and it seemed unaffected after running these tests. Also in the next line I'm resetting that env var.
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.
So long as os.Unsetenv()
reset it to the previous value, or at least doesn't change the user's environment 👍
@@ -24,6 +26,9 @@ func TestEndpointNotSet(t *testing.T) { | |||
} | |||
|
|||
func TestPayload(t *testing.T) { | |||
os.Setenv("GITHUB_TOKEN", "test-token") |
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.
Same as above with saving the previous value.
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.
LGTM with the caveat that the user's environment doesn't get changed.
cmd/gitops/add/clusters/cmd_test.go
Outdated
@@ -141,3 +143,77 @@ func TestEndpointNotSet(t *testing.T) { | |||
err := cmd.Execute() | |||
assert.EqualError(t, err, "the Weave GitOps Enterprise HTTP API endpoint flag (--endpoint) has not been set") | |||
} | |||
|
|||
func TestGitProviderToken(t *testing.T) { | |||
os.Setenv("GITHUB_TOKEN", "test-token") |
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.
So long as os.Unsetenv()
reset it to the previous value, or at least doesn't change the user's environment 👍
Thanks @jpellizzari for the review. While I haven't had any issues locally, I'll change this to make it more robust. Bonus test helper for when we switch to Go 1.17 🎉 |
6ce8439
to
c8bb5a5
Compare
Closes: weaveworks/weave-gitops-enterprise#203
What changed?
Why?
This is so that the Weave GitOps Enterprise API can make calls to the git provider on behalf of the end user.
How did you test it?
Tested locally + unit tests
Release notes
N/A
Documentation Changes
N/A