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
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Jérome Perrin
gitlab-ce
Commits
46119566
Commit
46119566
authored
Nov 21, 2016
by
Tomasz Maczukin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add Gitlab::Ci::Build::Credentials module with build credentials abstraction
parent
e3fb0740
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
145 additions
and
25 deletions
+145
-25
app/models/ci/build.rb
app/models/ci/build.rb
+1
-8
lib/gitlab/ci/build/credentials.rb
lib/gitlab/ci/build/credentials.rb
+0
-16
lib/gitlab/ci/build/credentials/base.rb
lib/gitlab/ci/build/credentials/base.rb
+13
-0
lib/gitlab/ci/build/credentials/factory.rb
lib/gitlab/ci/build/credentials/factory.rb
+27
-0
lib/gitlab/ci/build/credentials/registry.rb
lib/gitlab/ci/build/credentials/registry.rb
+24
-0
spec/lib/gitlab/ci/build/credentials/factory_spec.rb
spec/lib/gitlab/ci/build/credentials/factory_spec.rb
+38
-0
spec/lib/gitlab/ci/build/credentials/registry_spec.rb
spec/lib/gitlab/ci/build/credentials/registry_spec.rb
+41
-0
spec/requests/ci/api/builds_spec.rb
spec/requests/ci/api/builds_spec.rb
+1
-1
No files found.
app/models/ci/build.rb
View file @
46119566
...
@@ -449,18 +449,11 @@ module Ci
...
@@ -449,18 +449,11 @@ module Ci
end
end
def
credentials
def
credentials
[
build_container_registry_credentials
].
compact
Gitlab
::
Ci
::
Build
::
Credentials
::
Factory
.
new
(
self
).
create!
end
end
private
private
def
build_container_registry_credentials
return
unless
Gitlab
.
config
.
registry
.
enabled
Gitlab
::
Ci
::
Build
::
Credentials
.
new
(
'docker-registry'
,
Gitlab
.
config
.
registry
.
host_port
,
'gitlab-ci-token'
,
token
)
end
def
update_artifacts_size
def
update_artifacts_size
self
.
artifacts_size
=
if
artifacts_file
.
exists?
self
.
artifacts_size
=
if
artifacts_file
.
exists?
artifacts_file
.
size
artifacts_file
.
size
...
...
lib/gitlab/ci/build/credentials.rb
deleted
100644 → 0
View file @
e3fb0740
module
Gitlab
module
Ci
module
Build
class
Credentials
attr_accessor
:type
,
:url
,
:username
,
:password
def
initialize
(
type
,
url
,
username
,
password
)
@type
=
type
@url
=
url
@username
=
username
@password
=
password
end
end
end
end
end
lib/gitlab/ci/build/credentials/base.rb
0 → 100644
View file @
46119566
module
Gitlab
module
Ci
module
Build
module
Credentials
class
Base
def
type
self
.
class
.
name
.
demodulize
.
underscore
end
end
end
end
end
end
lib/gitlab/ci/build/credentials/factory.rb
0 → 100644
View file @
46119566
module
Gitlab
module
Ci
module
Build
module
Credentials
class
Factory
def
initialize
(
build
)
@build
=
build
end
def
create!
credentials
.
select
(
&
:valid?
)
end
private
def
credentials
providers
.
map
{
|
provider
|
provider
.
new
(
@build
)
}
end
def
providers
[
Registry
]
end
end
end
end
end
end
lib/gitlab/ci/build/credentials/registry.rb
0 → 100644
View file @
46119566
module
Gitlab
module
Ci
module
Build
module
Credentials
class
Registry
<
Base
attr_reader
:username
,
:password
def
initialize
(
build
)
@username
=
'gitlab-ci-token'
@password
=
build
.
token
end
def
url
Gitlab
.
config
.
registry
.
host_port
end
def
valid?
Gitlab
.
config
.
registry
.
enabled
end
end
end
end
end
end
spec/lib/gitlab/ci/build/credentials/factory_spec.rb
0 → 100644
View file @
46119566
require
'spec_helper'
describe
Gitlab
::
Ci
::
Build
::
Credentials
::
Factory
do
let
(
:build
)
{
create
(
:ci_build
,
name:
'spinach'
,
stage:
'test'
,
stage_idx:
0
)
}
subject
{
Gitlab
::
Ci
::
Build
::
Credentials
::
Factory
.
new
(
build
).
create!
}
class
TestProvider
def
initialize
(
build
);
end
end
before
do
allow_any_instance_of
(
Gitlab
::
Ci
::
Build
::
Credentials
::
Factory
).
to
receive
(
:providers
).
and_return
([
TestProvider
])
end
context
'when provider is valid'
do
before
do
allow_any_instance_of
(
TestProvider
).
to
receive
(
:valid?
).
and_return
(
true
)
end
it
'generates an array of credentials objects'
do
is_expected
.
to
be_kind_of
(
Array
)
is_expected
.
not_to
be_empty
expect
(
subject
.
first
).
to
be_kind_of
(
TestProvider
)
end
end
context
'when provider is not valid'
do
before
do
allow_any_instance_of
(
TestProvider
).
to
receive
(
:valid?
).
and_return
(
false
)
end
it
'generates an array without specific credential object'
do
is_expected
.
to
be_kind_of
(
Array
)
is_expected
.
to
be_empty
end
end
end
spec/lib/gitlab/ci/build/credentials/registry_spec.rb
0 → 100644
View file @
46119566
require
'spec_helper'
describe
Gitlab
::
Ci
::
Build
::
Credentials
::
Registry
do
let
(
:build
)
{
create
(
:ci_build
,
name:
'spinach'
,
stage:
'test'
,
stage_idx:
0
)
}
let
(
:registry_url
)
{
'registry.example.com:5005'
}
subject
{
Gitlab
::
Ci
::
Build
::
Credentials
::
Registry
.
new
(
build
)
}
before
do
stub_container_registry_config
(
host_port:
registry_url
)
end
it
'contains valid DockerRegistry credentials'
do
expect
(
subject
).
to
be_kind_of
(
Gitlab
::
Ci
::
Build
::
Credentials
::
Registry
)
expect
(
subject
.
username
).
to
eq
'gitlab-ci-token'
expect
(
subject
.
password
).
to
eq
build
.
token
expect
(
subject
.
url
).
to
eq
registry_url
expect
(
subject
.
type
).
to
eq
'registry'
end
describe
'.valid?'
do
subject
{
Gitlab
::
Ci
::
Build
::
Credentials
::
Registry
.
new
(
build
).
valid?
}
context
'when registry is enabled'
do
before
do
stub_container_registry_config
(
enabled:
true
)
end
it
{
is_expected
.
to
be_truthy
}
end
context
'when registry is disabled'
do
before
do
stub_container_registry_config
(
enabled:
false
)
end
it
{
is_expected
.
to
be_falsey
}
end
end
end
spec/requests/ci/api/builds_spec.rb
View file @
46119566
...
@@ -60,7 +60,7 @@ describe Ci::API::API do
...
@@ -60,7 +60,7 @@ describe Ci::API::API do
context
'registry credentials'
do
context
'registry credentials'
do
let
(
:registry_credentials
)
do
let
(
:registry_credentials
)
do
{
'type'
=>
'
docker-
registry'
,
{
'type'
=>
'registry'
,
'url'
=>
'registry.example.com:5005'
,
'url'
=>
'registry.example.com:5005'
,
'username'
=>
'gitlab-ci-token'
,
'username'
=>
'gitlab-ci-token'
,
'password'
=>
build
.
token
}
'password'
=>
build
.
token
}
...
...
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