class Bosh::Workspace::GitCredentialsProvider
Attributes
credentials_file[R]
Public Class Methods
new(credentials_file)
click to toggle source
# File lib/bosh/workspace/git_credentials_provider.rb, line 5 def initialize(credentials_file) @credentials_file = credentials_file end
Public Instance Methods
callback()
click to toggle source
# File lib/bosh/workspace/git_credentials_provider.rb, line 9 def callback proc do |url, user, allowed_types| require_credentials_file_for!(url) validate_credentials! validate_url_protocol_support! credentials_for(url, user, allowed_types) end end
Private Instance Methods
credentials()
click to toggle source
# File lib/bosh/workspace/git_credentials_provider.rb, line 20 def credentials @credentials ||= Credentials.new(@credentials_file) end
credentials_for(url, user, allowed_types)
click to toggle source
# File lib/bosh/workspace/git_credentials_provider.rb, line 45 def credentials_for(url, user, allowed_types) if creds = credentials.find_by_url(url) load_git_credentials(creds, user, allowed_types) else say("Credential look up failed in: #{credentials_file}") err("No credentials found for: #{url}".make_red) end end
err(*args)
click to toggle source
Calls superclass method
# File lib/bosh/workspace/git_credentials_provider.rb, line 76 def err(*args) super end
load_git_credentials(credentials, user, allowed_types)
click to toggle source
# File lib/bosh/workspace/git_credentials_provider.rb, line 54 def load_git_credentials(credentials, user, allowed_types) case allowed_types when %i(ssh_key) key_file = temp_key_file(credentials[:private_key]) Rugged::Credentials::SshKey.new username: user, privatekey: key_file when %i(plaintext) Rugged::Credentials::UserPassword.new(credentials) end end
require_credentials_file_for!(url)
click to toggle source
# File lib/bosh/workspace/git_credentials_provider.rb, line 24 def require_credentials_file_for!(url) return if File.exist? @credentials_file say("Authentication is required for: #{url}".make_red) err("Credentials file does not exist: #{@credentials_file}".make_red) end
say(*args)
click to toggle source
Calls superclass method
# File lib/bosh/workspace/git_credentials_provider.rb, line 72 def say(*args) super end
temp_key_file(key)
click to toggle source
# File lib/bosh/workspace/git_credentials_provider.rb, line 64 def temp_key_file(key) file = Tempfile.new('sshkey') file.write key file.close File.chmod(0600, file.path) file.path end
validate_credentials!()
click to toggle source
# File lib/bosh/workspace/git_credentials_provider.rb, line 30 def validate_credentials! return if credentials.valid? say("Validation errors:".make_red) credentials.errors.each { |error| say("- #{error}") } err("'#{credentials_file}' is not valid".make_red) end
validate_url_protocol_support!()
click to toggle source
# File lib/bosh/workspace/git_credentials_provider.rb, line 37 def validate_url_protocol_support! credentials.url_protocols.each do |url, protocol| next if Rugged.features.include? protocol say("Please reinstall Rugged gem with #{protocol} support: http://git.io/veiyJ") err("Rugged requires #{protocol} support for: #{url}") end end