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

Instance Method Summary collapse

Instance Attribute Details

#regenerate_ssh_private_keyObject

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_methodObject


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

Returns:

  • (Boolean)

56
57
58
# File 'app/models/concerns/mirror_authentication.rb', line 56

def password_auth?
  auth_method == 'password'
end

#ssh_key_auth?Boolean

Returns:

  • (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_fingerprintsObject


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_byObject


64
65
66
# File 'app/models/concerns/mirror_authentication.rb', line 64

def ssh_known_hosts_verified_by
  @ssh_known_hosts_verified_by ||= ::User.find_by(id: ssh_known_hosts_verified_by_id)
end

#ssh_mirror_url?Boolean

Returns:

  • (Boolean)

60
61
62
# File 'app/models/concerns/mirror_authentication.rb', line 60

def ssh_mirror_url?
  url&.start_with?('ssh://')
end

#ssh_public_keyObject


78
79
80
81
82
83
# File 'app/models/concerns/mirror_authentication.rb', line 78

def ssh_public_key
  return if ssh_private_key.blank?

  comment = "[email protected]#{::Gitlab.config.gitlab.host}"
  SSHData::PrivateKey.parse(ssh_private_key).first.public_key.openssh(comment: comment)
end