Class: Cyclid::Cli::AdminOrganization
- Defined in:
- lib/cyclid/cli/admin/organization.rb
Overview
‘admin organization’ sub-commands
Instance Method Summary collapse
- #create(name, email) ⇒ Object
- #delete(name) ⇒ Object
- #list ⇒ Object
- #modify(name) ⇒ Object
- #show(name) ⇒ Object
Instance Method Details
#create(name, email) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/cyclid/cli/admin/organization.rb', line 62 def create(name, email) client.org_add(name, email) if [:admin] # Add the user to the organization and create the appropriate admin # permissions for them. client.org_modify(name, members: [[:admin]]) perms = { 'admin' => true, 'write' => true, 'read' => true } client.(name, [:admin], perms) end rescue StandardError => ex abort "Failed to create new organization: #{ex}" end |
#delete(name) ⇒ Object
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/cyclid/cli/admin/organization.rb', line 107 def delete(name) if [:force] delete = true else Formatter.ask "Delete organization #{name}: are you sure? (Y/n)" delete = STDIN.getc.chr.casecmp('y').zero? end abort unless delete begin client.org_delete(name) rescue StandardError => ex abort "Failed to delete organization: #{ex}" end end |
#list ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'lib/cyclid/cli/admin/organization.rb', line 22 def list orgs = client.org_list orgs.each do |org| puts org end rescue StandardError => ex abort "Failed to retrieve list of organizations: #{ex}" end |
#modify(name) ⇒ Object
92 93 94 95 96 97 98 |
# File 'lib/cyclid/cli/admin/organization.rb', line 92 def modify(name) client.org_modify(name, owner_email: [:email], members: [:members]) rescue StandardError => ex abort "Failed to modify organization: #{ex}" end |
#show(name) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/cyclid/cli/admin/organization.rb', line 32 def show(name) org = client.org_get(name) # Convert the public key to PEM der_key = Base64.decode64(org['public_key']) public_key = OpenSSL::PKey::RSA.new(der_key) # Pretty print the organization details Formatter.colorize 'Name', org['name'] Formatter.colorize 'Owner Email', org['owner_email'] Formatter.colorize 'Public Key', public_key.to_pem Formatter.colorize 'Members:' if org['users'].any? org['users'].each do |user| Formatter.puts "\t#{user}" end else Formatter.puts "\tNone" end rescue StandardError => ex abort "Failed to get organization: #{ex}" end |