Module: MirrorAuthentication
- Extended by:
- ActiveSupport::Concern
- Included in:
- RemoteMirror
- Defined in:
- app/models/concerns/mirror_authentication.rb
Overview
Mirroring may use password or SSH public-key authentication. This concern implements support for persisting the necessary data in a ‘credentials` serialized attribute. It also needs an `url` method to be defined
Instance Attribute Summary collapse
-
#regenerate_ssh_private_key ⇒ Object
Returns the value of attribute regenerate_ssh_private_key.
Instance Method Summary collapse
- #auth_method ⇒ Object
- #generate_ssh_private_key! ⇒ Object
- #password_auth? ⇒ Boolean
- #ssh_key_auth? ⇒ Boolean
- #ssh_known_hosts_fingerprints ⇒ Object
- #ssh_known_hosts_verified_by ⇒ Object
- #ssh_mirror_url? ⇒ Boolean
- #ssh_public_key ⇒ Object
Instance Attribute Details
#regenerate_ssh_private_key ⇒ Object
Returns the value of attribute regenerate_ssh_private_key.
50 51 52 |
# File 'app/models/concerns/mirror_authentication.rb', line 50 def regenerate_ssh_private_key @regenerate_ssh_private_key end |
Instance Method Details
#auth_method ⇒ Object
72 73 74 75 76 |
# File 'app/models/concerns/mirror_authentication.rb', line 72 def auth_method auth_method = credentials.fetch(:auth_method, nil) if credentials.present? auth_method.presence || 'password' end |
#generate_ssh_private_key! ⇒ Object
85 86 87 |
# File 'app/models/concerns/mirror_authentication.rb', line 85 def generate_ssh_private_key! self.ssh_private_key = SSHData::PrivateKey::RSA.generate(4096).openssl.to_pem end |
#password_auth? ⇒ Boolean
56 57 58 |
# File 'app/models/concerns/mirror_authentication.rb', line 56 def password_auth? auth_method == 'password' end |
#ssh_key_auth? ⇒ Boolean
52 53 54 |
# File 'app/models/concerns/mirror_authentication.rb', line 52 def ssh_key_auth? ssh_mirror_url? && auth_method == 'ssh_public_key' end |
#ssh_known_hosts_fingerprints ⇒ Object
68 69 70 |
# File 'app/models/concerns/mirror_authentication.rb', line 68 def ssh_known_hosts_fingerprints ::SshHostKey.fingerprint_host_keys(ssh_known_hosts) end |
#ssh_known_hosts_verified_by ⇒ Object
64 65 66 |
# File 'app/models/concerns/mirror_authentication.rb', line 64 def ssh_known_hosts_verified_by @ssh_known_hosts_verified_by ||= user_by_ssh_known_hosts_verified_by_id end |
#ssh_mirror_url? ⇒ Boolean
60 61 62 |
# File 'app/models/concerns/mirror_authentication.rb', line 60 def ssh_mirror_url? url&.start_with?('ssh://') end |