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

Migrate configuration #13

Merged
merged 5 commits into from
Aug 14, 2024
Merged

Migrate configuration #13

merged 5 commits into from
Aug 14, 2024

Conversation

shackra
Copy link
Contributor

@shackra shackra commented Aug 13, 2024

Pull Request

To help us get this pull request reviewed and merged quickly, please be sure to include the following items:

  • Tests (if applicable)
  • Documentation (if applicable)
  • Changelog entry
  • A full explanation here in the PR description of the work done

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Tests
  • Other

Backward Compatibility

Is this change backward compatible with the most recently released version? Does it introduce changes which might change the user experience in any way? Does it alter the Connector in any way?

  • Yes (backward compatible)
  • No (breaking changes)

Useful links:

  • [https://github.com/ConductorOne/baton-sdk/wiki/Coding-Guidelines](Baton SDK coding guidelines)
  • [https://github.com/ConductorOne/baton/blob/main/CONTRIBUTING.md](New contributor guide)

Issue Linking

What's new?

cmd/baton-jenkins/config.go Outdated Show resolved Hide resolved
Copy link

@mgaeta mgaeta left a comment

Choose a reason for hiding this comment

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

https://www.jenkins.io/doc/book/system-administration/authenticating-scripted-clients/
I think the password and token are basically interchangeable

func WithSetBasicAuthHeader(username, password string) uhttp.RequestOption {
	return uhttp.WithHeader("Authorization", "Basic "+basicAuth(username, password))
}

func WithSetTokenAuthHeader(username, token string) uhttp.RequestOption {
	return uhttp.WithHeader("Authorization", "Basic "+basicAuth(username, token))
}

Also, make sure to update the help text in the README

l := ctxzap.Extract(ctx)
jenkinsClient := client.NewClient()
if cfg.JenkinsToken != "" {
jenkinsClient.WithUser(cfg.JenkinsUsername).WithBearerToken(cfg.JenkinsToken)
if v.GetString("token") != "" {
Copy link

Choose a reason for hiding this comment

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

l := ctxzap.Extract(ctx)
err := field.Validate(Configuration, v)
if err != nil {
  return nil, err
}
jenkinsClient := client.NewClient().
  WithUser(v.GetString("username")).
  WithPassword(v.GetString("password")).
  WithToken(v.GetString("token"))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I mean, is that even possible without causing API errors? 😆

@shackra
Copy link
Contributor Author

shackra commented Aug 13, 2024

https://www.jenkins.io/doc/book/system-administration/authenticating-scripted-clients/ I think the password and token are basically interchangeable

func WithSetBasicAuthHeader(username, password string) uhttp.RequestOption {
	return uhttp.WithHeader("Authorization", "Basic "+basicAuth(username, password))
}

func WithSetTokenAuthHeader(username, token string) uhttp.RequestOption {
	return uhttp.WithHeader("Authorization", "Basic "+basicAuth(username, token))
}

Also, make sure to update the help text in the README

the client API for Jenkins has some expectations, so we cannot re-use variables to set that piece of auth information:

jenkinsClient.WithUser("random-username").WithBearerToken("magic-token")

jenkinsClient.WithUser("random-username").WithPassword("secretpassword")

@shackra shackra requested a review from mgaeta August 14, 2024 21:19
@shackra shackra merged commit 8f05ded into main Aug 14, 2024
3 checks passed
@shackra shackra deleted the shackra/migrate-config branch August 14, 2024 22:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants