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

remove credentials-metadata from input #242

Merged
merged 2 commits into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 9 additions & 13 deletions cmd/dependabot/internal/cmd/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -362,21 +362,17 @@ func processInput(input *model.Input, flags *UpdateFlags) {
}
}

// As a convenience, fill credentials-metadata if credentials are provided
// which is what happens in production. This way the user doesn't have to
// specify credentials-metadata in the scenario file unless they want to.
if len(input.Job.CredentialsMetadata) == 0 {
log.Println("Adding missing credentials-metadata into job definition")
for _, credential := range input.Credentials {
entry := make(map[string]any)
for k, v := range credential {
// Updater does not get credentials.
if k != "token" && k != "password" && k != "key" && k != "auth-key" {
entry[k] = v
}
// Calculate the credentials-metadata as it cannot be provided by the user anymore.
input.Job.CredentialsMetadata = []model.Credential{}
for _, credential := range input.Credentials {
entry := make(map[string]any)
for k, v := range credential {
// Updater does not get credentials.
if k != "username" && k != "token" && k != "password" && k != "key" && k != "auth-key" {
entry[k] = v
}
input.Job.CredentialsMetadata = append(input.Job.CredentialsMetadata, entry)
}
input.Job.CredentialsMetadata = append(input.Job.CredentialsMetadata, entry)
}
}

Expand Down
4 changes: 1 addition & 3 deletions cmd/dependabot/internal/cmd/update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ func Test_processInput(t *testing.T) {
t.Run("adds git_source to credentials when local token is present", func(t *testing.T) {
var input model.Input
os.Setenv("LOCAL_GITHUB_ACCESS_TOKEN", "token")
// Adding a dummy metadata to test the inner if
input.Job.CredentialsMetadata = []model.Credential{{}}

processInput(&input, nil)

Expand All @@ -51,7 +49,7 @@ func Test_processInput(t *testing.T) {
}) {
t.Error("expected credentials to be added")
}
if !reflect.DeepEqual(input.Job.CredentialsMetadata[1], model.Credential{
if !reflect.DeepEqual(input.Job.CredentialsMetadata[0], model.Credential{
"type": "git_source",
"host": "github.com",
}) {
Expand Down
2 changes: 1 addition & 1 deletion internal/model/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ type Job struct {
RejectExternalCode bool `json:"reject-external-code" yaml:"reject-external-code,omitempty"`
RepoPrivate bool `json:"repo-private" yaml:"repo-private,omitempty"`
CommitMessageOptions *CommitOptions `json:"commit-message-options" yaml:"commit-message-options,omitempty"`
CredentialsMetadata []Credential `json:"credentials-metadata" yaml:"credentials-metadata,omitempty"`
CredentialsMetadata []Credential `json:"credentials-metadata" yaml:"-"`
MaxUpdaterRunTime int `json:"max-updater-run-time" yaml:"max-updater-run-time,omitempty"`
}

Expand Down
3 changes: 0 additions & 3 deletions internal/model/job_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,9 +338,6 @@ job:
- name: npm
rules:
patterns: ["npm", "@npmcli*"]
credentials-metadata:
- type: git_source
host: github.com
security-advisories:
- dependency-name: got
patched-versions: []
Expand Down