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

feat: Implement github SDK with access token support #138

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

asvinours
Copy link

@asvinours asvinours commented Jan 14, 2023

fixes #132 and #133

changes summary:

  • Replace anonymous HTTP call with an implementation of the GitHub SDK
    • Add support for authenticated GitHub requests using access token
  • Upgrade go to 1.19
  • Remove the proxy
    • Retrieve the list of versions from GitHub instead of https://warrensbox.github.io/terragunt-versions-list/index.json
    • Download release assets directly from GitHub API
tgswitch$ go run .
2023/01/14 11:56:02 Unable to make request. Please try again.
exit status 1

tgswitch$ GITHUB_AUTH_TOKEN="ghp_[...]" go run .
✔ 0.38.1
Installing terragrunt at /home/fbaumann/bin
Downloading https://github.com/gruntwork-io/terragrunt/releases/download/v0.38.1/terragrunt_linux_amd64 to terragrunt_linux_amd64
Downloading ...
35337033 bytes downloaded.
Switched terragrunt to version "0.38.1"
make test output
go build -v -ldflags "-X main.version=" -o tgswitch github.com/warrensbox/tgswitch
mkdir -vp ./build
mv tgswitch ./build
go test -v ./...
=== RUN   TestMain
=== RUN   TestMain/User_should_exist
    main_test.go:19: Current user exist: /home/fbaumann  [expected]
--- PASS: TestMain (0.00s)
    --- PASS: TestMain/User_should_exist (0.00s)
PASS
ok  	github.com/warrensbox/tgswitch	(cached)
=== RUN   TestNewCommand
    command_test.go:17: Value returned is a pointer &{terragrunt} [expected]
--- PASS: TestNewCommand (0.00s)
=== RUN   TestPathList
    command_test.go:33: Found bin path [expected]
--- PASS: TestPathList (0.00s)
=== RUN   TestFind
--- PASS: TestFind (0.02s)
=== RUN   TestDownloadFromURL_FileNameMatch
Current user: /home/fbaumann 
Downloading https://github.com/gruntwork-io/terragrunt/releases/download/v0.13.9/terragrunt_linux_amd64 to terragrunt_linux_amd64
Downloading ...
15276607 bytes downloaded.
    download_test.go:63: Expected file /home/fbaumann/.terragrunt.versions_test/terragrunt_linux_amd64
    download_test.go:64: Downloaded file /home/fbaumann/.terragrunt.versions_test/terragrunt_linux_amd64
    download_test.go:65: Download file matches expected file
Downloading https://github.com/gruntwork-io/terragrunt/releases/download/v0.14.11/terragrunt_linux_amd64 to terragrunt_linux_amd64
Downloading ...
16535740 bytes downloaded.
    download_test.go:80: Expected file name /home/fbaumann/.terragrunt.versions_test/terragrunt_linux_amd64
    download_test.go:81: Downloaded file name /home/fbaumann/.terragrunt.versions_test/terragrunt_linux_amd64
    download_test.go:82: Download file name matches expected file
--- PASS: TestDownloadFromURL_FileNameMatch (2.00s)
=== RUN   TestDownloadFromURL_FileExist
Current user: /home/fbaumann 
2023/01/14 11:51:27 Creating directory for terragrunt: /home/fbaumann/.terragrunt.versions_test/
Downloading https://github.com/gruntwork-io/terragrunt/releases/download/v0.13.9/terragrunt_linux_amd64 to terragrunt_linux_amd64
Downloading ...
15276607 bytes downloaded.
    download_test.go:133: Expected file /home/fbaumann/.terragrunt.versions_test/terragrunt_linux_amd64
    download_test.go:134: Downloaded file /home/fbaumann/.terragrunt.versions_test/terragrunt_linux_amd64
    download_test.go:135: Download file matches expected file
Downloading https://github.com/gruntwork-io/terragrunt/releases/download/v0.14.11/terragrunt_linux_amd64 to terragrunt_linux_amd64
Downloading ...
16535740 bytes downloaded.
    download_test.go:150: Expected file /home/fbaumann/.terragrunt.versions_test/terragrunt_linux_amd64
    download_test.go:151: Downloaded file /home/fbaumann/.terragrunt.versions_test/terragrunt_linux_amd64
    download_test.go:152: Download file matches expected file
--- PASS: TestDownloadFromURL_FileExist (1.02s)
=== RUN   TestDownloadFromURL_Valid
    download_test.go:171: Valid URL from https://github.com/gruntwork-io/terragrunt/releases/download/
--- PASS: TestDownloadFromURL_Valid (0.00s)
=== RUN   TestRenameFile
2023/01/14 11:51:28 Creating directory for terragrunt: /home/fbaumann/.terragrunt.versions_test/
==> done creating file /home/fbaumann/.terragrunt.versions_test/terragrunt
    files_test.go:39: File exist /home/fbaumann/.terragrunt.versions_test/terragrunt
    files_test.go:48: New file exist /home/fbaumann/.terragrunt.versions_test/terragrunt_0.0.7
    files_test.go:58: Old file does not exist /home/fbaumann/.terragrunt.versions_test/terragrunt
--- PASS: TestRenameFile (0.00s)
=== RUN   TestRemoveFiles
2023/01/14 11:51:28 Creating directory for terragrunt: /home/fbaumann/.terragrunt.versions_test/
==> done creating file /home/fbaumann/.terragrunt.versions_test/terragrunt
    files_test.go:82: File exist /home/fbaumann/.terragrunt.versions_test/terragrunt
    files_test.go:94: Old file does not exist /home/fbaumann/.terragrunt.versions_test/terragrunt
