diff options
author | Kamil Trzcinski <ayufan@ayufan.eu> | 2016-05-09 22:34:24 +0300 |
---|---|---|
committer | Kamil Trzcinski <ayufan@ayufan.eu> | 2016-05-09 22:34:24 +0300 |
commit | b5043d5d33ed2a213889dfe52c819addd0d847ef (patch) | |
tree | 77ddb63c77b7b24b14cbafe040536f2e1efd468f /lib/container_registry | |
parent | 60869580023da553613ee18bcdbc8682ebdde2cf (diff) | |
download | gitlab-ce-b5043d5d33ed2a213889dfe52c819addd0d847ef.tar.gz |
Fix review comments
Diffstat (limited to 'lib/container_registry')
-rw-r--r-- | lib/container_registry/blob.rb | 1 | ||||
-rw-r--r-- | lib/container_registry/client.rb | 33 |
2 files changed, 19 insertions, 15 deletions
diff --git a/lib/container_registry/blob.rb b/lib/container_registry/blob.rb index 16e3f853418..d59792a383e 100644 --- a/lib/container_registry/blob.rb +++ b/lib/container_registry/blob.rb @@ -44,7 +44,6 @@ module ContainerRegistry end def data - return @data if defined?(@data) @data ||= client.blob(repository.name, digest, type) end diff --git a/lib/container_registry/client.rb b/lib/container_registry/client.rb index b823428344b..41d9cb46ae9 100644 --- a/lib/container_registry/client.rb +++ b/lib/container_registry/client.rb @@ -9,20 +9,8 @@ module ContainerRegistry def initialize(base_uri, options = {}) @base_uri = base_uri - @faraday = Faraday.new(@base_uri) do |builder| - builder.request :json - builder.headers['Accept'] = MANIFEST_VERSION - - builder.response :json, :content_type => /\bjson$/ - builder.response :json, :content_type => 'application/vnd.docker.distribution.manifest.v1+prettyjws' - - if options[:user] && options[:password] - builder.request(:basic_auth, options[:user].to_s, options[:password].to_s) - elsif options[:token] - builder.request(:authorization, :bearer, options[:token].to_s) - end - - builder.adapter :net_http + @faraday = Faraday.new(@base_uri) do |conn| + initialize_connection(conn) end end @@ -60,5 +48,22 @@ module ContainerRegistry def delete_blob(name, digest) @faraday.delete("/v2/#{name}/blobs/#{digest}").success? end + + private + + def initialize_connection(conn) + conn.request :json + conn.headers['Accept'] = MANIFEST_VERSION + + conn.response :json, :content_type => /\bjson$/ + + if options[:user] && options[:password] + conn.request(:basic_auth, options[:user].to_s, options[:password].to_s) + elsif options[:token] + conn.request(:authorization, :bearer, options[:token].to_s) + end + + conn.adapter :net_http + end end end |