Skip to content

Commit

Permalink
Updated blank aliases environment variable name behavior to remove le…
Browse files Browse the repository at this point in the history
…ading underscore and removed whitespace, removed merge artifact from README and implemented cleaner implementation for the leading underscore removal
  • Loading branch information
YuvalShAz committed Feb 22, 2024
1 parent d4ae0de commit d7344f7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,7 @@ To use a prefix, enter at least three characters followed by an asterisk. For ex

Set `parse-json-secrets` to `true` to create environment variables for each key/value pair in the JSON.

<<<<<<< HEAD
Note that if the JSON uses case-sensitive keys such as "name" and "Name", the action will have duplicate name conflicts. In this case, set `parse-json-secrets` to `false` and parse the JSON secret value separately. Additionally, if the secret is JSON and this flag is true: blank aliases are allowed and result in an environment variables with a leading underscore (see Example 4).
=======
Note that if the JSON uses case-sensitive keys such as "name" and "Name", the action will have duplicate name conflicts. In this case, set `parse-json-secrets` to `false` and parse the JSON secret value separately. Additionally, if the secret is JSON and this flag is true: blank aliases are allowed and result in environment variables with no prefix (see Example 4).
>>>>>>> 5c54aff (Updated blank alias prefixing to remove leading underscore)
### Examples
Expand Down
12 changes: 7 additions & 5 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,14 @@ export function injectSecret(secretName: string, secretValue: string, parseJsonS
for (const k in secretMap) {
const keyValue = typeof secretMap[k] === 'string' ? secretMap[k] as string : JSON.stringify(secretMap[k]);

// Check to avoid prepending an underscore
const newEnvNamePrefix = tempEnvName || transformToValidEnvName(secretName);
const newEnvNameSpacer: "_"|"" = newEnvNamePrefix ? "_" : "";
// Append the current key to the name of the env variable and check to avoid prepending an underscore
const newEnvName = [
tempEnvName || transformToValidEnvName(secretName),
transformToValidEnvName(k)
]
.filter(elem => elem) // Uses truthy-ness of elem to determine if it remains
.join("_"); // Join the remaining elements with an underscore

// Append the current key to the name of the env variable
const newEnvName = `${newEnvNamePrefix}${newEnvNameSpacer}${transformToValidEnvName(k)}`;
secretsToCleanup = [...secretsToCleanup, ...injectSecret(secretName, keyValue, parseJsonSecrets, newEnvName)];
}
} else {
Expand Down

0 comments on commit d7344f7

Please sign in to comment.