Commit 287746f4 authored by Sean McGivern's avatar Sean McGivern

Merge branch '8740-qa-add_credentials_to_netrc-needed-in-configure_identity' into 'master'

QA: Try to add .netrc credentials if needed

Closes #8740

See merge request gitlab-org/gitlab-ee!8721
parents f269d4a3 718e745f
...@@ -41,12 +41,6 @@ module QA ...@@ -41,12 +41,6 @@ module QA
def use_default_credentials def use_default_credentials
self.username, self.password = default_credentials self.username, self.password = default_credentials
# Write out .netrc as we need it for:
#
# git & git-lfs over HTTP
# git-lfs over SSH
add_credentials_to_netrc if add_credentials?
end end
def clone(opts = '') def clone(opts = '')
...@@ -146,6 +140,22 @@ module QA ...@@ -146,6 +140,22 @@ module QA
output[/git< version (\d+)/, 1] || 'unknown' output[/git< version (\d+)/, 1] || 'unknown'
end end
def try_add_credentials_to_netrc
return unless add_credentials?
return if netrc_already_contains_content?
# Despite libcurl supporting a custom .netrc location through the
# CURLOPT_NETRC_FILE environment variable, git does not support it :(
# Info: https://curl.haxx.se/libcurl/c/CURLOPT_NETRC_FILE.html
#
# This will create a .netrc in the correct working directory, which is
# a temporary directory created in .perform()
#
FileUtils.mkdir_p(tmp_home_dir)
File.open(netrc_file_path, 'a') { |file| file.puts(netrc_content) }
File.chmod(0600, netrc_file_path)
end
private private
attr_reader :uri, :username, :password, :known_hosts_file, attr_reader :uri, :username, :password, :known_hosts_file,
...@@ -159,6 +169,7 @@ module QA ...@@ -159,6 +169,7 @@ module QA
end end
def add_credentials? def add_credentials?
return false if !username || !password
return true unless ssh_key_set? return true unless ssh_key_set?
return true if ssh_key_set? && use_lfs? return true if ssh_key_set? && use_lfs?
...@@ -215,21 +226,6 @@ module QA ...@@ -215,21 +226,6 @@ module QA
File.exist?(netrc_file_path) && File.exist?(netrc_file_path) &&
File.readlines(netrc_file_path).grep(/^#{netrc_content}$/).any? File.readlines(netrc_file_path).grep(/^#{netrc_content}$/).any?
end end
def add_credentials_to_netrc
# Despite libcurl supporting a custom .netrc location through the
# CURLOPT_NETRC_FILE environment variable, git does not support it :(
# Info: https://curl.haxx.se/libcurl/c/CURLOPT_NETRC_FILE.html
#
# This will create a .netrc in the correct working directory, which is
# a temporary directory created in .perform()
#
return if netrc_already_contains_content?
FileUtils.mkdir_p(tmp_home_dir)
File.open(netrc_file_path, 'a') { |file| file.puts(netrc_content) }
File.chmod(0600, netrc_file_path)
end
end end
end end
end end
...@@ -67,6 +67,8 @@ module QA ...@@ -67,6 +67,8 @@ module QA
email = user.email email = user.email
end end
repository.try_add_credentials_to_netrc
@output += repository.clone @output += repository.clone
repository.configure_identity(username, email) repository.configure_identity(username, email)
......
...@@ -48,10 +48,7 @@ module QA ...@@ -48,10 +48,7 @@ module QA
end end
# Grab the HTTP URI for the secondary and store as 'location' # Grab the HTTP URI for the secondary and store as 'location'
location = Page::Project::Show.act do location = Page::Project::Show.act { repository_clone_http_location }
choose_repository_clone_http
repository_location
end
# Perform a git push over HTTP at the secondary # Perform a git push over HTTP at the secondary
push = Resource::Repository::Push.fabricate! do |push| push = Resource::Repository::Push.fabricate! do |push|
...@@ -127,10 +124,7 @@ module QA ...@@ -127,10 +124,7 @@ module QA
end end
# Grab the HTTP URI for the secondary and store as 'location' # Grab the HTTP URI for the secondary and store as 'location'
location = Page::Project::Show.act do location = Page::Project::Show.act { repository_clone_http_location }
choose_repository_clone_http
repository_location
end
# Perform a git push over HTTP at the secondary # Perform a git push over HTTP at the secondary
push = Resource::Repository::Push.fabricate! do |push| push = Resource::Repository::Push.fabricate! do |push|
......
...@@ -66,10 +66,7 @@ module QA ...@@ -66,10 +66,7 @@ module QA
end end
# Grab the SSH URI for the secondary and store as 'location' # Grab the SSH URI for the secondary and store as 'location'
location = Page::Project::Show.act do location = Page::Project::Show.act { repository_clone_ssh_location }
choose_repository_clone_ssh
repository_location
end
# Perform a git push over SSH at the secondary # Perform a git push over SSH at the secondary
push = Resource::Repository::Push.fabricate! do |push| push = Resource::Repository::Push.fabricate! do |push|
...@@ -158,10 +155,7 @@ module QA ...@@ -158,10 +155,7 @@ module QA
end end
# Grab the SSH URI for the secondary and store as 'location' # Grab the SSH URI for the secondary and store as 'location'
location = Page::Project::Show.act do location = Page::Project::Show.act { repository_clone_ssh_location }
choose_repository_clone_ssh
repository_location
end
# Perform a git push over SSH at the secondary # Perform a git push over SSH at the secondary
push = Resource::Repository::Push.fabricate! do |push| push = Resource::Repository::Push.fabricate! do |push|
......
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