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

Update aws_get_environment_value to return NULL for empty values #1141

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

waahm7
Copy link
Contributor

@waahm7 waahm7 commented Jul 31, 2024

Description of changes:
aws_get_environment_value is error-prone because one of the frequent use cases is to check an environment variable, else check other source like config file. In that case, the previous implementation required us to check three cases:

  • NULL -> check the alternative
  • Empty -> destroy and check the alternative
  • Available -> use that
    Since we don't need to differentiate between empty values and unset values, treat empty environment values as unset.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@codecov-commenter
Copy link

codecov-commenter commented Jul 31, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 83.84%. Comparing base (2add521) to head (e5e7776).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1141      +/-   ##
==========================================
+ Coverage   83.82%   83.84%   +0.01%     
==========================================
  Files          57       57              
  Lines        5991     5998       +7     
==========================================
+ Hits         5022     5029       +7     
  Misses        969      969              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@bretambrose
Copy link
Contributor

  Since we don't need to differentiate between empty values and unset values, treat empty environment values as unset.

This is a pretty big assumption since you're not only asserting it for right now, but for everything that comes in the future too. I don't really agree with this.

@@ -14,7 +14,7 @@ int aws_get_environment_value(
struct aws_string **value_out) {

const char *value = getenv(aws_string_c_str(variable_name));
if (value == NULL) {
if (value == NULL || value[0] == '\0') {
Copy link
Contributor

Choose a reason for hiding this comment

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

It sucks, but this is how it is with environment variables. Sometimes just the existence of the env-var is meaningful, even if it's blank. Maybe create an alternate function like aws_get_environment_variable_nonempty() that has this behavior, and scrub the codebase for places that would benefit from using that instead

Copy link
Contributor Author

@waahm7 waahm7 Aug 1, 2024

Choose a reason for hiding this comment

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

Yeah, I agree. We can discuss the following options in the office tomorrow.

  1. Modify the existing function, and we can create a new function in the future if required, like if we have a use case where env-var can be blank.

  2. Create a new function, aws_get_environment_variable_nonempty, aws_get_environment_variable_cursor, or aws_get_environment_variable_c_str. I prefer the aws_get_environment_variable_cursor if we decide to just create a new function.

  3. Keep the function as it is, and validate all the uses to handle it correctly.

@waahm7 waahm7 marked this pull request as draft August 1, 2024 18:21
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.

4 participants