-
Notifications
You must be signed in to change notification settings - Fork 293
feat: add support for separate GitHub app credentials #649
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
Merged
jannfis
merged 5 commits into
argoproj-labs:master
from
dlactin:separate-github-app-credentials
Dec 7, 2023
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
ad6d8a1
feat: add support for separate GitHub app credentials stored as Kuber…
dlactin 4b6edba
test: added tests for consuming GitHub app credentials from a secret
dlactin 6ea67ef
fix: added GitHub App placeholder words to expect.txt
dlactin 674a9fe
fix: checking for errors when converting GitHub App and Installation IDs
dlactin 7691eee
fix: added more descriptive error messages for string-to-number conve…
dlactin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -3,6 +3,7 @@ package argocd | |||||||
import ( | ||||||||
"context" | ||||||||
"fmt" | ||||||||
"strconv" | ||||||||
"strings" | ||||||||
|
||||||||
"github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1" | ||||||||
|
@@ -66,14 +67,31 @@ func getCredsFromSecret(wbc *WriteBackConfig, credentialsSecret string, kubeClie | |||||||
} | ||||||||
return git.NewSSHCreds(string(sshPrivateKey), "", true), nil | ||||||||
} else if git.IsHTTPSURL(wbc.GitRepo) { | ||||||||
var username, password []byte | ||||||||
if username, ok = credentials["username"]; !ok { | ||||||||
return nil, fmt.Errorf("invalid secret %s: does not contain field username", credentialsSecret) | ||||||||
var username, password, githubAppID, githubAppInstallationID, githubAppPrivateKey []byte | ||||||||
if githubAppID, ok = credentials["githubAppID"]; ok { | ||||||||
if githubAppInstallationID, ok = credentials["githubAppInstallationID"]; !ok { | ||||||||
return nil, fmt.Errorf("invalid secret %s: does not contain field githubAppInstallationID", credentialsSecret) | ||||||||
} | ||||||||
if githubAppPrivateKey, ok = credentials["githubAppPrivateKey"]; !ok { | ||||||||
return nil, fmt.Errorf("invalid secret %s: does not contain field githubAppPrivateKey", credentialsSecret) | ||||||||
} | ||||||||
// converting byte array to string and ultimately int64 for NewGitHubAppCreds | ||||||||
intGithubAppID, err := strconv.ParseInt(string(githubAppID), 10, 64) | ||||||||
if err != nil { | ||||||||
return nil, err | ||||||||
} | ||||||||
intGithubAppInstallationID, _ := strconv.ParseInt(string(githubAppInstallationID), 10, 64) | ||||||||
if err != nil { | ||||||||
return nil, err | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
just a tiny improvement to help with troubleshooting |
||||||||
} | ||||||||
return git.NewGitHubAppCreds(intGithubAppID, intGithubAppInstallationID, string(githubAppPrivateKey), "", "", "", "", true), nil | ||||||||
} else if username, ok = credentials["username"]; ok { | ||||||||
if password, ok = credentials["password"]; !ok { | ||||||||
return nil, fmt.Errorf("invalid secret %s: does not contain field password", credentialsSecret) | ||||||||
} | ||||||||
return git.NewHTTPSCreds(string(username), string(password), "", "", true, ""), nil | ||||||||
} | ||||||||
if password, ok = credentials["password"]; !ok { | ||||||||
return nil, fmt.Errorf("invalid secret %s: does not contain field password", credentialsSecret) | ||||||||
} | ||||||||
return git.NewHTTPSCreds(string(username), string(password), "", "", true, ""), nil | ||||||||
return nil, fmt.Errorf("invalid repository credentials in secret %s: does not contain githubAppID or username", credentialsSecret) | ||||||||
} | ||||||||
return nil, fmt.Errorf("unknown repository type") | ||||||||
} |
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
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.
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.
just a tiny improvement to help with troubleshooting
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.
Wasn't sure if I could just commit the suggestions, so I added a new commit for these changes. Thank you!