Class: Luban::Deployment::Application::Authenticator
- Inherits:
-
Worker::Base
- Object
- Worker::Base
- Luban::Deployment::Application::Authenticator
show all
- Defined in:
- lib/luban/deployment/cli/application/authenticator.rb
Constant Summary
Parameters::General::DefaultLubanRootPath
Helpers::Utils::LogLevels
Instance Attribute Summary
Attributes inherited from Worker::Base
#task
#backend
#config
Instance Method Summary
collapse
#dry_run?, #env_name, #force?, #initialize, #linux?, #osx?, #run, #target_full_name, #target_major_version, #target_name, #target_patch_level, #target_version
#parameter
included
#assure, #assure_dirs, #assure_symlink, #capture, #check_pass?, #chmod, #cp, #directory?, #file?, #hardware_name, #host, #hostname, #ln, #match?, #md5_for_file, #md5_matched?, #method_missing, #mkdir, #mv, #now, #os_name, #os_release, #readlink, #render_template, #revision_match?, #rm, #rmdir, #sudo, #symlink?, #upload_by_template, #url_exists?, #user_home
#ask, #default_templates_paths, #fetch, #find_template_file, #load_configuration_file, #primary, #release_roles, #role, #roles, #server, #set, #set_default, #syntax_error?
Instance Method Details
#app ⇒ Object
50
|
# File 'lib/luban/deployment/cli/application/authenticator.rb', line 50
def app; task.opts.app; end
|
#authen_keys_path ⇒ Object
9
10
11
|
# File 'lib/luban/deployment/cli/application/authenticator.rb', line 9
def authen_keys_path
@authen_keys_path ||= Pathname.new(user_home).join('.ssh')
end
|
#authorized_keys_file_path ⇒ Object
21
22
23
|
# File 'lib/luban/deployment/cli/application/authenticator.rb', line 21
def authorized_keys_file_path
@authorized_keys_file_path ||= authen_keys_path.join('authorized_keys')
end
|
#generate_key_pairs ⇒ Object
42
43
44
|
# File 'lib/luban/deployment/cli/application/authenticator.rb', line 42
def generate_key_pairs
execute(keygen_command) unless key_pairs_generated?
end
|
#get_public_key ⇒ Object
37
38
39
40
|
# File 'lib/luban/deployment/cli/application/authenticator.rb', line 37
def get_public_key
generate_key_pairs
capture(keyget_command)
end
|
#key_pairs_generated? ⇒ Boolean
46
47
48
|
# File 'lib/luban/deployment/cli/application/authenticator.rb', line 46
def key_pairs_generated?
file?(private_key_file_path) and file?(public_key_file_path)
end
|
#keygen_command ⇒ Object
33
34
35
|
# File 'lib/luban/deployment/cli/application/authenticator.rb', line 33
def keygen_command
@keygen_command ||= "ssh-keygen -t #{authen_key_type} -f #{private_key_file_path} -N '' 2>&1"
end
|
#keyget_command ⇒ Object
29
30
31
|
# File 'lib/luban/deployment/cli/application/authenticator.rb', line 29
def keyget_command
@keyget_command ||= "cat #{public_key_file_path} 2>&1"
end
|
#private_key_file_name ⇒ Object
5
6
7
|
# File 'lib/luban/deployment/cli/application/authenticator.rb', line 5
def private_key_file_name
@private_key_file_name ||= "id_#{authen_key_type}"
end
|
#private_key_file_path ⇒ Object
13
14
15
|
# File 'lib/luban/deployment/cli/application/authenticator.rb', line 13
def private_key_file_path
@private_key_file ||= authen_keys_path.join(private_key_file_name)
end
|
#promptless_authen ⇒ Object
52
53
54
55
56
57
58
59
60
61
62
|
# File 'lib/luban/deployment/cli/application/authenticator.rb', line 52
def promptless_authen
if promptless_authen_enabled?
update_result "Skipped! Promptless authentication has been enabled ALREADY.",
status: :skipped, public_key: public_key
else
setup_password_authen
generate_key_pairs
add_authorized_keys
update_result "Promptless authentication is enabled.", public_key: public_key
end
end
|
#promptless_authen_enabled? ⇒ Boolean
64
65
66
67
68
69
70
71
72
73
74
75
76
|
# File 'lib/luban/deployment/cli/application/authenticator.rb', line 64
def promptless_authen_enabled?
origin_auth_methods = host.ssh_options[:auth_methods]
host.ssh_options[:auth_methods] = %w(publickey)
capture('echo ok') == 'ok'
rescue Net::SSH::AuthenticationFailed
false
ensure
if origin_auth_methods.nil?
host.ssh_options.delete(:auth_methods)
else
host.ssh_options[:auth_methods] = origin_auth_methods
end
end
|
#public_key ⇒ Object
25
26
27
|
# File 'lib/luban/deployment/cli/application/authenticator.rb', line 25
def public_key
@public_key ||= get_public_key
end
|
#public_key_file_path ⇒ Object
17
18
19
|
# File 'lib/luban/deployment/cli/application/authenticator.rb', line 17
def public_key_file_path
@public_key_file_path ||= authen_keys_path.join("#{private_key_file_name}.pub")
end
|