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::Application::DefaultLogrotateInterval, Parameters::Application::DefaultLogrotateMaxAge
Parameters::General::DefaultLubanRootPath
Helpers::Utils::LogLevels
Instance Attribute Summary
Attributes inherited from Worker::Base
#task
#backend
#config
Instance Method Summary
collapse
#dry_run?, #force?, #initialize, #linux?, #method_missing, #osx?, #packages, #run, #target_full_name, #target_major_version, #target_name, #target_patch_level, #target_version
#env_name, #logrotate_count, #monitor_itself?, #monitorable?
#parameter
#monitor_defined?, #process_monitor_via
included
#assure, #assure_dirs, #assure_symlink, #capture, #check_pass?, #chmod, #cp, #directory?, #exists?, #file?, #hardware_name, #host, #hostname, #ln, #match?, #md5_for, #md5_for_dir, #md5_for_file, #md5_matched?, #mkdir, #mv, #now, #os_name, #os_release, #readlink, #render_template, #revision_match?, #rm, #rmdir, #sudo, #symlink?, #touch, #truncate, #upload_by_template, #url_exists?, #user_home
#ask, #fetch, #find_template_file, #load_configuration_file, #primary, #release_roles, #role, #roles, #server, #set, #set_default, #syntax_error?
Instance Method Details
#app ⇒ Object
56
|
# File 'lib/luban/deployment/cli/application/authenticator.rb', line 56
def app; task.opts.app; end
|
#authen_keys_path ⇒ Object
15
16
17
|
# File 'lib/luban/deployment/cli/application/authenticator.rb', line 15
def authen_keys_path
@authen_keys_path ||= Pathname.new(user_home).join('.ssh')
end
|
#authorized_keys_file_path ⇒ Object
27
28
29
|
# File 'lib/luban/deployment/cli/application/authenticator.rb', line 27
def authorized_keys_file_path
@authorized_keys_file_path ||= authen_keys_path.join('authorized_keys')
end
|
#generate_key_pairs ⇒ Object
48
49
50
|
# File 'lib/luban/deployment/cli/application/authenticator.rb', line 48
def generate_key_pairs
execute(keygen_command) unless key_pairs_generated?
end
|
#get_public_key ⇒ Object
43
44
45
46
|
# File 'lib/luban/deployment/cli/application/authenticator.rb', line 43
def get_public_key
generate_key_pairs
capture(keyget_command)
end
|
#key_pairs_generated? ⇒ Boolean
52
53
54
|
# File 'lib/luban/deployment/cli/application/authenticator.rb', line 52
def key_pairs_generated?
file?(private_key_file_path) and file?(public_key_file_path)
end
|
#keygen_command ⇒ Object
39
40
41
|
# File 'lib/luban/deployment/cli/application/authenticator.rb', line 39
def keygen_command
@keygen_command ||= "ssh-keygen -t #{authen_key_type} -f #{private_key_file_path} -N '' 2>&1"
end
|
#keyget_command ⇒ Object
35
36
37
|
# File 'lib/luban/deployment/cli/application/authenticator.rb', line 35
def keyget_command
@keyget_command ||= "cat #{public_key_file_path} 2>&1"
end
|
#private_key_file_name ⇒ Object
11
12
13
|
# File 'lib/luban/deployment/cli/application/authenticator.rb', line 11
def private_key_file_name
@private_key_file_name ||= "id_#{authen_key_type}"
end
|
#private_key_file_path ⇒ Object
19
20
21
|
# File 'lib/luban/deployment/cli/application/authenticator.rb', line 19
def private_key_file_path
@private_key_file ||= authen_keys_path.join(private_key_file_name)
end
|
#promptless_authen ⇒ Object
58
59
60
61
62
63
64
65
66
67
68
|
# File 'lib/luban/deployment/cli/application/authenticator.rb', line 58
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
70
71
72
73
74
75
76
77
78
79
80
81
82
|
# File 'lib/luban/deployment/cli/application/authenticator.rb', line 70
def promptless_authen_enabled?
origin_auth_methods = host.ssh_options[:auth_methods]
host.ssh_options[:auth_methods] = %w(publickey)
capture('echo ok') == 'ok' and keys_authorzied?
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
31
32
33
|
# File 'lib/luban/deployment/cli/application/authenticator.rb', line 31
def public_key
@public_key ||= get_public_key
end
|
#public_key_file_path ⇒ Object
23
24
25
|
# File 'lib/luban/deployment/cli/application/authenticator.rb', line 23
def public_key_file_path
@public_key_file_path ||= authen_keys_path.join("#{private_key_file_name}.pub")
end
|
#public_keys ⇒ Object
5
6
7
8
9
|
# File 'lib/luban/deployment/cli/application/authenticator.rb', line 5
def public_keys
@public_keys = task.opts.public_keys || []
@public_keys.uniq!
@public_keys
end
|