Module: App42::Command::UserToken
Instance Method Summary collapse
-
#check_key_file? ⇒ Boolean
Load yaml config file make sure file contain api and secret key.
-
#config_path ⇒ Object
Extract app42pass config dir path and remove from configuration file.
-
#ensure_config_dir ⇒ Object
make sure configuration root directory exist? create new dir unless file.exist?.
-
#ensure_key_file ⇒ Object
collect key path from constants mkdir key file.
-
#get_keys ⇒ Object
Load yaml config file read api and secret key.
-
#key_path ⇒ Object
Expand key path.
-
#local_app42_key(api_key, secret_key) ⇒ Object
expand key file path And open in write mode and configure api and secret key.
-
#remove_key_file ⇒ Object
Extract key path and remove from configuration file.
Instance Method Details
#check_key_file? ⇒ Boolean
Load yaml config file make sure file contain api and secret key
17 18 19 20 |
# File 'lib/app42/command/user_key.rb', line 17 def check_key_file? info = YAML.load_file(key_path) if File.exist? key_path true unless info.nil? || info['api_key'].nil? || info['secret_key'].nil? end |
#config_path ⇒ Object
Extract app42pass config dir path and remove from configuration file
56 57 58 |
# File 'lib/app42/command/user_key.rb', line 56 def config_path File.(App42::CONFIG_DIR) end |
#ensure_config_dir ⇒ Object
make sure configuration root directory exist? create new dir unless file.exist?
11 12 13 |
# File 'lib/app42/command/user_key.rb', line 11 def ensure_config_dir FileUtils.mkdir_p(config_path) unless File.exist? config_path end |
#ensure_key_file ⇒ Object
collect key path from constants mkdir key file
62 63 64 |
# File 'lib/app42/command/user_key.rb', line 62 def ensure_key_file FileUtils.mkdir_p(key_path) unless File.exist? key_path end |
#get_keys ⇒ Object
Load yaml config file read api and secret key
24 25 26 27 28 |
# File 'lib/app42/command/user_key.rb', line 24 def get_keys keys = YAML.load_file(key_path) if File.exist? key_path return nil, nil if keys.nil? || keys.empty? return keys['api_key'], keys['secret_key'] unless keys.empty? || keys.nil? end |
#key_path ⇒ Object
Expand key path
50 51 52 |
# File 'lib/app42/command/user_key.rb', line 50 def key_path File.(App42::KEYS_FILE) end |
#local_app42_key(api_key, secret_key) ⇒ Object
expand key file path And open in write mode and configure api and secret key
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/app42/command/user_key.rb', line 32 def local_app42_key api_key, secret_key key_file = File.(App42::KEYS_FILE) File.open(key_file, "w") { |f| f.puts "api_key:" f.puts " #{api_key}" f.puts "secret_key:" f.puts " #{secret_key}" } end |
#remove_key_file ⇒ Object
Extract key path and remove from configuration file
45 46 47 |
# File 'lib/app42/command/user_key.rb', line 45 def remove_key_file FileUtils.rm_f(key_path) end |