Skip to content

Commit

Permalink
fix: Valid canister-based env vars (#2574)
Browse files Browse the repository at this point in the history
# Description
Hyphens are not valid in shell environment variables, but do occur in canister names such as nns-dapp.  This poses a problem for vars with names such as `CANISTER_ID_${CANISTER_NAME}`.

Changes:
- In env vars set by dfx, replace hyphens by underscores.
  • Loading branch information
bitdivine authored Sep 20, 2022
1 parent 96e4e6b commit a32ae7a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ If you want to disable this behavior, you can config it in dfx.json:
}
}

### fix: Valid canister-based env vars

Hyphens are not valid in shell environment variables, but do occur in canister names such as `smiley-dapp`. This poses a problem for vars with names such as `CANISTER_ID_${CANISTER_NAME}`. With this change, hyphens are replaced with underscores in environment variables. The canister id of `smiley-dapp` will be available as `CANISTER_ID_smiley_dapp`. Other environment variables are unaffected.

### feat: Add dfx sns deploy

This allows users to deploy a set of SNS canisters.
Expand Down
4 changes: 2 additions & 2 deletions docs/cli-reference/dfx-envars.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ For example, if you have a `whoami_frontend` canister that lists `whoami` under

## CANISTER_ID\_{canister.name}

Use environment variables with the `CANISTER_ID` prefix to reference the canister identifier for each canister in the `dfx.json` file for your project.
Use environment variables with the `CANISTER_ID` prefix to reference the canister identifier for each canister in the `dfx.json` file for your project. Hyphens are invalid in environment variables and are replaced by underscores.

For example, if you have a `linkedup` project that consists of the `linkedup` and `connectd` canisters, you could use the `CANISTER_ID_linkedup` and `CANISTER_ID_connectd` environment variables to refer to the canister identifiers—for example `ryjl3-tyaaa-aaaaa-aaaba-cai` and `rrkah-fqaaa-aaaaa-aaaaq-cai`—created for your project.
For example, if you have a `linkedup` project that consists of the `linkedup` and `connect-d` canisters, you could use the `CANISTER_ID_linkedup` and `CANISTER_ID_connect_d` environment variables to refer to the canister identifiers—for example `ryjl3-tyaaa-aaaaa-aaaba-cai` and `rrkah-fqaaa-aaaaa-aaaaq-cai`—created for your project.

## DFX_CONFIG_ROOT

Expand Down
10 changes: 8 additions & 2 deletions src/dfx/src/lib/builders/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,14 +316,20 @@ pub fn environment_variables<'a>(
};

vars.push((
Owned(format!("CANISTER_CANDID_PATH_{}", canister.get_name())),
Owned(format!(
"CANISTER_CANDID_PATH_{}",
canister.get_name().replace('-', "_")
)),
Borrowed(candid_path),
));
}
}
for canister in pool.get_canister_list() {
vars.push((
Owned(format!("CANISTER_ID_{}", canister.get_name())),
Owned(format!(
"CANISTER_ID_{}",
canister.get_name().replace('-', "_")
)),
Owned(canister.canister_id().to_text().into()),
));
}
Expand Down

0 comments on commit a32ae7a

Please sign in to comment.