Skip to content

Commit

Permalink
feat(cli): Introduce optional GITHUB_API_TOKEN_CDKTF env var to use f…
Browse files Browse the repository at this point in the history
…or authenticated requests when determining available pre-built providers for Go

We can't use CDKTF_ in a prefix as that collides with yargs arguments from env vars and its strict mode.
Refer to: yargs/yargs#873
  • Loading branch information
ansgarm committed Dec 14, 2022
1 parent 9a21a46 commit 9641a02
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ jobs:
env:
CHECKPOINT_DISABLE: "1"
TERRAFORM_VERSION: ${{ matrix.terraform }}
GITHUB_API_TOKEN_CDKTF: ${{ secrets.GITHUB_TOKEN }}
timeout-minutes: 60

steps:
Expand Down Expand Up @@ -128,6 +129,7 @@ jobs:
env:
CHECKPOINT_DISABLE: "1"
TERRAFORM_VERSION: ${{ matrix.terraform }}
GITHUB_API_TOKEN_CDKTF: ${{ secrets.GITHUB_TOKEN }}
timeout-minutes: 60

steps:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ import * as semver from "semver";
import fetch from "node-fetch";
import * as z from "zod";

// Can't use CDKTF_ as prefix because yargs .env("CDKTF") in strict mode does not allow us to
// Refer to: https://github.com/yargs/yargs/issues/873
const { GITHUB_API_TOKEN_CDKTF } = process.env;

// {
// "version": "1.0.0",
// "name": "testUSHasF",
Expand Down Expand Up @@ -670,6 +674,10 @@ class GoPackageManager extends PackageManager {
const response = await fetch(url, {
headers: {
Accept: "application/vnd.github+json",
"User-Agent": "HashiCorp/cdktf-cli",
...(GITHUB_API_TOKEN_CDKTF
? { Authorization: `Bearer ${GITHUB_API_TOKEN_CDKTF}` }
: {}),
},
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Use these environment variables to configure CDK for Terraform (CDKTF) behavior.
| Variable Name | Description | Default |
| ------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------- |
| CDKTF_DISABLE_PLUGIN_CACHE_ENV | If set to `true` or `1`, CDKTF disables the [plugin cache](/cli/config/config-file#provider-plugin-cache). Otherwise, CDKTF creates the plugin cache directory in `~/.terraform.d/plugin-cache` if it is not already present. | |
| GITHUB_API_TOKEN_CDKTF | If set, the `provider add` and `provider update` command will use this token for authenticated requests to Github when looking for pre-built provider packages for Go. | |
| CDKTF_HOME | Where CDKTF should store cache and configuration files. | `~/.cdktf` |
| CDKTF_LOG_FILE_DIRECTORY | The directory path where CDKTF should create `cdktf.log` and print logs at the `debug` level. If not set, CDKTF writes logs to standard out at the level specified in `CDKTF_LOG_LEVEL`. | standard out |
| CDKTF_LOG_LEVEL | Controls how much log information CDKTF prints to the console. You can set it to one of the following values: `all`, `debug`, `info`, `warn`, `error`, `fatal`, `off`. | `warn` |
Expand Down

0 comments on commit 9641a02

Please sign in to comment.