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
26968b70
Commit
26968b70
authored
May 15, 2020
by
Steve Abrams
Committed by
Sean McGivern
May 15, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Detect container registry vendor/version/features
Co-authored-by:
João Pereira
<
jpereira@gitlab.com
>
parent
f35bf8cb
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
68 additions
and
1 deletion
+68
-1
lib/container_registry/client.rb
lib/container_registry/client.rb
+17
-0
spec/lib/container_registry/client_spec.rb
spec/lib/container_registry/client_spec.rb
+51
-1
No files found.
lib/container_registry/client.rb
View file @
26968b70
...
...
@@ -13,6 +13,8 @@ module ContainerRegistry
DOCKER_DISTRIBUTION_MANIFEST_V2_TYPE
=
'application/vnd.docker.distribution.manifest.v2+json'
OCI_MANIFEST_V1_TYPE
=
'application/vnd.oci.image.manifest.v1+json'
CONTAINER_IMAGE_V1_TYPE
=
'application/vnd.docker.container.image.v1+json'
REGISTRY_VERSION_HEADER
=
'gitlab-container-registry-version'
REGISTRY_FEATURES_HEADER
=
'gitlab-container-registry-features'
ACCEPTED_TYPES
=
[
DOCKER_DISTRIBUTION_MANIFEST_V2_TYPE
,
OCI_MANIFEST_V1_TYPE
].
freeze
...
...
@@ -24,6 +26,21 @@ module ContainerRegistry
@options
=
options
end
def
registry_info
response
=
faraday
.
get
(
"/v2/"
)
return
{}
unless
response
&
.
success?
version
=
response
.
headers
[
REGISTRY_VERSION_HEADER
]
features
=
response
.
headers
.
fetch
(
REGISTRY_FEATURES_HEADER
,
''
)
{
version:
version
,
features:
features
.
split
(
','
).
map
(
&
:strip
),
vendor:
version
?
'gitlab'
:
'other'
}
end
def
repository_tags
(
name
)
response_body
faraday
.
get
(
"/v2/
#{
name
}
/tags/list"
)
end
...
...
spec/lib/container_registry/client_spec.rb
View file @
26968b70
...
...
@@ -85,7 +85,7 @@ describe ContainerRegistry::Client do
it
'follows 307 redirect for GET /v2/:name/blobs/:digest'
do
stub_request
(
:get
,
"http://container-registry/v2/group/test/blobs/sha256:0123456789012345"
)
.
with
(
headers:
blob_headers
)
.
to_return
(
status:
307
,
body:
""
,
headers:
{
Location
:
'http://redirected'
})
.
to_return
(
status:
307
,
body:
''
,
headers:
{
Location
:
'http://redirected'
})
# We should probably use hash_excluding here, but that requires an update to WebMock:
# https://github.com/bblimke/webmock/blob/master/lib/webmock/matchers/hash_excluding_matcher.rb
stub_request
(
:get
,
"http://redirected/"
)
...
...
@@ -238,4 +238,54 @@ describe ContainerRegistry::Client do
it
{
is_expected
.
to
be_falsey
}
end
end
def
stub_registry_info
(
headers:
{},
status:
200
)
stub_request
(
:get
,
'http://container-registry/v2/'
)
.
to_return
(
status:
status
,
body:
""
,
headers:
headers
)
end
describe
'#registry_info'
do
subject
{
client
.
registry_info
}
context
'when the check is successful'
do
context
'when using the GitLab container registry'
do
before
do
stub_registry_info
(
headers:
{
'GitLab-Container-Registry-Version'
=>
'2.9.1-gitlab'
,
'GitLab-Container-Registry-Features'
=>
'a,b,c'
})
end
it
'identifies the vendor as "gitlab"'
do
expect
(
subject
).
to
include
(
vendor:
'gitlab'
)
end
it
'identifies version and features'
do
expect
(
subject
).
to
include
(
version:
'2.9.1-gitlab'
,
features:
%w[a b c]
)
end
end
context
'when using a third-party container registry'
do
before
do
stub_registry_info
end
it
'identifies the vendor as "other"'
do
expect
(
subject
).
to
include
(
vendor:
'other'
)
end
it
'does not identify version or features'
do
expect
(
subject
).
to
include
(
version:
nil
,
features:
[])
end
end
end
context
'when the check is not successful'
do
it
'does not identify vendor, version or features'
do
stub_registry_info
(
status:
500
)
expect
(
subject
).
to
eq
({})
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