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

Support for authenticated tf module download #658

Merged
merged 6 commits into from
Apr 15, 2021

Conversation

jlk
Copy link
Contributor

@jlk jlk commented Apr 13, 2021

Adding support to use credentials in ~/.terraformrc when downloading tf modules from a private registry. This fixes #631

@codecov
Copy link

codecov bot commented Apr 13, 2021

Codecov Report

Merging #658 (7889212) into master (1257ec2) will decrease coverage by 0.15%.
The diff coverage is 62.85%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #658      +/-   ##
==========================================
- Coverage   75.13%   74.97%   -0.16%     
==========================================
  Files         110      110              
  Lines        3028     3061      +33     
==========================================
+ Hits         2275     2295      +20     
- Misses        582      592      +10     
- Partials      171      174       +3     
Impacted Files Coverage Δ
pkg/downloader/module-download.go 82.75% <62.85%> (-8.81%) ⬇️

return registry.NewClient(nil, nil)
}
// TODO: Need to add support for Windows %APPDIR%/terraform.rc
terraformrc := filepath.Join(homedir, "/.terraformrc")
Copy link
Contributor

Choose a reason for hiding this comment

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

Though the end result would be same, adding the path separator is not required before .terraformrc

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thx - I was originally using sprintf and forgot to change...


hostCredentialMap := convertCredentialMapToHostMap(result.Credentials)
if hostCredentialMap == nil {
return nil, err
Copy link
Contributor

Choose a reason for hiding this comment

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

err would be nil here, we would need to create an error to return.

@@ -542,3 +542,68 @@ func TestGetVersionToDownload(t *testing.T) {
})
}
}

func TestAuthenticatedRegistryClient(t *testing.T) {
testDirPath := "testdata/run-test"
Copy link
Contributor

Choose a reason for hiding this comment

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

We should use filepath.Join() here.

name: "invalid terraformrc file",
filename: "badterraformrc",
},
}
Copy link
Contributor

Choose a reason for hiding this comment

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

May be we can add a test with non existing file and a test with a file that doesn't have valid data?
Also, there should be a test that verifies the behavior for nil input to convertCredentialMapToHostMap.
It will increase the code coverage

@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 1 Code Smell

No Coverage information No Coverage information
0.0% 0.0% Duplication

@jlk jlk merged commit 23ca9f7 into tenable:master Apr 15, 2021
@jlk jlk deleted the add-auth-module-dl branch April 15, 2021 18:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for private terraform repos
2 participants