diff options
-rw-r--r-- | changelogs/unreleased/api_masked_variables.yml | 5 | ||||
-rw-r--r-- | doc/api/project_level_variables.md | 12 | ||||
-rw-r--r-- | lib/api/entities.rb | 1 | ||||
-rw-r--r-- | lib/api/variables.rb | 2 | ||||
-rw-r--r-- | spec/requests/api/variables_spec.rb | 5 |
5 files changed, 21 insertions, 4 deletions
diff --git a/changelogs/unreleased/api_masked_variables.yml b/changelogs/unreleased/api_masked_variables.yml new file mode 100644 index 00000000000..3605339cb91 --- /dev/null +++ b/changelogs/unreleased/api_masked_variables.yml @@ -0,0 +1,5 @@ +--- +title: 'API: Allow to get and set "masked" attribute for variables' +merge_request: 28381 +author: Mathieu Parent +type: added diff --git a/doc/api/project_level_variables.md b/doc/api/project_level_variables.md index 4a6f5624394..3b00f6f140e 100644 --- a/doc/api/project_level_variables.md +++ b/doc/api/project_level_variables.md @@ -52,7 +52,9 @@ curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/a { "key": "TEST_VARIABLE_1", "variable_type": "env_var", - "value": "TEST_1" + "value": "TEST_1", + "protected": false, + "masked": true } ``` @@ -71,6 +73,7 @@ POST /projects/:id/variables | `value` | string | yes | The `value` of a variable | | `variable_type` | string | no | The type of a variable. Available types are: `env_var` (default) and `file` | | `protected` | boolean | no | Whether the variable is protected | +| `masked` | boolean | no | Whether the variable is masked | ``` curl --request POST --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/1/variables" --form "key=NEW_VARIABLE" --form "value=new value" @@ -81,7 +84,8 @@ curl --request POST --header "PRIVATE-TOKEN: <your_access_token>" "https://gitla "key": "NEW_VARIABLE", "value": "new value", "variable_type": "env_var", - "protected": false + "protected": false, + "masked": false } ``` @@ -100,6 +104,7 @@ PUT /projects/:id/variables/:key | `value` | string | yes | The `value` of a variable | | `variable_type` | string | no | The type of a variable. Available types are: `env_var` (default) and `file` | | `protected` | boolean | no | Whether the variable is protected | +| `masked` | boolean | no | Whether the variable is masked | ``` curl --request PUT --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/1/variables/NEW_VARIABLE" --form "value=updated value" @@ -110,7 +115,8 @@ curl --request PUT --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab "key": "NEW_VARIABLE", "value": "updated value", "variable_type": "env_var", - "protected": true + "protected": true, + "masked": false } ``` diff --git a/lib/api/entities.rb b/lib/api/entities.rb index 1a3318fe849..96a1ccefbe5 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -1303,6 +1303,7 @@ module API class Variable < Grape::Entity expose :variable_type, :key, :value expose :protected?, as: :protected, if: -> (entity, _) { entity.respond_to?(:protected?) } + expose :masked?, as: :masked, if: -> (entity, _) { entity.respond_to?(:masked?) } end class Pipeline < PipelineBasic diff --git a/lib/api/variables.rb b/lib/api/variables.rb index a1bb21b3a06..b07dd1bab79 100644 --- a/lib/api/variables.rb +++ b/lib/api/variables.rb @@ -55,6 +55,7 @@ module API requires :key, type: String, desc: 'The key of the variable' requires :value, type: String, desc: 'The value of the variable' optional :protected, type: String, desc: 'Whether the variable is protected' + optional :masked, type: String, desc: 'Whether the variable is masked' optional :variable_type, type: String, values: Ci::Variable.variable_types.keys, desc: 'The type of variable, must be one of env_var or file. Defaults to env_var' if Gitlab.ee? @@ -81,6 +82,7 @@ module API optional :key, type: String, desc: 'The key of the variable' optional :value, type: String, desc: 'The value of the variable' optional :protected, type: String, desc: 'Whether the variable is protected' + optional :masked, type: String, desc: 'Whether the variable is masked' optional :variable_type, type: String, values: Ci::Variable.variable_types.keys, desc: 'The type of variable, must be one of env_var or file' if Gitlab.ee? diff --git a/spec/requests/api/variables_spec.rb b/spec/requests/api/variables_spec.rb index cc07869a744..55b1419a004 100644 --- a/spec/requests/api/variables_spec.rb +++ b/spec/requests/api/variables_spec.rb @@ -43,6 +43,7 @@ describe API::Variables do expect(response).to have_gitlab_http_status(200) expect(json_response['value']).to eq(variable.value) expect(json_response['protected']).to eq(variable.protected?) + expect(json_response['masked']).to eq(variable.masked?) expect(json_response['variable_type']).to eq('env_var') end @@ -74,13 +75,14 @@ describe API::Variables do context 'authorized user with proper permissions' do it 'creates variable' do expect do - post api("/projects/#{project.id}/variables", user), params: { key: 'TEST_VARIABLE_2', value: 'PROTECTED_VALUE_2', protected: true } + post api("/projects/#{project.id}/variables", user), params: { key: 'TEST_VARIABLE_2', value: 'PROTECTED_VALUE_2', protected: true, masked: true } end.to change {project.variables.count}.by(1) expect(response).to have_gitlab_http_status(201) expect(json_response['key']).to eq('TEST_VARIABLE_2') expect(json_response['value']).to eq('PROTECTED_VALUE_2') expect(json_response['protected']).to be_truthy + expect(json_response['masked']).to be_truthy expect(json_response['variable_type']).to eq('env_var') end @@ -93,6 +95,7 @@ describe API::Variables do expect(json_response['key']).to eq('TEST_VARIABLE_2') expect(json_response['value']).to eq('VALUE_2') expect(json_response['protected']).to be_falsey + expect(json_response['masked']).to be_falsey expect(json_response['variable_type']).to eq('file') end |