Skip to content

Commit

Permalink
remove credentials-metadata from input (#242)
Browse files Browse the repository at this point in the history
* remove credentials-metadata from CLI input

* remove credentials-metadata from CLI input
  • Loading branch information
jakecoffman authored Jan 19, 2024
1 parent 45e4ef2 commit b2776ec
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 20 deletions.
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

0 comments on commit b2776ec

Please sign in to comment.