summaryrefslogtreecommitdiff
path: root/lib/oxidized/hook
diff options
context:
space:
mode:
authorytti <saku@ytti.fi>2018-04-07 13:10:22 +0300
committerGitHub <noreply@github.com>2018-04-07 13:10:22 +0300
commit1fb037d4d6f4361ecd3c495a76d008c79b9ee712 (patch)
treeabb79c1e58dc14e04cedf136d0bf5bd5655456ae /lib/oxidized/hook
parent5eb0282dcd140860d6b158581e95d46cf73a06e8 (diff)
parentbb7b89f0db0c73650e0d1ac035d8441a0cb2e94f (diff)
Merge pull request #1257 from wk/githubrepo-username
refactor githubrepo credential handling (closes #1240)
Diffstat (limited to 'lib/oxidized/hook')
-rw-r--r--lib/oxidized/hook/githubrepo.rb25
1 files changed, 16 insertions, 9 deletions
diff --git a/lib/oxidized/hook/githubrepo.rb b/lib/oxidized/hook/githubrepo.rb
index f74b22a..4cae4e6 100644
--- a/lib/oxidized/hook/githubrepo.rb
+++ b/lib/oxidized/hook/githubrepo.rb
@@ -45,16 +45,23 @@ class GithubRepo < Oxidized::Hook
private
def credentials
- @credentials ||= if cfg.has_key?('username') && cfg.has_key?('password')
- log "Using https auth", :debug
- Rugged::Credentials::UserPassword.new(username: cfg.username, password: cfg.password)
- else
- if cfg.has_key?('publickey') && cfg.has_key?('privatekey')
- log "Using ssh auth with key", :debug
- Rugged::Credentials::SshKey.new(username: 'git', publickey: File.expand_path(cfg.publickey), privatekey: File.expand_path(cfg.privatekey), passphrase: ENV["OXIDIZED_SSH_PASSPHRASE"])
+ Proc.new do |url, username_from_url, allowed_types|
+
+ if cfg.has_key?('username')
+ git_user = cfg.username
+ else
+ git_user = username_from_url ? username_from_url : 'git'
+ end
+
+ if cfg.has_key?('password')
+ log "Authenticating using username and password as '#{git_user}'", :debug
+ Rugged::Credentials::UserPassword.new(username: git_user, password: cfg.password)
+ elsif cfg.has_key?('publickey') && cfg.has_key?('privatekey')
+ log "Authenticating using ssh keys as '#{git_user}'", :debug
+ Rugged::Credentials::SshKey.new(username: git_user, publickey: File.expand_path(cfg.publickey), privatekey: File.expand_path(cfg.privatekey), passphrase: ENV["OXIDIZED_SSH_PASSPHRASE"])
else
- log "Using ssh auth with agentforwarding", :debug
- Rugged::Credentials::SshKeyFromAgent.new(username: 'git')
+ log "Authenticating using ssh agent as '#{git_user}'", :debug
+ Rugged::Credentials::SshKeyFromAgent.new(username: git_user)
end
end
end