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

Validate user ref when creating user repository #250

Merged
merged 1 commit into from
Oct 12, 2023

Conversation

somtochiama
Copy link
Member

@somtochiama somtochiama commented Oct 11, 2023

Description

This pull request adds a function to the UserRepositories interface called GetUserLogin. It gets the current
authenticated user associated with the token. This function is used when creating user repositories to validate
that UserLogin. This is required because the Create API doesn't require you to pass a user and giving the wrong UserLogin
successfully creates a repository.

When running flux bootstrap with the wrong user (and the repository already exists) returns this confusing error because
ggp tries to create the repository under the authenticated user.

flux bootstrap github --owner=soule --token-auth --repository=fleet-infra --personal
► connecting to github.com
✗ failed to create new Git repository "https://github.com/soule/fleet-infra": multiple errors occurred:
- POST https://api.github.com/user/repos: 422 Repository creation failed. [{Resource:Repository Field:name Code:custom Message:name already exists on this account}]
- resource already exists, cannot create object. Use Reconcile() to create it idempotently

With these changes, we give a better error

./bin/flux bootstrap github --owner=soule --token-auth --repository=fleet-infraxx --personal
► connecting to github.com
✗ failed to create new Git repository "https://github.com/soule/fleet-infraxx": incorrect owner 'soule' passed in

Test results

@somtochiama somtochiama marked this pull request as ready for review October 11, 2023 12:26
gitea/client_repositories_user.go Outdated Show resolved Hide resolved
github/client_repositories_user.go Outdated Show resolved Hide resolved
gitlab/client_repositories_user.go Outdated Show resolved Hide resolved
github/integration_test.go Outdated Show resolved Hide resolved
gitlab/integration_test.go Show resolved Hide resolved
Copy link
Member

@souleb souleb left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks @somtochiama

Signed-off-by: Somtochi Onyekwere <somtochionyekwere@gmail.com>
Copy link
Member

@stefanprodan stefanprodan left a comment

Choose a reason for hiding this comment

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

LGTM

Great UX improvement for Flux bootstrap! Thanks @somtochiama 🥇

@souleb souleb merged commit 9789fae into fluxcd:main Oct 12, 2023
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants