Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
gitlab-ce
Commits
ea4777ff
Commit
ea4777ff
authored
Dec 31, 2015
by
Tomasz Maczukin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add features for list and show details of variables in API
parent
2c1f8e2d
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
150 additions
and
0 deletions
+150
-0
app/models/ci/variable.rb
app/models/ci/variable.rb
+1
-0
lib/api/api.rb
lib/api/api.rb
+2
-0
lib/api/entities.rb
lib/api/entities.rb
+4
-0
lib/api/variables.rb
lib/api/variables.rb
+43
-0
spec/factories/ci/variables.rb
spec/factories/ci/variables.rb
+25
-0
spec/requests/api/variables_spec.rb
spec/requests/api/variables_spec.rb
+75
-0
No files found.
app/models/ci/variable.rb
View file @
ea4777ff
...
@@ -9,6 +9,7 @@
...
@@ -9,6 +9,7 @@
# encrypted_value :text
# encrypted_value :text
# encrypted_value_salt :string(255)
# encrypted_value_salt :string(255)
# encrypted_value_iv :string(255)
# encrypted_value_iv :string(255)
# gl_project_id :integer
#
#
module
Ci
module
Ci
...
...
lib/api/api.rb
View file @
ea4777ff
...
@@ -54,5 +54,7 @@ module API
...
@@ -54,5 +54,7 @@ module API
mount
Keys
mount
Keys
mount
Tags
mount
Tags
mount
Triggers
mount
Triggers
mount
Variables
end
end
end
end
lib/api/entities.rb
View file @
ea4777ff
...
@@ -365,5 +365,9 @@ module API
...
@@ -365,5 +365,9 @@ module API
class
TriggerRequest
<
Grape
::
Entity
class
TriggerRequest
<
Grape
::
Entity
expose
:id
,
:variables
expose
:id
,
:variables
end
end
class
Variable
<
Grape
::
Entity
expose
:id
,
:key
,
:value
end
end
end
end
end
lib/api/variables.rb
0 → 100644
View file @
ea4777ff
module
API
# Projects variables API
class
Variables
<
Grape
::
API
before
{
authenticate!
}
before
{
authorize_admin_project
}
resource
:projects
do
# Get project variables
#
# Parameters:
# id (required) - The ID of a project
# page (optional) - The page number for pagination
# per_page (optional) - The value of items per page to show
# Example Request:
# GET /projects/:id/variables
get
':id/variables'
do
variables
=
user_project
.
variables
present
paginate
(
variables
),
with:
Entities
::
Variable
end
# Get specifica bariable of a project
#
# Parameters:
# id (required) - The ID of a project
# variable_id (required) - The ID OR `key` of variable to show; if variable_id contains only digits it's treated
# as ID other ways it's treated as `key`
# Example Reuest:
# GET /projects/:id/variables/:variable_id
get
':id/variables/:variable_id'
do
variable_id
=
params
[
:variable_id
]
variables
=
user_project
.
variables
variables
=
if
variable_id
.
match
(
/^\d+$/
)
variables
.
where
(
id:
variable_id
.
to_i
)
else
variables
.
where
(
key:
variable_id
)
end
present
variables
.
first
,
with:
Entities
::
Variable
end
end
end
end
spec/factories/ci/variables.rb
0 → 100644
View file @
ea4777ff
# == Schema Information
#
# Table name: ci_variables
#
# id :integer not null, primary key
# project_id :integer not null
# key :string(255)
# value :text
# encrypted_value :text
# encrypted_value_salt :string(255)
# encrypted_value_iv :string(255)
# gl_project_id :integer
#
# Read about factories at https://github.com/thoughtbot/factory_girl
FactoryGirl
.
define
do
factory
:ci_variable
,
class:
Ci
::
Variable
do
id
1
key
'TEST_VARIABLE_1'
value
'VALUE_1'
project
factory: :empty_project
end
end
spec/requests/api/variables_spec.rb
0 → 100644
View file @
ea4777ff
require
'spec_helper'
describe
API
::
API
,
api:
true
do
include
ApiHelpers
let
(
:user
)
{
create
(
:user
)
}
let
(
:user2
)
{
create
(
:user
)
}
let!
(
:project
)
{
create
(
:project
,
creator_id:
user
.
id
)
}
let!
(
:master
)
{
create
(
:project_member
,
user:
user
,
project:
project
,
access_level:
ProjectMember
::
MASTER
)
}
let!
(
:developer
)
{
create
(
:project_member
,
user:
user2
,
project:
project
,
access_level:
ProjectMember
::
DEVELOPER
)
}
let!
(
:variable
)
{
create
(
:ci_variable
,
project:
project
)
}
describe
'GET /projects/:id/variables'
do
context
'authorized user with proper permissions'
do
it
'should return project variables'
do
get
api
(
"/projects/
#{
project
.
id
}
/variables"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
json_response
).
to
be_a
(
Array
)
end
end
context
'authorized user with invalid permissions'
do
it
'should not return project variables'
do
get
api
(
"/projects/
#{
project
.
id
}
/variables"
,
user2
)
expect
(
response
.
status
).
to
eq
(
403
)
end
end
context
'unauthorized user'
do
it
'should not return project variables'
do
get
api
(
"/projects/
#{
project
.
id
}
/variables"
)
expect
(
response
.
status
).
to
eq
(
401
)
end
end
end
describe
'GET /projects/:id/variables/:variable_id'
do
context
'authorized user with proper permissions'
do
it
'should return project variable details when ID is used as :variable_id'
do
get
api
(
"/projects/
#{
project
.
id
}
/variables/1"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
json_response
[
'key'
]).
to
eq
(
'TEST_VARIABLE_1'
)
expect
(
json_response
[
'value'
]).
to
eq
(
'VALUE_1'
)
end
it
'should return project variable details when `key` is used as :variable_id'
do
get
api
(
"/projects/
#{
project
.
id
}
/variables/TEST_VARIABLE_1"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
json_response
[
'id'
]).
to
eq
(
1
)
expect
(
json_response
[
'value'
]).
to
eq
(
'VALUE_1'
)
end
end
context
'authorized user with invalid permissions'
do
it
'should not return project variable details'
do
get
api
(
"/projects/
#{
project
.
id
}
/variables/1"
,
user2
)
expect
(
response
.
status
).
to
eq
(
403
)
end
end
context
'unauthorized user'
do
it
'should not return project variable details'
do
get
api
(
"/projects/
#{
project
.
id
}
/variables/1"
)
expect
(
response
.
status
).
to
eq
(
401
)
end
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a 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