BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
2785bc4f
Commit
2785bc4f
authored
May 27, 2017
by
Lin Jen-Shin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Merge secret and protected vars to variables_for(ref)
Also introduce Ci::Variable#to_runner_variable to build up the hash for runner.
parent
9cc918a5
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
50 additions
and
31 deletions
+50
-31
build.rb
app/models/ci/build.rb
+1
-4
variable.rb
app/models/ci/variable.rb
+4
-0
project.rb
app/models/project.rb
+7
-14
build_spec.rb
spec/models/ci/build_spec.rb
+1
-1
variable_spec.rb
spec/models/ci/variable_spec.rb
+7
-0
project_spec.rb
spec/models/project_spec.rb
+30
-12
No files found.
app/models/ci/build.rb
View file @
2785bc4f
...
@@ -185,10 +185,7 @@ module Ci
...
@@ -185,10 +185,7 @@ module Ci
variables
+=
project
.
deployment_variables
if
has_environment?
variables
+=
project
.
deployment_variables
if
has_environment?
variables
+=
yaml_variables
variables
+=
yaml_variables
variables
+=
user_variables
variables
+=
user_variables
variables
+=
project
.
secret_variables
variables
+=
project
.
variables_for
(
ref
)
variables
+=
project
.
protected_variables
if
ProtectedBranch
.
protected?
(
project
,
ref
)
||
ProtectedTag
.
protected?
(
project
,
ref
)
variables
+=
trigger_request
.
user_variables
if
trigger_request
variables
+=
trigger_request
.
user_variables
if
trigger_request
variables
variables
end
end
...
...
app/models/ci/variable.rb
View file @
2785bc4f
...
@@ -18,5 +18,9 @@ module Ci
...
@@ -18,5 +18,9 @@ module Ci
insecure_mode:
true
,
insecure_mode:
true
,
key:
Gitlab
::
Application
.
secrets
.
db_key_base
,
key:
Gitlab
::
Application
.
secrets
.
db_key_base
,
algorithm:
'aes-256-cbc'
algorithm:
'aes-256-cbc'
def
to_runner_variable
{
key:
key
,
value:
value
,
public:
false
}
end
end
end
end
end
app/models/project.rb
View file @
2785bc4f
...
@@ -1256,16 +1256,15 @@ class Project < ActiveRecord::Base
...
@@ -1256,16 +1256,15 @@ class Project < ActiveRecord::Base
variables
variables
end
end
def
secret_variables
def
variables_for
(
ref
)
filtered_variables
=
variables
.
to_a
.
reject
(
&
:protected?
)
vars
=
if
ProtectedBranch
.
protected?
(
self
,
ref
)
||
ProtectedTag
.
protected?
(
self
,
ref
)
build_variables
(
filtered_variables
)
variables
.
to_a
else
variables
.
to_a
.
reject
(
&
:protected?
)
end
end
def
protected_variables
vars
.
map
(
&
:to_runner_variable
)
filtered_variables
=
variables
.
to_a
.
select
(
&
:protected?
)
build_variables
(
filtered_variables
)
end
end
def
deployment_variables
def
deployment_variables
...
@@ -1418,10 +1417,4 @@ class Project < ActiveRecord::Base
...
@@ -1418,10 +1417,4 @@ class Project < ActiveRecord::Base
raise
ex
raise
ex
end
end
def
build_variables
(
filtered_variables
)
filtered_variables
.
map
do
|
variable
|
{
key:
variable
.
key
,
value:
variable
.
value
,
public:
false
}
end
end
end
end
spec/models/ci/build_spec.rb
View file @
2785bc4f
...
@@ -1384,7 +1384,7 @@ describe Ci::Build, :models do
...
@@ -1384,7 +1384,7 @@ describe Ci::Build, :models do
allow
(
project
).
to
receive
(
:predefined_variables
)
{
[
'project'
]
}
allow
(
project
).
to
receive
(
:predefined_variables
)
{
[
'project'
]
}
allow
(
pipeline
).
to
receive
(
:predefined_variables
)
{
[
'pipeline'
]
}
allow
(
pipeline
).
to
receive
(
:predefined_variables
)
{
[
'pipeline'
]
}
allow
(
build
).
to
receive
(
:yaml_variables
)
{
[
'yaml'
]
}
allow
(
build
).
to
receive
(
:yaml_variables
)
{
[
'yaml'
]
}
allow
(
project
).
to
receive
(
:
secret_variables
)
{
[
'secret'
]
}
allow
(
project
).
to
receive
(
:
variables_for
).
with
(
build
.
ref
)
{
[
'secret'
]
}
end
end
it
{
is_expected
.
to
eq
(
%w[predefined project pipeline yaml secret]
)
}
it
{
is_expected
.
to
eq
(
%w[predefined project pipeline yaml secret]
)
}
...
...
spec/models/ci/variable_spec.rb
View file @
2785bc4f
...
@@ -36,4 +36,11 @@ describe Ci::Variable, models: true do
...
@@ -36,4 +36,11 @@ describe Ci::Variable, models: true do
to
raise_error
(
OpenSSL
::
Cipher
::
CipherError
,
'bad decrypt'
)
to
raise_error
(
OpenSSL
::
Cipher
::
CipherError
,
'bad decrypt'
)
end
end
end
end
describe
'#to_runner_variable'
do
it
'returns a hash for the runner'
do
expect
(
subject
.
to_runner_variable
)
.
to
eq
(
key:
subject
.
key
,
value:
subject
.
value
,
public:
false
)
end
end
end
end
spec/models/project_spec.rb
View file @
2785bc4f
...
@@ -1710,7 +1710,7 @@ describe Project, models: true do
...
@@ -1710,7 +1710,7 @@ describe Project, models: true do
end
end
end
end
describe
'
variables
'
do
describe
'
#variables_for
'
do
let
(
:project
)
{
create
(
:empty_project
)
}
let
(
:project
)
{
create
(
:empty_project
)
}
let!
(
:secret_variable
)
do
let!
(
:secret_variable
)
do
...
@@ -1721,22 +1721,40 @@ describe Project, models: true do
...
@@ -1721,22 +1721,40 @@ describe Project, models: true do
create
(
:ci_variable
,
:protected
,
value:
'protected'
,
project:
project
)
create
(
:ci_variable
,
:protected
,
value:
'protected'
,
project:
project
)
end
end
describe
'#secret_variables'
do
subject
{
project
.
variables_for
(
'ref'
)
}
shared_examples
'ref is protected'
do
it
'contains all the variables'
do
is_expected
.
to
contain_exactly
(
*
[
secret_variable
,
protected_variable
].
map
(
&
:to_runner_variable
))
end
end
context
'when the ref is not protected'
do
before
do
stub_application_setting
(
default_branch_protection:
Gitlab
::
Access
::
PROTECTION_NONE
)
end
it
'contains only the secret variables'
do
it
'contains only the secret variables'
do
expect
(
project
.
secret_variables
).
to
eq
(
is_expected
.
to
contain_exactly
(
secret_variable
.
to_runner_variable
)
[{
key:
secret_variable
.
key
,
value:
secret_variable
.
value
,
public:
false
}])
end
end
end
end
describe
'#protected_variables
'
do
context
'when the ref is a protected branch
'
do
it
'contains only the protected variables'
do
before
do
expect
(
project
.
protected_variables
).
to
eq
(
create
(
:protected_branch
,
name:
'ref'
,
project:
project
)
[{
key:
protected_variable
.
key
,
end
value:
protected_variable
.
value
,
public:
false
}])
it_behaves_like
'ref is protected'
end
end
context
'when the ref is a protected tag'
do
before
do
create
(
:protected_tag
,
name:
'ref'
,
project:
project
)
end
it_behaves_like
'ref is protected'
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