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

Bash variable name iteration #1443

Closed
wants to merge 14 commits into from

Conversation

IsaacCalligeros95
Copy link
Contributor

@IsaacCalligeros95 IsaacCalligeros95 commented Feb 19, 2025

This is an alternative to #1441 If we can use the cli command xxd this is not an issue and simplifies the implementation significantly.

This change adds the ability to iterate variable names in base. The implementation for this is based off of the PowerShell implementation of OctopusParameters Decrypt-Variables.

For PowerShell we do the following in C#

  • Base 64 encode the variable name and value with a $ delimiter between them. (This is to make sure all special characters are removed)
  • Encrypt the combined string of all variables (We can a base string and IV)
  • Base64 encode the base string and convert the IV to hex.

These are then string replaced in the PowerShell bootstrap.ps1 script.

The PowerShell bootstrap script does the following:

  • Decodes the IV and Hex
  • Decrypts the whole string
  • Decodes one by one the variable name and values

This works well in Powershell ~3000 variables takes about 1 second in this process.
In base we use Openssl to decode base64 strings, this spins up a process and overall repeating this same process for ~3000 variables takes ~60 seconds.

To work around this I've settled on Hex encoding the variable names, unlike base64 hex encoded strings can be concatenated and decrypted all at once, this also doesn't depend on the openssl process being invoked. We have to handle the hex to string ourselves, we could use strtonum but it's not available everywhere.

image

Accessing keys

echo ${!example_array[@]}

}

hex_to_string() {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be removed if we can depend on xxd. This is generally supported but not available everywhere, we could check if it is available and only add the octopus_parameters if it is.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hexdump seems generally available on Nix, but is not installed by default on mac

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant