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 deployment variable list --save with secrets #1558

Merged
merged 1 commit into from
Feb 21, 2024

Conversation

ashb
Copy link
Contributor

@ashb ashb commented Feb 20, 2024

Description

After the migration to the REST API in #1425 it wasn't dealing with secret variables (which don't have a value anymore).

And while I'm there do a bit of tidying up:

  • _, x := range instead of slice index access
  • Remove the use of environmentVariablesObjects global variable!
  • Refactoring of selecting the variable key to one place only (rather
    than in multiple)

🎟 Issue(s)

Related #XXX

🧪 Functional Testing

I ran the command in question on a deployment with secret variables

📋 Checklist

  • Rebased from the main (or release if patching) branch (before testing)
  • Ran make test before taking out of draft
  • Ran make lint before taking out of draft
  • Added/updated applicable tests
  • Tested against Astro-API (if necessary).
  • Tested against Houston-API and Astronomer (if necessary).
  • Communicated to/tagged owners of respective clients potentially impacted by these changes.
  • Updated any related documentation

Copy link

codecov bot commented Feb 20, 2024

Codecov Report

Attention: 2 lines in your changes are missing coverage. Please review.

Comparison is base (f47a24a) 86.16% compared to head (022430f) 86.18%.
Report is 4 commits behind head on main.

Files Patch % Lines
cloud/deployment/deployment_variable.go 93.93% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1558      +/-   ##
==========================================
+ Coverage   86.16%   86.18%   +0.01%     
==========================================
  Files         112      112              
  Lines       14952    14944       -8     
==========================================
- Hits        12883    12879       -4     
+ Misses       1251     1248       -3     
+ Partials      818      817       -1     

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

@ashb
Copy link
Contributor Author

ashb commented Feb 20, 2024

This will need backporting to 1.23 too (it applies cleanly)

varTab.AddRow([]string{strconv.Itoa(nbEnvVarFound), environmentVariablesObjects[i].Key, printValue, strconv.FormatBool(environmentVariablesObjects[i].IsSecret)}, false)
for i, variable := range environmentVariablesObjects {
if variable.Value != nil && !variable.IsSecret {
printValue = *variable.Value
Copy link
Contributor

Choose a reason for hiding this comment

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

do we not have to reset this to ****
eg. the first variable is not secret then the next one is, won't do the next printValue be the same as the first one?

Copy link
Contributor

Choose a reason for hiding this comment

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

if that is indeed the case, we should add a test case to cover that
if it's not, maybe you can help me fill in the missing gaps im missing

Copy link
Contributor

Choose a reason for hiding this comment

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

Screenshot 2024-02-20 at 6 36 17 PM seems to be working as intended

Copy link
Contributor

Choose a reason for hiding this comment

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

what if theres another secret var after the third one

Copy link
Contributor

Choose a reason for hiding this comment

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

Agree with Vandy's comment here, can we just declare a temporary variable inside the loop? A unit test case is required here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I didn't actually change this behaviour -- before it was

printValue = *environmentVariablesObjects[i].Value

I agree though, while we're here lets fix it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Global variables bad!

Copy link
Contributor

@sunkickr sunkickr left a comment

Choose a reason for hiding this comment

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

Everything appears to be working now

@ashb ashb force-pushed the variables-save-with-secrets-dont-panic branch from 53adbfa to 2ea288c Compare February 21, 2024 11:02
After the migration to the REST API in #1425 it wasn't dealing with secret
variables (which don't have a value anymore).

And while I'm there do a bit of tidying up:
- `_, x := range` instead of slice index access
- Remove the use of `environmentVariablesObjects` global variable!
- Refactoring of selecting the variable key to one place only (rather
  than in multiple)
@ashb ashb force-pushed the variables-save-with-secrets-dont-panic branch from 2ea288c to 022430f Compare February 21, 2024 11:06
@ashb ashb requested a review from vandyliu February 21, 2024 11:07
Copy link
Contributor

@vandyliu vandyliu left a comment

Choose a reason for hiding this comment

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

thanks for the fix and additionally the improvements!

@kushalmalani kushalmalani merged commit 8159d12 into main Feb 21, 2024
4 of 5 checks passed
@kushalmalani kushalmalani deleted the variables-save-with-secrets-dont-panic branch February 21, 2024 17:44
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.

None yet

4 participants