fix(scm/gitlab): start without credentials instead of panicking - #6644
Open
markphelps wants to merge 3 commits into
Open
markphelps wants to merge 3 commits into
markphelps wants to merge 3 commits into
Conversation
…e missing Signed-off-by: Mark Phelps <209477+markphelps@users.noreply.github.com>
Signed-off-by: Mark Phelps <209477+markphelps@users.noreply.github.com>
Signed-off-by: Mark Phelps <209477+markphelps@users.noreply.github.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## v2 #6644 +/- ##
==========================================
- Coverage 69.44% 61.93% -7.52%
==========================================
Files 147 147
Lines 13669 13677 +8
==========================================
- Hits 9493 8471 -1022
- Misses 4176 5206 +1030
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
With
scm.type: gitlaband noscm.credentials, Flipt crashes at startup with a nil pointer dereference ingitlab.NewSCM. The GitLab client is only created when credentials are set, and the code then uses it either way. GitHub, Bitbucket and Gitea all start without credentials and return the SCM's API error if a proposal is attempted. GitLab should behave the same way.While fixing this, I also found that the "unsupported credential type" error in the Bitbucket, Gitea and GitLab SCMs printed the Go type name (
config.CredentialType) instead of the actual value, and the CUE and JSON config schemas markedscm.credentialsas required even though the Go config treats it as optional.What
NewSCMnow creates an unauthenticated client and still honoursapi_url, matching Bitbucket and Gitea.PRIVATE-TOKENheader, even when the token is empty. A small HTTP transport removes the empty header, so requests without credentials carry no auth header.unsupported credential type: "ssh".scm.credentialsis now optional inflipt.schema.cueandflipt.schema.json, matching the Go config.Testing
TestNewSCM_NoApiAuth:NewSCMwith no credentials returns a usable SCM. It panicked before.TestNewSCM_NoApiAuth_Propose: against a test server returning 401,Proposereturns GitLab's 401 error. The request reaches the configuredapi_urland carries noPRIVATE-TOKENorAuthorizationheader.TestNewSCM_UnsupportedCredentialTypein each of the three packages, using a real SSH credential.Test_SchemaSCMCredentialsOptional: both schemas accept an SCM block with and without credentials.api_urlstarts, serves flags and logs no panic. The same config onv2crashes atgitlab.go:108.mise run lintandmise run go:modernizeare clean,go mod tidymakes no changes, andgo test -racepasses forinternal/coss/storage/...andinternal/storage/environments/....