Class: Cyclid::Cli::AdminOrganization

Inherits:
Thor
  • Object
show all
Defined in:
lib/cyclid/cli/admin/organization.rb

Overview

‘admin organization’ sub-commands

Instance Method Summary collapse

Instance Method Details

#create(name, email) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/cyclid/cli/admin/organization.rb', line 60

def create(name, email)
  client.org_add(name, email)

  if options[:admin]
    # Add the user to the organization and create the appropriate admin
    # permissions for them.
    client.org_modify(name,
                      members: options[:admin])

    perms = { 'admin' => true, 'write' => true, 'read' => true }
    client.org_user_permissions(name,
                                options[:admin],
                                perms)
  end
rescue StandardError => ex
  abort "Failed to create new organization: #{ex}"
end

#delete(name) ⇒ Object



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/cyclid/cli/admin/organization.rb', line 105

def delete(name)
  if options[:force]
    delete = true
  else
    print "Delete organization #{name}: are you sure? (Y/n): ".colorize(:red)
    delete = STDIN.getc.chr.casecmp('y') == 0
  end
  abort unless delete

  begin
    client.org_delete(name)
  rescue StandardError => ex
    abort "Failed to delete organization: #{ex}"
  end
end

#listObject



20
21
22
23
24
25
26
27
# File 'lib/cyclid/cli/admin/organization.rb', line 20

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



90
91
92
93
94
95
96
# File 'lib/cyclid/cli/admin/organization.rb', line 90

def modify(name)
  client.org_modify(name,
                    owner_email: options[:email],
                    members: options[:members])
rescue StandardError => ex
  abort "Failed to modify organization: #{ex}"
end

#show(name) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/cyclid/cli/admin/organization.rb', line 30

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
  puts 'Name: '.colorize(:cyan) + org['name']
  puts 'Owner Email: '.colorize(:cyan) + org['owner_email']
  puts 'Public Key: '.colorize(:cyan) + public_key.to_pem
  puts 'Members:'.colorize(:cyan)
  if org['users'].any?
    org['users'].each do |user|
      puts "\t#{user}"
    end
  else
    puts "\tNone"
  end
rescue StandardError => ex
  abort "Failed to get organization: #{ex}"
end