Class: Cyclid::Cli::Organization
- Defined in:
- lib/cyclid/cli/organization.rb
Overview
‘organization’ sub-command
Instance Method Summary collapse
Instance Method Details
#list ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/cyclid/cli/organization.rb', line 65 def list Dir.glob("#{CYCLID_CONFIG_DIR}/*").each do |fname| next if File.symlink?(fname) next unless File.file?(fname) begin # Create a Config from this file and display the details config = Cyclid::Client::Config.new(path: fname) Formatter.colorize File.basename(fname) scheme = config.tls ? URI::HTTPS : URI::HTTP uri = scheme.build(host: config.server, port: config.port) Formatter.colorize "\tURL", uri.to_s Formatter.colorize "\tOrganization", config.organization Formatter.colorize "\tUsername", config.username rescue StandardError => ex $stderr.puts "Failed to load config file #{fname}: #{ex}" end end end |
#modify ⇒ Object
57 58 59 60 61 62 |
# File 'lib/cyclid/cli/organization.rb', line 57 def modify client.org_modify(client.config.organization, owner_email: [:email]) rescue StandardError => ex abort "Failed to modify organization: #{ex}" end |
#show ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/cyclid/cli/organization.rb', line 27 def show org = client.org_get(client.config.organization) # 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| puts "\t#{user}" end else puts "\tNone" end rescue StandardError => ex abort "Failed to get organization: #{ex}" end |
#use(name = nil) ⇒ Object
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 116 117 118 119 120 121 122 123 |
# File 'lib/cyclid/cli/organization.rb', line 87 def use(name = nil) # If 'use' was called without an argument, print the name of the # current configuration if name.nil? fname = if File.symlink?([:config]) File.readlink([:config]) else [:config] end puts File.basename(fname) else # List the avialble configurations fname = File.join(CYCLID_CONFIG_DIR, name) # Sanity check that the configuration file exists and is valid abort 'No such organization' unless File.exist?(fname) abort 'Not a valid organization' unless File.file?(fname) begin config = Cyclid::Client::Config.new(path: fname) raise if config.server.nil? or \ config.organization.nil? or \ config.username.nil? or \ config.secret.nil? rescue StandardError abort 'Invalid configuration file' end # The configuration file exists and appears to be sane, so switch the # 'config' symlink to point to it. Dir.chdir(CYCLID_CONFIG_DIR) do File.delete('config') if File.exist?('config') File.symlink(name, 'config') end end end |