Class: Duse::CLI::SecretAdd
- Inherits:
-
ApiCommand
- Object
- Command
- ApiCommand
- Duse::CLI::SecretAdd
- Includes:
- ShareWithUser, KeyHelper
- Defined in:
- lib/duse/cli/secret_add.rb
Instance Attribute Summary
Attributes inherited from Command
#arguments, #force_interactive, #input, #output
Instance Method Summary collapse
Methods included from KeyHelper
#choose_key, #choose_private_key_file, #ensure_matching_keys_for, #generate_key, #home_dir, #matching_keys?, #possible_ssh_keys, #private_key_for, #ssh_dir, #valid_ssh_private_key?
Methods inherited from ApiCommand
Methods inherited from Command
abstract, abstract?, #check_arity, #color, #command_name, command_name, #config, description, #error, #execute, #format, #full_command, full_command, has_subcommands?, has_super_command?, #help, #help_subcommands, #initialize, #interactive?, #parse, #say, #setup, skip, subcommand, subcommands, #success, super_command, super_command=, #terminal, #usage, #usage_for, #warn, #write_to, #wrong_args
Methods included from Parser
Constructor Details
This class inherits a constructor from Duse::CLI::Command
Instance Method Details
#run ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/duse/cli/secret_add.rb', line 21 def run self.title ||= terminal.ask 'What do you want to call this secret? ' self.secret = File.read(self.file) if file? self.secret = SecretGenerator.new.generated_password if generate_secret? self.secret ||= terminal.ask 'Secret to save: ' users = who_to_share_with if self.folder.nil? && terminal.agree('Put secret in a folder other than the root folder?[y/n] ') self.folder = terminal.ask 'Which folder do you want to put the secret in? (provide the id) ' end user = Duse::User.current ensure_matching_keys_for user private_key = config.private_key_for user secret_hash = Duse::Client::CreateSecret.with( title: self.title, secret_text: self.secret, folder_id: self.folder, users: users ).sign_with(private_key).build response = Duse::Secret.create secret_hash success 'Secret successfully created!' end |