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

OpenTofu support and JSON recentFile support #435

Merged
merged 105 commits into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from 96 commits
Commits
Show all changes
105 commits
Select commit Hold shift + click to select a range
c14a06e
Check version sources based on whether verison has been set
MatthewJohn May 9, 2024
7df2b96
Remove check if TOML file exists before calling getParamsTOML, as get…
MatthewJohn May 9, 2024
90433e0
Remove unused checkXExists methods in toml, terragrunt, terraform_ver…
MatthewJohn May 9, 2024
b1467d4
Add check for ensuring that gohcl.DecodeBody does not return diagnost…
MatthewJohn May 9, 2024
104d48d
Ignore diagnostics from gohcl.DecodeBody to retain original behavoir
MatthewJohn May 9, 2024
b1db9e2
Update version param_parsing tests to check err return values
MatthewJohn May 9, 2024
627ef90
Check version value after error from TOML file reading
MatthewJohn May 9, 2024
9b95ed7
Add tests to ensure terragrunt, TOML and terraform version handle sit…
MatthewJohn May 9, 2024
3a0973d
Revert "Remove unused checkXExists methods in toml, terragrunt, terra…
MatthewJohn May 9, 2024
9fe6973
Re-introduce checking if configuration types exist before obtaining p…
MatthewJohn May 9, 2024
c3224c9
Remove unused parameter 'params' in 'tomlFileExists'
MatthewJohn May 26, 2024
ea41eca
Ensure environment variable has been set to a non-empty string before…
MatthewJohn May 26, 2024
8c22bca
Unset environment variable for TF_VERSION in tests after setting to a…
MatthewJohn May 26, 2024
25d1953
Update expected value in precedence to new expected value.
MatthewJohn May 26, 2024
58f3a49
Update precendence test to create each configuration incrementally en…
MatthewJohn May 26, 2024
6d1efac
Improve precedence tests
MatthewJohn May 26, 2024
49fd706
Add test to ensure that --default flag is handled correctly
MatthewJohn May 26, 2024
801c4bd
Revert "Add test to ensure that --default flag is handled correctly"
MatthewJohn May 26, 2024
f041edd
Merge branch 'master' into 420-how-to-deal-with-toml-file
MatthewJohn May 26, 2024
b5f6863
chore: Split parsing of release HTML into seperate function to allow …
MatthewJohn May 26, 2024
e0b88e5
chore: Update getTFURLBody to return the body string, without splitti…
MatthewJohn May 26, 2024
a7c20f8
test: Improve error message on slice size matching in version list test
MatthewJohn May 26, 2024
fdda102
test: Add test to check rendering of OpenTofu release page
MatthewJohn May 26, 2024
d25e941
feat: Add compatibility in releases page parsing to support OpenTofu
MatthewJohn May 26, 2024
28d014e
test: Add tests for getTFURLBody, getTFLatest and getTFLatestImplicit
MatthewJohn May 26, 2024
48f9298
feat: Add support for passing of product in parameters and updating d…
MatthewJohn May 26, 2024
52d00c4
Update Install methods to support new "product" entity, to define req…
MatthewJohn May 26, 2024
4388e4c
Fix download URL for opentofu
MatthewJohn May 26, 2024
d84be06
Fix signature file used from OpenTofu to verify SHA file
MatthewJohn May 26, 2024
1aa25aa
Fix file to be extracted from zip file
MatthewJohn May 26, 2024
5fcea5d
Convert recent file to JSON
MatthewJohn May 26, 2024
689c396
chore: Use formatters in promptui and custom type to allow labelling …
MatthewJohn May 26, 2024
0ef7b9b
test: Move precedence check to skip-integration-tests as the director…
MatthewJohn May 26, 2024
8437e8f
Improve log messages when unable to read from third party configurati…
MatthewJohn May 27, 2024
8e5e83f
Update permissions of test files created by tests to use more restric…
MatthewJohn May 27, 2024
0daf90a
Update Unzip to retain previous signature to avoid breaking external …
MatthewJohn May 27, 2024
619b02d
Improve comments for deprecated functions that are being replaced by …
MatthewJohn May 27, 2024
039e9f1
Combine RECENT files into a single file with keys for each product
MatthewJohn May 27, 2024
3110e33
Move recentFile-related code into new recent file
MatthewJohn May 27, 2024
0c44e1a
Add handling migration of Recent file data from previous format
MatthewJohn May 27, 2024
1ca10b6
Move responsibility for handling RecentData to products
MatthewJohn May 27, 2024
d881bb9
Update errors during write of recent file to be errors
MatthewJohn May 27, 2024
3055263
Replace use of deprecated io package with os
MatthewJohn May 27, 2024
41885ef
Improve debug when obtaining list of versions to avoid using Terrafor…
MatthewJohn May 27, 2024
700f107
Provide default product in help for product command line argument
MatthewJohn May 27, 2024
724af91
Use non-formatting logging function where formatting is not used
MatthewJohn May 27, 2024
6d69db5
Improve error when invalid product is specified
MatthewJohn May 27, 2024
269ff35
Simplify logic in installableBinLocation.
MatthewJohn May 27, 2024
513ff89
Reference legacy product for default executable name in Unzip and err…
MatthewJohn May 27, 2024
1674f1a
Add comment to getLegacyProduct about it's use
MatthewJohn May 27, 2024
45b0c38
Update comment for getTFList to exlcude information about Terraform
MatthewJohn May 27, 2024
b3111bc
Improve log message in installableBinLocation to use product name
MatthewJohn May 27, 2024
17c6f9b
Merge branch '315-opentofu-support' into 315-convert-recent-file-to-json
MatthewJohn May 28, 2024
1542aa0
Replace uses of Terraform with product name in prompt for getting ver…
MatthewJohn May 27, 2024
67433db
Assign product entity to Params to avoid fetching product in main
MatthewJohn May 28, 2024
147fd93
Add support for "product" config key in tfswitch TOML file to set pro…
MatthewJohn May 28, 2024
9ab0409
Rename "product" short option to -t
MatthewJohn May 28, 2024
27a0071
Add tests for recent functions
MatthewJohn May 28, 2024
3afe3fe
Update recent versions to retain previous 3 latest versions
MatthewJohn May 28, 2024
b459aad
Add test for Unzip method with parameter for fileToExtract
MatthewJohn May 28, 2024
d22a046
Add stub method for previous ChangeSymlink signature and create new r…
MatthewJohn May 28, 2024
c25d831
Add initial draft test for DownloadProductFromURL using mocked server…
MatthewJohn May 29, 2024
522466f
Further attempts to get openpgp signing to work
MatthewJohn May 29, 2024
dbc10af
test: Update TestDownloadProductFromURL to use ProtonMail gopenpgp pa…
MatthewJohn May 29, 2024
631404f
Update getChecksumFromHashFile to check split length of checksum file.
MatthewJohn May 29, 2024
d04ce60
Merge branch '420-how-to-deal-with-toml-file' into 315-opentofu-support
MatthewJohn May 29, 2024
858380b
Move creating product method before GetParamsFor* to avoid attempting…
MatthewJohn May 29, 2024
6328f74
Update tests for GetVersion* to set mirror URL, which is usually perf…
MatthewJohn May 29, 2024
6ce88b5
Simplify logic of getTFLatestImplicit to use getTFList
MatthewJohn May 29, 2024
caad61d
Revert "Simplify logic of getTFLatestImplicit to use getTFList"
MatthewJohn May 29, 2024
f31f766
Disable failing tests
MatthewJohn May 29, 2024
dc8ea09
Initialise logger in tests
MatthewJohn May 29, 2024
936961f
Ensure trailing slash is appended as necessary in MirrorURL
MatthewJohn May 29, 2024
f9c2f0e
Add deprecation notice to WriteLines and ReadLines and update depreca…
MatthewJohn May 31, 2024
ef7ab52
Add tests for products
MatthewJohn May 31, 2024
427379f
Add requested version to error when the version cannot be found in tf…
MatthewJohn May 31, 2024
98152db
Update version in test_tfswitchtoml to use a valid opentofu version
MatthewJohn May 31, 2024
7a25f5a
Update TestGetParameters_toml_params_are_overridden_by_cli to overrid…
MatthewJohn May 31, 2024
57ebfd7
Fix joining expected path to support windows
MatthewJohn May 31, 2024
f7c7032
fix: Only obtain TOML file from home directory
MatthewJohn Jun 3, 2024
161e0d5
Move TOML directory to attribute of Params, defaulting to HomeDir.
MatthewJohn Jun 3, 2024
8555500
Split GetParameters logic to just call initParams and new populatePar…
MatthewJohn Jun 3, 2024
3630353
Update integration tests to symlink tfswitch TOML in CWD to home dire…
MatthewJohn Jun 3, 2024
21400f9
Update build to copy .tfswitch.toml to home directory, rather than us…
MatthewJohn Jun 3, 2024
b2a5916
Add warning when failing to parse Terraform
MatthewJohn Jun 4, 2024
309b0ed
Improve error in warning for invalid Terraform module
MatthewJohn Jun 4, 2024
17507bf
Merge branch 'master' into 420-how-to-deal-with-toml-file
MatthewJohn Jun 5, 2024
fc5cd6b
Merge branch '420-how-to-deal-with-toml-file' into 315-opentofu-support
MatthewJohn Jun 5, 2024
6766145
Fix typo in comment
MatthewJohn Jun 5, 2024
e7fc028
Simplify CI integration test setup to use rm -f
MatthewJohn Jun 5, 2024
c3be17a
Add additional tests for DownloadProductFromURL to test some failure …
MatthewJohn Jun 5, 2024
5093a5b
Add support for setting product using environment variable
MatthewJohn Jun 5, 2024
f9d56fb
Update TestUnzip_with_file_to_unzip to support windows
MatthewJohn Jun 5, 2024
1af481d
docs: Update documentation for environment variables to explain TF_PR…
MatthewJohn Jun 5, 2024
2a3ab61
Fix EOL whitespace in tfswitch.toml
MatthewJohn Jun 5, 2024
e8e0707
Update documentation for config-files to reference new product config…
MatthewJohn Jun 5, 2024
59548d1
Stop appending *recent to recent versions in recent methods, as this …
MatthewJohn Jun 7, 2024
f558e54
Add tests for unmarshalRecentFileData function
MatthewJohn Jun 7, 2024
c9c8272
Fix bug where empty recent file causes panic due to referencing non-e…
MatthewJohn Jun 7, 2024
91ec8c6
Add test of recent file with invalid JSON data
MatthewJohn Jun 7, 2024
ecfbfc8
Fix showing versions from recent in full list of versions in interface
MatthewJohn Jun 7, 2024
927f999
Use map of pre-existing versions to improve lookup of recent versions…
MatthewJohn Jun 7, 2024
0d34959
Move checking if recent file exists to unmarshalRecentFileData, as ch…
MatthewJohn Jun 7, 2024
8ed723c
added product name to "Switch <product> info"
warrensbox Jun 7, 2024
217fc31
Merge branch 'master' into 315-opentofu-support
warrensbox Jun 7, 2024
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
6 changes: 6 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ jobs:
go build -v -o build/tfswitch
mkdir `pwd`/bin/
find ./test-data/integration-tests/* -type d -print0 | while read -r -d $'\0' TEST_PATH; do
if test -f "${TEST_PATH}/.tfswitch.toml"
then
cp "${TEST_PATH}/.tfswitch.toml" ~/
else
rm -f ~/.tfswitch.toml
fi
./build/tfswitch -c "${TEST_PATH}" -b `pwd`/bin/terraform || exit 1
done

Expand Down
5 changes: 5 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,13 @@ require (
)

require (
github.com/ProtonMail/go-crypto v0.0.0-20230717121422-5aa5874ade95 // indirect
github.com/ProtonMail/go-mime v0.0.0-20230322103455-7d82a3887f2f // indirect
github.com/ProtonMail/gopenpgp/v2 v2.7.5 // indirect
github.com/agext/levenshtein v1.2.3 // indirect
github.com/apparentlymart/go-textseg/v15 v15.0.0 // indirect
github.com/chzyer/readline v1.5.1 // indirect
github.com/cloudflare/circl v1.3.3 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/google/go-cmp v0.6.0 // indirect
Expand All @@ -31,6 +35,7 @@ require (
github.com/mitchellh/go-wordwrap v1.0.1 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/rogpeppe/go-internal v1.12.0 // indirect
github.com/sagikazarmark/locafero v0.5.0 // indirect
Expand Down
53 changes: 53 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
github.com/ProtonMail/go-crypto v0.0.0-20230717121422-5aa5874ade95 h1:KLq8BE0KwCL+mmXnjLWEAOYO+2l2AE4YMmqG1ZpZHBs=
github.com/ProtonMail/go-crypto v0.0.0-20230717121422-5aa5874ade95/go.mod h1:EjAoLdwvbIOoOQr3ihjnSoLZRtE8azugULFRteWMNc0=
github.com/ProtonMail/go-mime v0.0.0-20230322103455-7d82a3887f2f h1:tCbYj7/299ekTTXpdwKYF8eBlsYsDVoggDAuAjoK66k=
github.com/ProtonMail/go-mime v0.0.0-20230322103455-7d82a3887f2f/go.mod h1:gcr0kNtGBqin9zDW9GOHcVntrwnjrK+qdJ06mWYBybw=
github.com/ProtonMail/gopenpgp/v2 v2.7.5 h1:STOY3vgES59gNgoOt2w0nyHBjKViB/qSg7NjbQWPJkA=
github.com/ProtonMail/gopenpgp/v2 v2.7.5/go.mod h1:IhkNEDaxec6NyzSI0PlxapinnwPVIESk8/76da3Ct3g=
github.com/agext/levenshtein v1.2.3 h1:YB2fHEn0UJagG8T1rrWknE3ZQzWM06O8AMAatNn7lmo=
github.com/agext/levenshtein v1.2.3/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558=
github.com/apparentlymart/go-textseg/v15 v15.0.0 h1:uYvfpb3DyLSCGWnctWKGj857c6ew1u1fNQOlOtuGxQY=
github.com/apparentlymart/go-textseg/v15 v15.0.0/go.mod h1:K8XmNZdhEBkdlyDdvbmmsvpAG721bKi0joRfFdHIWJ4=
github.com/bwesterb/go-ristretto v1.2.3/go.mod h1:fUIoIZaG73pV5biE2Blr2xEzDoMj7NFEuV9ekS419A0=
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
github.com/chzyer/logex v1.2.1 h1:XHDu3E6q+gdHgsdTPH6ImJMIp436vR6MPtH8gP05QzM=
github.com/chzyer/logex v1.2.1/go.mod h1:JLbx6lG2kDbNRFnfkgvh4eRJRPX1QCoOIWomwysCBrQ=
Expand All @@ -11,6 +18,8 @@ github.com/chzyer/readline v1.5.1/go.mod h1:Eh+b79XXUwfKfcPLepksvw2tcLE/Ct21YObk
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
github.com/chzyer/test v1.0.0 h1:p3BQDXSxOhOG0P9z6/hGnII4LGiEPOYBhs8asl/fC04=
github.com/chzyer/test v1.0.0/go.mod h1:2JlltgoNkt4TW/z9V/IzDdFaMTM2JPIi26O1pF38GC8=
github.com/cloudflare/circl v1.3.3 h1:fE/Qz0QdIGqeWfnwq0RE0R7MI51s0M2E4Ga9kq5AEMs=
github.com/cloudflare/circl v1.3.3/go.mod h1:5XYMA4rFBvNIrhs50XuiBJ15vF2pZn4nnUKZrLbUZFA=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
Expand Down Expand Up @@ -60,6 +69,8 @@ github.com/pborman/getopt v1.1.0 h1:eJ3aFZroQqq0bWmraivjQNt6Dmm5M0h2JcDW38/Azb0=
github.com/pborman/getopt v1.1.0/go.mod h1:FxXoW1Re00sQG/+KIkuSqRL/LwQgSkv7uyac+STFsbk=
github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM=
github.com/pelletier/go-toml/v2 v2.2.2/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
Expand All @@ -83,6 +94,7 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
Expand All @@ -94,30 +106,71 @@ github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6Kllzaw
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e h1:JVG44RsyaB9T2KIHavMF/ppJZNG9ZpyihvCd0w101no=
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e/go.mod h1:RbqR21r5mrJuqunuUZ/Dhy/avygyECGrLceyNeo4LiM=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
github.com/zclconf/go-cty v1.14.4 h1:uXXczd9QDGsgu0i/QFR/hzI5NYCHLf6NQw/atrbnhq8=
github.com/zclconf/go-cty v1.14.4/go.mod h1:VvMs5i0vgZdhYawQNq5kePSpLAoz8u1xvZgrPIxfnZE=
github.com/zclconf/go-cty-debug v0.0.0-20191215020915-b22d67c1ba0b h1:FosyBZYxY34Wul7O/MSKey3txpPYyCqVO5ZyceuQJEI=
github.com/zclconf/go-cty-debug v0.0.0-20191215020915-b22d67c1ba0b/go.mod h1:ZRKQfBXbGkpdV6QMzT3rU1kSTAnfu1dO8dPKjYprgj8=
go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0=
go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.3.1-0.20221117191849-2c476679df9a/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4=
golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU=
golang.org/x/crypto v0.23.0 h1:dIJU/v2J8Mdglj/8rJ6UUOM3Zc9zLZxVZwwxMooUSAI=
golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8=
golang.org/x/exp v0.0.0-20240531132922-fd00a4e0eefc h1:O9NuF4s+E/PvMIy+9IUZB9znFwUIXEWSstNjek6VpVg=
golang.org/x/exp v0.0.0-20240531132922-fd00a4e0eefc/go.mod h1:XtvwrStGgqGPLc4cjQfWqZHG1YFdYs6swckp8vpsjnc=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/mod v0.17.0 h1:zY54UmvipHiNd+pm+m0x9KhZ9hl1/7QNMyxXbc6ICqA=
golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/net v0.2.0/go.mod h1:KqCZLdyyvdV855qA2rE3GC2aiw5xGR5TEjj8smXukLY=
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M=
golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.0.0-20181122145206-62eef0e2fa9b/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220310020820-b874c991c1a5/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y=
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc=
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
golang.org/x/term v0.6.0/go.mod h1:m6U89DPEgQRMq3DNkDClhWw02AUbt2daBVO4cn4Hv9U=
golang.org/x/term v0.20.0 h1:VnkxpohqXaOBYJtBmEppKUG6mXpi+4O6purfc2+sMhw=
golang.org/x/term v0.20.0/go.mod h1:8UkIAJTvZgivsXaD6/pH6U9ecQzZ45awqEOzuCvwpFY=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
golang.org/x/text v0.15.0 h1:h1V/4gjBv8v9cjcR6+AR5+/cIYK5N/WAgiv4xlsEtAk=
golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
golang.org/x/tools v0.21.0 h1:qc0xYgIbsSDt9EyWz05J5wfa7LOVW0YTLOXrqdLAWIw=
golang.org/x/tools v0.21.0/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
Expand Down
5 changes: 3 additions & 2 deletions lib/checksum.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import (
"bufio"
"crypto/sha256"
"encoding/hex"
"golang.org/x/crypto/openpgp"
"io"
"os"
"path/filepath"
"strings"

"golang.org/x/crypto/openpgp"
)

// getChecksumFromFile Extract the checksum from the signature file
Expand All @@ -24,7 +25,7 @@ func getChecksumFromHashFile(signatureFilePath string, terraformFileName string)
scanner.Split(bufio.ScanLines)
for scanner.Scan() {
split := strings.Split(scanner.Text(), " ")
if split[1] == terraformFileName {
if len(split) == 2 && split[1] == terraformFileName {
return split[0], nil
}
}
Expand Down
11 changes: 1 addition & 10 deletions lib/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,6 @@ import (
"runtime"
)

var (
PubKeyId = "72D7468F"
PubKeyPrefix = "hashicorp_"
PubKeyUri = "https://www.hashicorp.com/.well-known/pgp-key.txt"
)

// GetDefaultBin Get default binary path
func GetDefaultBin() string {
var defaultBin = "/usr/local/bin/terraform"
Expand All @@ -23,12 +17,9 @@ func GetDefaultBin() string {
const (
DefaultMirror = "https://releases.hashicorp.com/terraform"
DefaultLatest = ""
distributionTerraform = "terraform"
distributionOpenTofu = "opentofu"
installFile = "terraform"
InstallDir = ".terraform.versions"
pubKeySuffix = ".asc"
recentFile = "RECENT"
tfDarwinArm64StartVersion = "1.0.2"
VersionPrefix = "terraform_"
DefaultProductId = "terraform"
)
37 changes: 22 additions & 15 deletions lib/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,17 @@ import (

// DownloadFromURL : Downloads the terraform binary and its hash from the source url
func DownloadFromURL(installLocation, mirrorURL, tfversion, versionPrefix, goos, goarch string) (string, error) {
product := getLegacyProduct()
MatthewJohn marked this conversation as resolved.
Show resolved Hide resolved
return DownloadProductFromURL(product, installLocation, mirrorURL, tfversion, versionPrefix, goos, goarch)
}
func DownloadProductFromURL(product Product, installLocation, mirrorURL, tfversion, versionPrefix, goos, goarch string) (string, error) {
var wg sync.WaitGroup
defer wg.Done()
pubKeyFilename := filepath.Join(installLocation, "/", PubKeyPrefix+PubKeyId+pubKeySuffix)
zipUrl := mirrorURL + tfversion + "/" + versionPrefix + tfversion + "_" + goos + "_" + goarch + ".zip"
hashUrl := mirrorURL + tfversion + "/" + versionPrefix + tfversion + "_SHA256SUMS"
hashSignatureUrl := mirrorURL + tfversion + "/" + versionPrefix + tfversion + "_SHA256SUMS." + PubKeyId + ".sig"
zipUrl := mirrorURL + "/" + versionPrefix + tfversion + "_" + goos + "_" + goarch + ".zip"
hashUrl := mirrorURL + "/" + versionPrefix + tfversion + "_SHA256SUMS"
hashSignatureUrl := mirrorURL + "/" + versionPrefix + tfversion + "_SHA256SUMS." + product.GetShaSignatureSuffix()

err := downloadPublicKey(installLocation, pubKeyFilename, &wg)
pubKeyFilename, err := downloadPublicKey(product, installLocation, &wg)
if err != nil {
logger.Error("Could not download public PGP key file.")
return "", err
Expand All @@ -46,6 +49,9 @@ func DownloadFromURL(installLocation, mirrorURL, tfversion, versionPrefix, goos,
return "", err
}

// // Wait for wait group, as the file downloads are required for the below functionality
// wg.Wait()

publicKeyFile, err := os.Open(pubKeyFilename)
if err != nil {
logger.Errorf("Could not open public key %q: %v", pubKeyFilename, err)
Expand Down Expand Up @@ -123,23 +129,24 @@ func downloadFromURL(installLocation string, url string, wg *sync.WaitGroup) (st
return filePath, nil
}

func downloadPublicKey(installLocation string, targetFileName string, wg *sync.WaitGroup) error {
logger.Debugf("Looking up public key file at %q", targetFileName)
publicKeyFileExists := FileExistsAndIsNotDir(targetFileName)
func downloadPublicKey(product Product, installLocation string, wg *sync.WaitGroup) (string, error) {
pubKeyFilePath := filepath.Join(installLocation, "/", product.GetId()+"_"+product.GetPublicKeyId()+pubKeySuffix)
yermulnik marked this conversation as resolved.
Show resolved Hide resolved
logger.Debugf("Looking up public key file at %q", pubKeyFilePath)
publicKeyFileExists := FileExistsAndIsNotDir(pubKeyFilePath)
if !publicKeyFileExists {
// Public key does not exist. Let's grab it from hashicorp
pubKeyFile, errDl := downloadFromURL(installLocation, PubKeyUri, wg)
pubKeyFile, errDl := downloadFromURL(installLocation, product.GetPublicKeyUrl(), wg)
if errDl != nil {
logger.Errorf("Error fetching public key file from %s", PubKeyUri)
return errDl
logger.Errorf("Error fetching public key file from %s", product.GetPublicKeyUrl())
return "", errDl
}
errRename := os.Rename(pubKeyFile, targetFileName)
errRename := os.Rename(pubKeyFile, pubKeyFilePath)
if errRename != nil {
logger.Errorf("Error renaming public key file from %q to %q", pubKeyFile, targetFileName)
return errRename
logger.Errorf("Error renaming public key file from %q to %q", pubKeyFile, pubKeyFilePath)
return "", errRename
}
}
return nil
return pubKeyFilePath, nil
}

func cleanup(paths []string, wg *sync.WaitGroup) {
Expand Down
Loading