--- PASS: TestRemoveFiles (0.00s)
=== RUN   TestCreateDirIfNotExist
    files_test.go:114: Directory should not exist /home/fbaumann/.terragrunt.versions_test/ (expected)
2023/01/14 11:51:28 Creating directory for terragrunt: /home/fbaumann/.terragrunt.versions_test/
    files_test.go:121: Creating directory /home/fbaumann/.terragrunt.versions_test/
    files_test.go:124: Directory exist /home/fbaumann/.terragrunt.versions_test/ (expected)
--- PASS: TestCreateDirIfNotExist (0.00s)
=== RUN   TestWriteLines
2023/01/14 11:51:28 Creating directory for terragrunt: /home/fbaumann/.terragrunt.versions_test/
    files_test.go:196: Write versions exist (expected)
--- PASS: TestWriteLines (0.00s)
=== RUN   TestReadLines
2023/01/14 11:51:28 Creating directory for terragrunt: /home/fbaumann/.terragrunt.versions_test/
    files_test.go:250: Read versions exist (expected)
--- PASS: TestReadLines (0.00s)
=== RUN   TestIsDirEmpty
    files_test.go:270: Create test dir: 2023-01-14 
2023/01/14 11:51:28 Creating directory for terragrunt: /home/fbaumann/.terragrunt.versions_test/
2023/01/14 11:51:28 Creating directory for terragrunt: /home/fbaumann/.terragrunt.versions_test//2023-01-14
    files_test.go:278: Expected directory to be empty /home/fbaumann/.terragrunt.versions_test//2023-01-14 [expected]
    files_test.go:281: Directory empty
--- PASS: TestIsDirEmpty (0.00s)
=== RUN   TestCheckDirHasTGBin
2023/01/14 11:51:28 Creating directory for terragrunt: /home/fbaumann/.terragrunt.versions_test/
==> done creating file /home/fbaumann/.terragrunt.versions_test/terragrunt_linux_amd64
    files_test.go:312: Expected directory to have tg file /home/fbaumann/.terragrunt.versions_test/terragrunt_linux_amd64 [expected]
    files_test.go:315: Directory empty
--- PASS: TestCheckDirHasTGBin (0.00s)
=== RUN   TestInstall
=== RUN   TestInstall/User_should_exist
    install_test.go:20: Current user exist: /home/fbaumann  [expected]
--- PASS: TestInstall (0.00s)
    --- PASS: TestInstall/User_should_exist (0.00s)
=== RUN   TestRemoveDuplicateVersions
    list_versions_test.go:20: Write versions exist (expected)
--- PASS: TestRemoveDuplicateVersions (0.00s)
=== RUN   TestValidVersionFormat
    list_versions_test.go:34: Valid version format : 0.11.8 (expected)
    list_versions_test.go:44: Valid version format : 1.11.9 (expected)
Invalid terragrunt version format. Format should be #.#.# or #.#.#-@# where # is numbers and @ is word characters. For example, 0.11.7 and 0.11.9-beta1 are valid versions
    list_versions_test.go:54: Invalid version format : 1.11.a (expected)
Invalid terragrunt version format. Format should be #.#.# or #.#.#-@# where # is numbers and @ is word characters. For example, 0.11.7 and 0.11.9-beta1 are valid versions
    list_versions_test.go:64: Invalid version format : 22323 (expected)
Invalid terragrunt version format. Format should be #.#.# or #.#.#-@# where # is numbers and @ is word characters. For example, 0.11.7 and 0.11.9-beta1 are valid versions
    list_versions_test.go:74: Invalid version format : @^&*!)! (expected)
    list_versions_test.go:84: Valid version format : 1.11.9-beta1 (expected)
    list_versions_test.go:94: Valid version format : 0.12.0-rc2 (expected)
    list_versions_test.go:104: Valid version format : 1.11.4-boom (expected)
Invalid terragrunt version format. Format should be #.#.# or #.#.#-@# where # is numbers and @ is word characters. For example, 0.11.7 and 0.11.9-beta1 are valid versions
    list_versions_test.go:114: Invalid version format : 1.11.4-1 (expected)
--- PASS: TestValidVersionFormat (0.00s)
=== RUN   TestCreateSymlink
    symlink_test.go:30: Symlink does not exist  [expected]
    symlink_test.go:41: Symlink exist /home/fbaumann/test-tgswitch-dest [expected]
--- PASS: TestCreateSymlink (0.00s)
=== RUN   TestRemoveSymlink
    symlink_test.go:68: Symlink does exist  [expected]
    symlink_test.go:69: Creating symlink
    symlink_test.go:82: Symlink was removed   [expected]
--- PASS: TestRemoveSymlink (0.00s)
=== RUN   TestCheckSymlink
    symlink_test.go:103: Creating symlink
    symlink_test.go:112: Symlink does exist  [expected]
--- PASS: TestCheckSymlink (0.00s)
PASS
ok  	github.com/warrensbox/tgswitch/lib	(cached)

@mholttech
Copy link

I prefer the current mechanism of using https://warrensbox.github.io/terragunt-versions-list/index.json which is generated from https://github.com/warrensbox/terragunt-versions-list

The Github API has usage restrictions when not authenticated and my organization doesn't use github so managing github credentials for this would be difficult. If this is popular, I would suggest making it an option to use this instead of the Proxy but not replace it outright.

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.

Unable to download new version through the proxy
3 participants