Class: KBSecret::CLI::Command::Session
- Defined in:
- lib/kbsecret/cli/command/session.rb
Overview
The implementation of kbsecret session
.
Constant Summary collapse
- SUBCOMMANDS =
The list of subcommands supported by
kbsecret session
. %w[new rm].freeze
Instance Attribute Summary
Attributes inherited from Abstract
Instance Method Summary collapse
-
#initialize(argv) ⇒ Session
constructor
A new instance of Session.
- #new_session ⇒ void private
- #rm_session ⇒ void private
- #run! ⇒ Object
- #setup! ⇒ Object
- #validate! ⇒ Object
Methods inherited from Abstract
Constructor Details
#initialize(argv) ⇒ Session
Returns a new instance of Session.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/kbsecret/cli/command/session.rb', line 11 def initialize(argv) super(argv) do |cli| cli.slop cmds: SUBCOMMANDS do |o| o. = " Usage:\n kbsecret session [options] <new|rm> <label>\n HELP\n\n o.string \"-t\", \"--team\", \"the team to create the session under\"\n o.array \"-u\", \"--users\", \"the Keybase users\", default: [Keybase::Local.current_user]\n o.string \"-r\", \"--root\", \"the secret root directory\"\n o.bool \"-c\", \"--create-team\", \"create the Keybase team if it does not exist\"\n o.bool \"-f\", \"--force\", \"force creation (ignore overwrites, etc.)\"\n o.bool \"-n\", \"--no-notify\", \"do not send a notification to session members\"\n o.bool \"-d\", \"--delete\", \"unlink the session in addition to deconfiguration\"\n end\n\n cli.dreck do\n string :command\n string :session\n end\n\n cli.ensure_session! :argument if cli.args[:command] == \"rm\"\n end\nend\n" |
Instance Method Details
#new_session ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/kbsecret/cli/command/session.rb', line 60 def new_session if Config.session?(@label) && !cli.opts.force? cli.die "Refusing to overwrite a session without --force." end if cli.opts[:team] teams = Keybase::Local::Team.list_self_memberships.teams unless teams.map(&:fq_name).include?(cli.opts[:team]) if cli.opts.create_team? Keybase::Local::Team.create_team cli.opts[:team] Keybase::Local::Team.add_members cli.opts[:team], users: [{ username: Keybase::Local.current_user, role: "admin", }] else cli.die "No such team (either nonexistent or non-member)." end end Config.configure_session(@label, team: cli.opts[:team], root: @label) else cli.die "Missing `-r', `--root' option." unless cli.opts[:root] cli.opts[:users].each do |user| cli.die "Nonexistent Keybase user: #{user}." unless Keybase::API.user? user end unless cli.opts[:users].include? Keybase::Local.current_user cli.warn "You didn't include yourself in the user list, but I'll add you." cli.opts[:users] << Keybase::Local.current_user end Config.configure_session(@label, users: cli.opts[:users], root: cli.opts[:root]) unless cli.opts.no_notify? && cli.opts[:users] != [Keybase::Local.current_user] users = cli.opts[:users].join(",") Keybase::Local::Chat. cli.opts[:users], " You've been added to a KBSecret session!\n\n To access this session, please run the following:\n\n ```\n $ kbsecret session new -r '\#{cli.opts[:root]}' -u \#{users} <label>\n ```\n\n If you don't have KBSecret installed, you can install it from `gem`:\n\n ```\n $ gem install kbsecret\n ```\n MESSAGE\n end\n end\nend\n" |
#rm_session ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
119 120 121 122 |
# File 'lib/kbsecret/cli/command/session.rb', line 119 def rm_session cli.session.unlink! if cli.opts.delete? Config.deconfigure_session @label end |
#run! ⇒ Object
49 50 51 52 53 54 55 56 |
# File 'lib/kbsecret/cli/command/session.rb', line 49 def run! case @subcmd when "new" new_session when "rm" rm_session end end |
#setup! ⇒ Object
38 39 40 41 |
# File 'lib/kbsecret/cli/command/session.rb', line 38 def setup! @label = cli.args[:session] @subcmd = cli.args[:command] end |
#validate! ⇒ Object
44 45 46 |
# File 'lib/kbsecret/cli/command/session.rb', line 44 def validate! cli.die "Unknown subcommand: #{@subcmd}." unless SUBCOMMANDS.include?(@subcmd) end |