nex_client 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 966a1986c27f330dde365f817b8ce3380274a50a
4
- data.tar.gz: 04a370447d11ce3a192429af577c90d773b09c03
3
+ metadata.gz: ee805369677f92651255b9e15f4f38f47ce4cee3
4
+ data.tar.gz: d1a10a09dc9ca24456af09d068359b8c8b7b2f97
5
5
  SHA512:
6
- metadata.gz: c47f1ed90b41a780f4329503bcb7c96bb004c8de9cf7f2ff0ae50e44b1973b7367050bd9ddc4a7131091239f1b2d59433a38b72b03e67a979ad7619cde0b731d
7
- data.tar.gz: b99d5eb4c7dc37c3e7d06f59f6be3ea7d547c6202162260407d46c5b67b434b12414705048f3f5637117ccf84668dce3abb8eddd1f3aa82c82cf27162c962a52
6
+ metadata.gz: c29fd30e917f5c8439f77a754820dd6c60afb253e97067cab10dedf29914590aa3bcc23345e4cc4c06cd9c30a256f8aa92ab07c9eecd59610f6889d066ebe0dd
7
+ data.tar.gz: c9f1a77c903b38b8b6131dcc0139457911a0012931b7a3544259b0cea71b1bf308691f8e250eced2a2fbb39f7c4d297987d7b69003fecc7fe99d0fead5876cb0
@@ -360,12 +360,35 @@ module NexClient
360
360
  c.description = 'List users'
361
361
  c.example 'list all users', 'nex-cli users'
362
362
  c.example 'list all users in doecorp organization', 'nex-cli users --organization doecorp'
363
+ c.example 'list all api-only users in doecorp organization', 'nex-cli users --api --organization doecorp'
364
+ c.option '--org ORG_HANDLE', String, 'list all users in the specified organization'
363
365
  c.option '--organization ORG_HANDLE', String, 'list all users in the specified organization'
366
+ c.option '--api', 'list api-only users'
364
367
  c.action do |args, options|
365
368
  NexClient::Commands::Users.list(args,options)
366
369
  end
367
370
  end
368
371
 
372
+ command :'users:create' do |c|
373
+ c.syntax = 'nex-cli users:create [options]'
374
+ c.summary = 'Create API users'
375
+ c.description = 'Create API users for organizations'
376
+ c.example 'create api user for doecorp organization', 'nex-cli users:create doecorp'
377
+ c.action do |args, options|
378
+ NexClient::Commands::Users.create_api_user(args,options)
379
+ end
380
+ end
381
+
382
+ command :'users:delete' do |c|
383
+ c.syntax = 'nex-cli users:delete HANDLE [options]'
384
+ c.summary = 'Delete API users'
385
+ c.description = 'Delete API users from organizations'
386
+ c.example 'delete api user doecorp/37fhsg', 'nex-cli users:delete doecorp/37fhsg'
387
+ c.action do |args, options|
388
+ NexClient::Commands::Users.destroy(args,options)
389
+ end
390
+ end
391
+
369
392
  run!
370
393
  end
371
394
  end
@@ -5,15 +5,15 @@ module NexClient
5
5
  extend Helpers
6
6
 
7
7
  USERS_TITLE = "Users".colorize(:blue)
8
- USERS_HEADERS = ['id','name','email','handle','orgs'].map(&:upcase)
8
+ USERS_HEADERS = ['handle','name','email','token','api-only','orgs'].map(&:upcase)
9
9
 
10
10
  def self.list(args,opts)
11
11
  filters = {}
12
+ filters[:api_only] = opts.api if opts.api
12
13
 
13
- # Stack filter
14
- if opts.organization.present?
15
- filters[:'organization.handle'] = opts.organization
16
- end
14
+ # Org filter
15
+ org = opts.organization || opts.org
16
+ filters[:'organization.handle'] = org if org.present?
17
17
 
18
18
  # Create table
19
19
  list = NexClient::User.includes(:organizations).where(filters).order('handle')
@@ -27,6 +27,45 @@ module NexClient
27
27
  end
28
28
  end
29
29
 
30
+ def self.create_api_user(args,opts)
31
+ o = NexClient::Organization.find(handle: args.first).first
32
+ unless o
33
+ error("Error! Could not find organization: #{args.first}")
34
+ return false
35
+ end
36
+
37
+ # Create user
38
+ u = o.create_api_user
39
+ self.display_users(u)
40
+ end
41
+
42
+ def self.destroy(args,opts)
43
+ handle = args.first
44
+ e = NexClient::User.find(handle: handle).first
45
+
46
+ # Display error
47
+ unless e
48
+ error("Error! Could not find user: #{name}")
49
+ return false
50
+ end
51
+
52
+ # Display error
53
+ unless e.api_only
54
+ error("Error! Only api users can be destroyed")
55
+ return false
56
+ end
57
+
58
+ # Ask confirmation
59
+ answer = ask("Enter the handle of this user to confirm: ")
60
+ unless answer == e.handle
61
+ error("Aborting deletion...")
62
+ return false
63
+ end
64
+
65
+ e.destroy
66
+ success("Successfully destroyed api user: #{handle}")
67
+ end
68
+
30
69
  def self.display_users(list)
31
70
  table = Terminal::Table.new title: USERS_TITLE, headings: USERS_HEADERS do |t|
32
71
  [list].flatten.compact.each do |e|
@@ -40,17 +79,18 @@ module NexClient
40
79
  def self.format_record(record)
41
80
  orgs = self.format_orgs(record)
42
81
  [
43
- record.id,
44
- record.first_name,
45
- record.email,
46
82
  record.handle,
83
+ record.first_name || '-',
84
+ record.email || '-',
85
+ record.api_token || '*****',
86
+ record.api_only,
47
87
  orgs
48
88
  ]
49
89
  end
50
90
 
51
91
  def self.format_orgs(record)
52
92
  return "-" unless record.organizations.present?
53
- record.organizations.map(&:name).join(',')
93
+ record.organizations.map(&:handle).uniq.join(',')
54
94
  end
55
95
  end
56
96
  end
@@ -1,5 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
  module NexClient
3
3
  class Organization < BaseResource
4
+ property :created_at, type: :time
5
+ property :updated_at, type: :time
6
+
7
+ # POST <api_root>/organizations/:id/create_api_user
8
+ custom_endpoint :create_api_user, on: :member, request_method: :post
4
9
  end
5
10
  end
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
  module NexClient
3
3
  class User < BaseResource
4
+ property :created_at, type: :time
5
+ property :updated_at, type: :time
4
6
  end
5
7
  end
@@ -1,3 +1,3 @@
1
1
  module NexClient
2
- VERSION = '0.3.0'
2
+ VERSION = '0.4.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nex_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Arnaud Lachaume
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-08-13 00:00:00.000000000 Z
11
+ date: 2016-08-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json_api_client