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

List scoped common variables #488

Merged
merged 8 commits into from
Feb 19, 2025
Merged

Conversation

bec-callow-oct
Copy link
Contributor

@bec-callow-oct bec-callow-oct commented Feb 17, 2025

[SC-93474]

When scoped tenant common variables are enabled, both common and project variables can be scoped by multiple environments. This PR provides support for variables with an array of environment scopes.

Before

Tenant common variables had no environment scoping, so Environment was blank. Project variables were only scoped to one environment, so per template, one row existed per environment.

$ ./octopus tenant variables list "t1"
NAME                        LABEL         TYPE     OWNER                    ENVIRONMENT  VALUE                   SENSITIVE  DEFAULT VALUE
template1                                 Library  set1                                  default                 false      true
secret template                           Library  set1                                  ***                     true       true
missing t1                                Library  missing set 1                         <missing>                      false      true
missing t2                                Library  missing set 1                         default                 false      true
proj template1                            Project  var scopes               Dev          default                 false      true
proj template1                            Project  var scopes               Test         CLI missing update 1    false      false
proj template1                            Project  var scopes               Prod         default                 false      true
Missing Proj template 1     missing vars  Project  var scopes               Test         <missing>               false      true
Missing Proj template 1     missing vars  Project  var scopes               Prod         <missing>               false      true
Missing Proj template 1     missing vars  Project  var scopes               Dev          <missing>               false      true

After

Tenant common variables now have environment scoping, and both common and project variables can have multiple environment scopes. We still list one row per template and environment because each environment can only have one value. Tested combining environment names for shared scopes into a comma separated list, but values were cut off when the list was long.

$ ./octopus tenant variables list "t1"
NAME                        LABEL  TYPE     OWNER                    ENVIRONMENT  VALUE                   SENSITIVE  DEFAULT VALUE
missing t1                         Library  missing set 1            Prod         <missing>               false      true
missing t1                         Library  missing set 1            Test         <missing>               false      true
missing t1                         Library  missing set 1            Dev          Dev scope only          false      false
missing t2                         Library  missing set 1            Dev          default                 false      true
missing t2                         Library  missing set 1            Test         default                 false      true
missing t2                         Library  missing set 1            Prod         default                 false      true
no scope common template 1         Library  no scope set1            Prod         default                 false      true
no scope common template 1         Library  no scope set1            Dev          default                 false      true
no scope common template 1         Library  no scope set1            Test         default                 false      true
secret template                    Library  set1                     Prod         ***                     true       true
secret template                    Library  set1                     Test         ***                     true       true
secret template                    Library  set1                     Dev          ***                     true       true
template1                          Library  set1                     Test         default                 false      true
template1                          Library  set1                     Prod         default                 false      true
template1                          Library  set1                     Dev          latest cli              false      false
Missing Proj template 1            Project  var scopes               Prod         <missing>               false      true
Missing Proj template 1            Project  var scopes               Dev          <missing>               false      true
Missing Proj template 1            Project  var scopes               Test         <missing>               false      true
proj template1                     Project  var scopes               Test         update 1                false      false
proj template1                     Project  var scopes               Dev          default                 false      true
proj template1                     Project  var scopes               Prod         default                 false      true
proj template 1                    Project  var scopes 2             Dev          project-template1-test  false      false
proj template 1                    Project  var scopes 2             Test         project-template1-test  false      false

@bec-callow-oct bec-callow-oct marked this pull request as ready for review February 18, 2025 22:53
Copy link
Collaborator

@tothegills tothegills left a comment

Choose a reason for hiding this comment

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

I've tested with feature toggles on and off. The correct variables are shown in both cases.
I think the choice to print a row per environment is a good one given our constraints. We can iterate on the design if feedback indicates that it is confusing.

I have a suspicion that we may end up with the wrong answer when asking if the feature toggle is disabled for versions of Octopus that do not have the feature toggle filter implemented. We may need to get a name match (and handle when the name does not exist).

}
var allVariableValues []*VariableValue
for _, element := range vars.LibraryVariables {
if toggleValue {
Copy link
Collaborator

@tothegills tothegills Feb 19, 2025

Choose a reason for hiding this comment

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

I was going to recommend splitting this into two functions, one for toggle on and off. But perhaps this makes more sense if we are going to remove one half anyway.

returnToggleResponse, err := configuration.Get(client, toggleRequest)

if err != nil {
return false, err
Copy link
Collaborator

Choose a reason for hiding this comment

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

What happens when the toggle name parameter does not exist? ie the cli is being run against a version of Octopus that doesn't have the toggle filter implemented.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch. I've updated the function to handle an empty list of toggles, as well as a name check since older versions of octopus return all toggles instead of just one

@bec-callow-oct bec-callow-oct merged commit 6592cb8 into main Feb 19, 2025
4 checks passed
@bec-callow-oct bec-callow-oct deleted the fnm/scoped-common-variables branch February 19, 2025 06:34
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