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

Fix order of RPC and wallet keys fetched from env vars #1150

Conversation

lukaszcl
Copy link
Contributor

@lukaszcl lukaszcl commented Sep 23, 2024

This commit refactors the code in lib/config/env.go to use sorted keys when handling environment variables. Previously, the code was iterating over the environment variables in an arbitrary order, which could lead to inconsistent behavior. Now, the getSortedEnvs function has been added to sort the environment variables by key before processing them.


Below is a summarization created by an LLM (gpt-4-0125-preview). Be mindful of hallucinations and verify accuracy.

Why

The changes ensure consistency and predictability in how environment variables are read and processed by sorting them alphabetically. This facilitates better organization and potentially makes debugging easier when dealing with a large number of environment variables.

What

  • lib/config/env.go
    • Added import of sort package to enable sorting functionality.
    • Introduced a new utility function getSortedEnvs which sorts environment variables by their keys before returning them. This function is now used in place of direct calls to os.Environ() in ReadEnvVarSlice_String, readEnvVarGroupedMap, and readEnvVarSingleMap functions.
      • This change ensures that environment variables are processed in a consistent order, which is particularly useful for functions that depend on the order of environment variables, such as when generating slices or maps from them.

This commit refactors the code in `lib/config/env.go` to use sorted keys when handling environment variables. Previously, the code was iterating over the environment variables in an arbitrary order, which could lead to inconsistent behavior. Now, the `getSortedEnvs` function has been added to sort the environment variables by key before processing them.
@cl-sonarqube-production
Copy link

@lukaszcl lukaszcl merged commit 2a5f3f4 into main Sep 23, 2024
45 checks passed
@lukaszcl lukaszcl deleted the TT-1746-CTF-should-read-wallet-keys-in-the-order-it-is-given-in-testsecrets branch September 23, 2024 09:12
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.

2 participants