Unverified Commit e3fb0740 authored by Tomasz Maczukin's avatar Tomasz Maczukin
Browse files

Send credentials array with build data

parent 58189099668a
......@@ -448,8 +448,19 @@ def user_variables
]
end
def credentials
[build_container_registry_credentials].compact
end
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
self.artifacts_size = if artifacts_file.exists?
artifacts_file.size
......
---
title: Send registry_url with build data to GitLab Runner
title: Send credentials (currently for registry only) with build data to GitLab Runner
merge_request: 7474
author:
......@@ -32,6 +32,10 @@ class Build < Grape::Entity
expose :artifacts_file, using: ArtifactFile, if: ->(build, _) { build.artifacts? }
end
class BuildCredentials < Grape::Entity
expose :type, :url, :username, :password
end
class BuildDetails < Build
expose :commands
expose :repo_url
......@@ -51,9 +55,7 @@ class BuildDetails < Build
expose :variables
expose :depends_on_builds, using: Build
expose :registry_url, if: ->(_, _) { Gitlab.config.registry.enabled } do |_|
Gitlab.config.registry.host_port
end
expose :credentials, using: BuildCredentials
end
class Runner < Grape::Entity
......
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
......@@ -58,28 +58,38 @@
expect { register_builds }.to change { runner.reload.contacted_at }
end
context 'when registry is enabled' do
before do
stub_container_registry_config(enabled: true, host_port: 'registry.example.com:5005')
context 'registry credentials' do
let(:registry_credentials) do
{ 'type' => 'docker-registry',
'url' => 'registry.example.com:5005',
'username' => 'gitlab-ci-token',
'password' => build.token }
end
it 'sends registry_url key' do
register_builds info: { platform: :darwin }
context 'when registry is enabled' do
before do
stub_container_registry_config(enabled: true, host_port: 'registry.example.com:5005')
end
expect(json_response).to have_key('registry_url')
expect(json_response['registry_url']).to eq("registry.example.com:5005")
end
end
it 'sends registry credentials key' do
register_builds info: { platform: :darwin }
context 'when registry is disabled' do
before do
stub_container_registry_config(enabled: false, host_port: 'registry.example.com:5005')
expect(json_response).to have_key('credentials')
expect(json_response['credentials']).to include(registry_credentials)
end
end
it 'does not send registry_url key' do
register_builds info: { platform: :darwin }
context 'when registry is disabled' do
before do
stub_container_registry_config(enabled: false, host_port: 'registry.example.com:5005')
end
expect(json_response).not_to have_key('registry_url')
it 'does not send registry credentials' do
register_builds info: { platform: :darwin }
expect(json_response).to have_key('credentials')
expect(json_response['credentials']).not_to include(registry_credentials)
end
end
end
end
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment