Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
佳 邓
Gitlab4j Api
Commits
1084773a
Commit
1084773a
authored
Jun 16, 2019
by
Philippe Vienne
Committed by
Greg Messner
Jun 15, 2019
Browse files
Add support for CI masked variables (#388)
* Add support for masked variables #387 #388
parent
124d923a
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/main/java/org/gitlab4j/api/ProjectApi.java
View file @
1084773a
...
...
@@ -2626,7 +2626,7 @@ public class ProjectApi extends AbstractApi implements Constants {
* @throws GitLabApiException if any exception occurs during execution
*/
public
Variable
createVariable
(
Object
projectIdOrPath
,
String
key
,
String
value
,
Boolean
isProtected
)
throws
GitLabApiException
{
return
(
createVariable
(
projectIdOrPath
,
key
,
value
,
isProtected
,
null
));
return
(
createVariable
(
projectIdOrPath
,
key
,
value
,
isProtected
,
(
String
)
null
));
}
/**
...
...
@@ -2645,11 +2645,51 @@ public class ProjectApi extends AbstractApi implements Constants {
* @throws GitLabApiException if any exception occurs during execution
*/
public
Variable
createVariable
(
Object
projectIdOrPath
,
String
key
,
String
value
,
Boolean
isProtected
,
String
environmentScope
)
throws
GitLabApiException
{
return
createVariable
(
projectIdOrPath
,
key
,
value
,
isProtected
,
null
,
environmentScope
);
}
/**
* Create a new project variable.
*
* <p>NOTE: Setting the environmentScope is only available on GitLab EE.</p>
*
* <pre><code>GitLab Endpoint: POST /projects/:id/variables</code></pre>
*
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance, required
* @param key the key of a variable; must have no more than 255 characters; only A-Z, a-z, 0-9, and _ are allowed, required
* @param value the value for the variable, required
* @param isProtected whether the variable is protected, optional
* @param isMasked whether the variable is masked, optional
* @return a Variable instance with the newly created variable
* @throws GitLabApiException if any exception occurs during execution
*/
public
Variable
createVariable
(
Object
projectIdOrPath
,
String
key
,
String
value
,
Boolean
isProtected
,
Boolean
isMasked
)
throws
GitLabApiException
{
return
createVariable
(
projectIdOrPath
,
key
,
value
,
isProtected
,
isMasked
,
null
);
}
/**
* Create a new project variable.
*
* <p>NOTE: Setting the environmentScope is only available on GitLab EE.</p>
*
* <pre><code>GitLab Endpoint: POST /projects/:id/variables</code></pre>
*
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance, required
* @param key the key of a variable; must have no more than 255 characters; only A-Z, a-z, 0-9, and _ are allowed, required
* @param value the value for the variable, required
* @param isProtected whether the variable is protected, optional
* @param isMasked whether the variable is masked, optional
* @param environmentScope the environment_scope of the variable, optional
* @return a Variable instance with the newly created variable
* @throws GitLabApiException if any exception occurs during execution
*/
public
Variable
createVariable
(
Object
projectIdOrPath
,
String
key
,
String
value
,
Boolean
isProtected
,
Boolean
isMasked
,
String
environmentScope
)
throws
GitLabApiException
{
GitLabApiForm
formData
=
new
GitLabApiForm
()
.
withParam
(
"key"
,
key
,
true
)
.
withParam
(
"value"
,
value
,
true
)
.
withParam
(
"protected"
,
isProtected
)
.
withParam
(
"masked"
,
isMasked
)
.
withParam
(
"environment_scope"
,
environmentScope
);
Response
response
=
post
(
Response
.
Status
.
CREATED
,
formData
,
"projects"
,
getProjectIdOrPath
(
projectIdOrPath
),
"variables"
);
return
(
response
.
readEntity
(
Variable
.
class
));
...
...
@@ -2668,7 +2708,7 @@ public class ProjectApi extends AbstractApi implements Constants {
* @throws GitLabApiException if any exception occurs during execution
*/
public
Variable
updateVariable
(
Object
projectIdOrPath
,
String
key
,
String
value
,
Boolean
isProtected
)
throws
GitLabApiException
{
return
(
updateVariable
(
projectIdOrPath
,
key
,
value
,
isProtected
,
null
));
return
(
updateVariable
(
projectIdOrPath
,
key
,
value
,
isProtected
,
(
String
)
null
));
}
/**
...
...
@@ -2687,10 +2727,50 @@ public class ProjectApi extends AbstractApi implements Constants {
* @throws GitLabApiException if any exception occurs during execution
*/
public
Variable
updateVariable
(
Object
projectIdOrPath
,
String
key
,
String
value
,
Boolean
isProtected
,
String
environmentScope
)
throws
GitLabApiException
{
return
updateVariable
(
projectIdOrPath
,
key
,
value
,
isProtected
,
null
,
environmentScope
);
}
/**
* Update a project variable.
*
* <p>NOTE: Updating the environmentScope is only available on GitLab EE.</p>
*
* <pre><code>GitLab Endpoint: PUT /projects/:id/variables/:key</code></pre>
*
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance, required
* @param key the key of an existing variable, required
* @param value the value for the variable, required
* @param isProtected whether the variable is protected, optional
* @param isMasked whether the variable is masked, optional
* @return a Variable instance with the updated variable
* @throws GitLabApiException if any exception occurs during execution
*/
public
Variable
updateVariable
(
Object
projectIdOrPath
,
String
key
,
String
value
,
Boolean
isProtected
,
Boolean
isMasked
)
throws
GitLabApiException
{
return
updateVariable
(
projectIdOrPath
,
key
,
value
,
isProtected
,
isMasked
,
null
);
}
/**
* Update a project variable.
*
* <p>NOTE: Updating the environmentScope is only available on GitLab EE.</p>
*
* <pre><code>GitLab Endpoint: PUT /projects/:id/variables/:key</code></pre>
*
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance, required
* @param key the key of an existing variable, required
* @param value the value for the variable, required
* @param isProtected whether the variable is protected, optional
* @param isMasked whether the variable is masked, optional
* @param environmentScope the environment_scope of the variable, optional.
* @return a Variable instance with the updated variable
* @throws GitLabApiException if any exception occurs during execution
*/
public
Variable
updateVariable
(
Object
projectIdOrPath
,
String
key
,
String
value
,
Boolean
isProtected
,
Boolean
isMasked
,
String
environmentScope
)
throws
GitLabApiException
{
GitLabApiForm
formData
=
new
GitLabApiForm
()
.
withParam
(
"value"
,
value
,
true
)
.
withParam
(
"protected"
,
isProtected
)
.
withParam
(
"masked"
,
isMasked
)
.
withParam
(
"environment_scope"
,
environmentScope
);
Response
response
=
putWithFormData
(
Response
.
Status
.
OK
,
formData
,
"projects"
,
getProjectIdOrPath
(
projectIdOrPath
),
"variables"
,
key
);
return
(
response
.
readEntity
(
Variable
.
class
));
...
...
src/main/java/org/gitlab4j/api/models/Variable.java
View file @
1084773a
...
...
@@ -14,6 +14,8 @@ public class Variable {
private
String
value
;
@JsonProperty
(
"protected"
)
private
Boolean
isProtected
;
@JsonProperty
(
"masked"
)
private
Boolean
isMasked
;
private
String
environmentScope
;
public
Variable
()
{
...
...
@@ -48,6 +50,14 @@ public class Variable {
this
.
isProtected
=
isProtected
;
}
public
Boolean
getMasked
()
{
return
isMasked
;
}
public
void
setMasked
(
Boolean
masked
)
{
isMasked
=
masked
;
}
public
String
getEnvironmentScope
()
{
return
environmentScope
;
}
...
...
src/test/java/org/gitlab4j/api/TestProjectApi.java
View file @
1084773a
...
...
@@ -672,7 +672,7 @@ public class TestProjectApi extends AbstractIntegrationTest {
String
key
=
TEST_VARIABLE_KEY_PREFIX
+
HelperUtils
.
getRandomInt
()
+
"_"
+
HelperUtils
.
getRandomInt
();
String
value
=
"TEST_VARIABLE_VALUE_"
+
HelperUtils
.
getRandomInt
()
+
"_"
+
HelperUtils
.
getRandomInt
();
Variable
variable
=
gitLabApi
.
getProjectApi
().
createVariable
(
testProject
,
key
,
value
,
null
,
null
);
Variable
variable
=
gitLabApi
.
getProjectApi
().
createVariable
(
testProject
,
key
,
value
,
null
,
null
,
null
);
assertNotNull
(
variable
);
assertEquals
(
key
,
variable
.
getKey
());
...
...
@@ -696,6 +696,15 @@ public class TestProjectApi extends AbstractIntegrationTest {
assertEquals
(
"NONE"
,
variable
.
getValue
());
assertTrue
(
variable
.
getProtected
());
gitLabApi
.
getProjectApi
().
updateVariable
(
testProject
,
key
,
value
,
true
,
true
,
"DEV"
);
variable
=
gitLabApi
.
getProjectApi
().
getVariable
(
testProject
,
key
);
assertNotNull
(
variable
);
assertEquals
(
key
,
variable
.
getKey
());
assertEquals
(
"NONE"
,
variable
.
getValue
());
assertTrue
(
variable
.
getMasked
());
assertTrue
(
variable
.
getProtected
());
gitLabApi
.
getProjectApi
().
deleteVariable
(
testProject
,
key
);
variables
=
gitLabApi
.
getProjectApi
().
getVariablesStream
(
testProject
);
assertNotNull
(
variables
);
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment