Class: R10K::Git::Rugged::Credentials Private
- Inherits:
-
Object
- Object
- R10K::Git::Rugged::Credentials
- Includes:
- Logging
- Defined in:
- lib/r10k/git/rugged/credentials.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Generate credentials for secured remote connections.
Constant Summary
Constants included from Logging
Instance Method Summary collapse
- #call(url, username_from_url, allowed_types) ⇒ Object private
- #get_default_credentials(url, username_from_url) ⇒ Object private
- #get_git_username(url, username_from_url) ⇒ Object private
- #get_plaintext_credentials(url, username_from_url) ⇒ Object private
- #get_ssh_key_credentials(url, username_from_url) ⇒ Object private
-
#initialize(repository) ⇒ Credentials
constructor
private
A new instance of Credentials.
Methods included from Logging
debug_formatter, default_formatter, default_outputter, #logger, #logger_name, parse_level
Constructor Details
#initialize(repository) ⇒ Credentials
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Credentials.
13 14 15 |
# File 'lib/r10k/git/rugged/credentials.rb', line 13 def initialize(repository) @repository = repository end |
Instance Method Details
#call(url, username_from_url, allowed_types) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
17 18 19 20 21 22 23 24 25 |
# File 'lib/r10k/git/rugged/credentials.rb', line 17 def call(url, username_from_url, allowed_types) if allowed_types.include?(:ssh_key) get_ssh_key_credentials(url, username_from_url) elsif allowed_types.include?(:plaintext) get_plaintext_credentials(url, username_from_url) else get_default_credentials(url, username_from_url) end end |
#get_default_credentials(url, username_from_url) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
44 45 46 |
# File 'lib/r10k/git/rugged/credentials.rb', line 44 def get_default_credentials(url, username_from_url) Rugged::Credentials::Default.new end |
#get_git_username(url, username_from_url) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/r10k/git/rugged/credentials.rb', line 48 def get_git_username(url, username_from_url) git_user = R10K::Git.settings[:username] user = nil if !username_from_url.nil? user = username_from_url logger.debug2 "URL #{url.inspect} includes the username #{username_from_url}, using that user for authentication." elsif git_user user = git_user logger.debug2 "URL #{url.inspect} did not specify a user, using #{user.inspect} from configuration" else user = Etc.getlogin logger.debug2 "URL #{url.inspect} did not specify a user, using current user #{user.inspect}" end user end |
#get_plaintext_credentials(url, username_from_url) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
38 39 40 41 42 |
# File 'lib/r10k/git/rugged/credentials.rb', line 38 def get_plaintext_credentials(url, username_from_url) user = get_git_username(url, username_from_url) password = URI.parse(url).password || '' Rugged::Credentials::UserPassword.new(username: user, password: password) end |
#get_ssh_key_credentials(url, username_from_url) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/r10k/git/rugged/credentials.rb', line 27 def get_ssh_key_credentials(url, username_from_url) user = get_git_username(url, username_from_url) private_key = R10K::Git.settings[:private_key] if private_key.nil? raise R10K::Git::GitError.new("Git remote #{url.inspect} uses the SSH protocol but no private key was given", :git_dir => @repository.path.to_s) end Rugged::Credentials::SshKey.new(:username => user, :privatekey => private_key) end |