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
Boxiang Sun
gitlab-ce
Commits
95e2c019
Commit
95e2c019
authored
Mar 22, 2017
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Clean code related to accessing registry from project
[ci skip]
parent
29c34267
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
9 additions
and
35 deletions
+9
-35
app/models/container_image.rb
app/models/container_image.rb
+4
-24
app/models/project.rb
app/models/project.rb
+5
-11
No files found.
app/models/container_image.rb
View file @
95e2c019
...
...
@@ -3,36 +3,16 @@ class ContainerImage < ActiveRecord::Base
belongs_to
:project
delegate
:container_registry
,
:container_registry_allowed_paths
,
:container_registry_path_with_namespace
,
to: :project
delegate
:container_registry
,
to: :project
delegate
:client
,
to: :container_registry
validates
:manifest
,
presence:
true
before_destroy
:delete_tags
before_validation
:update_token
,
on: :create
def
update_token
paths
=
container_registry_allowed_paths
<<
name_with_namespace
token
=
Auth
::
ContainerRegistryAuthenticationService
.
full_access_token
(
paths
)
client
.
update_token
(
token
)
end
def
parent
project
end
def
parent_changed?
project_id_changed?
end
# def path
# [container_registry.path, name_with_namespace].compact.join('/')
# end
def
name_with_namespace
[
container_registry_path_with_namespace
,
name
].
reject
(
&
:blank?
).
join
(
'/'
)
def
registry
# TODO, container registry with image access level
token
=
Auth
::
ContainerRegistryAuthenticationService
.
image_token
(
self
)
end
def
tag
(
tag
)
...
...
app/models/project.rb
View file @
95e2c019
...
...
@@ -405,29 +405,23 @@ class Project < ActiveRecord::Base
@repository
||=
Repository
.
new
(
path_with_namespace
,
self
)
end
def
container_registry_path_with_namespace
path_with_namespace
.
downcase
end
def
container_registry_allowed_paths
@container_registry_allowed_paths
||=
[
container_registry_path_with_namespace
]
+
container_images
.
map
{
|
i
|
i
.
name_with_namespace
}
end
def
container_registry
return
unless
Gitlab
.
config
.
registry
.
enabled
@container_registry
||=
begin
token
=
Auth
::
ContainerRegistryAuthenticationService
.
full_access_token
(
container_registry_allowed_paths
)
token
=
Auth
::
ContainerRegistryAuthenticationService
.
full_access_token
(
project
)
url
=
Gitlab
.
config
.
registry
.
api_url
host_port
=
Gitlab
.
config
.
registry
.
host_port
# TODO, move configuration vars into ContainerRegistry::Registry, clean
# this method up afterwards
ContainerRegistry
::
Registry
.
new
(
url
,
token:
token
,
path:
host_port
)
end
end
def
container_registry_url
if
Gitlab
.
config
.
registry
.
enabled
"
#{
Gitlab
.
config
.
registry
.
host_port
}
/
#{
container_registry_path_with_namespac
e
}
"
"
#{
Gitlab
.
config
.
registry
.
host_port
}
/
#{
path_with_namespace
.
downcas
e
}
"
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