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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
9b781f73
Commit
9b781f73
authored
Jun 02, 2020
by
João Pereira
Committed by
Markus Koller
Jun 02, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add authentication to registry configure rake task
parent
62c5f15a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
2 deletions
+33
-2
lib/tasks/gitlab/container_registry.rake
lib/tasks/gitlab/container_registry.rake
+7
-1
spec/tasks/gitlab/container_registry_rake_spec.rb
spec/tasks/gitlab/container_registry_rake_spec.rb
+26
-1
No files found.
lib/tasks/gitlab/container_registry.rake
View file @
9b781f73
...
...
@@ -11,7 +11,13 @@ namespace :gitlab do
warn_user_is_not_gitlab
url
=
registry_config
.
api_url
client
=
ContainerRegistry
::
Client
.
new
(
url
)
# registry_info will query the /v2 route of the registry API. This route
# requires authentication, but not authorization (the response has no body,
# only headers that show the version of the registry). There is no
# associated user when running this rake, so we need to generate a valid
# JWT token with no access permissions to authenticate as a trusted client.
token
=
Auth
::
ContainerRegistryAuthenticationService
.
access_token
([],
[])
client
=
ContainerRegistry
::
Client
.
new
(
url
,
token:
token
)
info
=
client
.
registry_info
Gitlab
::
CurrentSettings
.
update!
(
...
...
spec/tasks/gitlab/container_registry_rake_spec.rb
View file @
9b781f73
...
...
@@ -4,6 +4,7 @@ require 'rake_helper'
describe
'gitlab:container_registry namespace rake tasks'
do
let_it_be
(
:application_settings
)
{
Gitlab
::
CurrentSettings
}
let_it_be
(
:api_url
)
{
'http://registry.gitlab'
}
before
:all
do
Rake
.
application
.
rake_require
'tasks/gitlab/container_registry'
...
...
@@ -11,7 +12,8 @@ describe 'gitlab:container_registry namespace rake tasks' do
describe
'configure'
do
before
do
stub_container_registry_config
(
enabled:
true
,
api_url:
'http://registry.gitlab'
)
stub_access_token
stub_container_registry_config
(
enabled:
true
,
api_url:
api_url
)
end
shared_examples
'invalid config'
do
...
...
@@ -37,6 +39,24 @@ describe 'gitlab:container_registry namespace rake tasks' do
it_behaves_like
'invalid config'
end
context
'when creating a registry client instance'
do
let
(
:token
)
{
'foo'
}
let
(
:client
)
{
ContainerRegistry
::
Client
.
new
(
api_url
,
token:
token
)
}
before
do
stub_registry_info
({})
end
it
'uses a token with no access permissions'
do
expect
(
Auth
::
ContainerRegistryAuthenticationService
)
.
to
receive
(
:access_token
).
with
([],
[]).
and_return
(
token
)
expect
(
ContainerRegistry
::
Client
)
.
to
receive
(
:new
).
with
(
api_url
,
token:
token
).
and_return
(
client
)
run_rake_task
(
'gitlab:container_registry:configure'
)
end
end
context
'when unabled to detect the container registry type'
do
it
'fails and raises an error message'
do
stub_registry_info
({})
...
...
@@ -79,6 +99,11 @@ describe 'gitlab:container_registry namespace rake tasks' do
end
end
def
stub_access_token
allow
(
Auth
::
ContainerRegistryAuthenticationService
)
.
to
receive
(
:access_token
).
with
([],
[]).
and_return
(
'foo'
)
end
def
stub_registry_info
(
output
)
allow_next_instance_of
(
ContainerRegistry
::
Client
)
do
|
client
|
allow
(
client
).
to
receive
(
:registry_info
).
and_return
(
output
)
...
...
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