enfcli 4.2.2.pre.alpha → 5.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  #
2
- # Copyright 2018 Xaptum,Inc
2
+ # Copyright 2018-2020 Xaptum,Inc
3
3
  #
4
4
  # Licensed under the Apache License, Version 2.0 (the "License");
5
5
  # you may not use this file except in compliance with the License.
@@ -26,8 +26,8 @@ module EnfCli
26
26
  [hash[:ipv6],
27
27
  hash[:name],
28
28
  hash[:state],
29
- hash[:state] == "OFFLINE" ? "" : hash[:ev_asn_org],
30
- hash[:state] == "OFFLINE" ? "" : hash[:ev_remote_ip]]
29
+ hash[:state] == "OFFLINE" ? "" : hash[:last_event][:asn_org],
30
+ hash[:state] == "OFFLINE" ? "" : hash[:last_event][:remote_ip]]
31
31
  }
32
32
  render_table(headings, rows, options.file)
33
33
  end
@@ -41,23 +41,23 @@ module EnfCli
41
41
  end
42
42
 
43
43
  def display_domains(domains)
44
- headings = ["Name", "Network", "Status"]
44
+ headings = ["Name", "Cidr", "Status"]
45
45
  rows = domains.map { |hash|
46
- [hash[:name], hash[:network], hash[:status]]
46
+ [hash[:name], hash[:cidr], hash[:status]]
47
47
  }
48
48
  render_table(headings, rows)
49
49
  end
50
50
 
51
51
  def display_networks(networks)
52
- headings = ["Name", "Network", "Description", "Status"]
52
+ headings = ["Name", "Cidr", "Description", "Status"]
53
53
  rows = networks.map { |hash|
54
- [hash[:name], hash[:network], hash[:description], hash[:status]]
54
+ [hash[:name], hash[:cidr], hash[:description], hash[:status]]
55
55
  }
56
56
  render_table(headings, rows)
57
57
  end
58
58
 
59
59
  def display_network(network)
60
- network_cidr = network[:network]
60
+ network_cidr = network[:cidr]
61
61
  name = network[:name] || ""
62
62
  description = network[:description] || ""
63
63
  status = network[:status] || ""
@@ -104,13 +104,26 @@ module EnfCli
104
104
  }
105
105
 
106
106
  desc "list-networks", "List all virtual networks in domain"
107
+ method_option :domain, type: :string, default: nil, banner: "/48 CIDR",
108
+ aliases: "-d"
107
109
 
108
110
  def list_networks
109
111
  try_with_rescue_in_session do
110
- domain_id = EnfCli::CTX.instance.session[:domain_id]
112
+ # get correct domain
113
+ domain = EnfCli::CTX.instance.session[:domain]
114
+ raise EnfCli::ERROR, "User not in a valid domain!" unless domain
115
+
116
+ # check if admin
117
+ if EnfCli::CTX.instance.xaptum_admin?
118
+ raise EnfCli::ERROR, "--domain is required" unless options[:domain]
119
+
120
+ domain = options[:domain]
121
+ elsif options[:domain]
122
+ say "Warning: Ignoring command option --domain #{options[:domain]}", :yellow
123
+ end
111
124
 
112
125
  # Call the api
113
- data = EnfApi::API.instance.list_domain_nws domain_id
126
+ data = EnfApi::API.instance.list_domain_nws domain
114
127
  networks = data[:data]
115
128
 
116
129
  # display table
@@ -120,13 +133,24 @@ module EnfCli
120
133
 
121
134
  desc "provision-network", "Provision a Network"
122
135
  method_option :name, :type => :array, :required => true, :banner => "NAME"
136
+ method_option :domain, type: :string, default: nil, banner: "/48 CIDR",
137
+ aliases: "-d"
123
138
  method_option :description, :type => :array, :banner => "DESCRIPTION"
124
139
 
125
140
  def provision_network
126
141
  try_with_rescue_in_session do
127
- # verify domain context is set
128
- domain_id = EnfCli::CTX.instance.session[:domain_id]
129
- raise EnfCli::ERROR, "User's domain not available!" if !domain_id || domain_id < 0
142
+ # get correct domain
143
+ domain = EnfCli::CTX.instance.session[:domain]
144
+ raise EnfCli::ERROR, "User not in a valid domain!" unless domain
145
+
146
+ # check if admin
147
+ if EnfCli::CTX.instance.xaptum_admin?
148
+ raise EnfCli::ERROR, "--domain is required" unless options[:domain]
149
+
150
+ domain = options[:domain]
151
+ elsif options[:domain]
152
+ say "Warning: Ignoring command option --domain #{options[:domain]}", :yellow
153
+ end
130
154
 
131
155
  # Get options
132
156
  description = ""
@@ -136,10 +160,9 @@ module EnfCli
136
160
  # Call the api
137
161
  hash = {
138
162
  :name => network_name,
139
- :domain_id => domain_id,
140
163
  :description => description,
141
164
  }
142
- data = EnfApi::API.instance.create_nw hash
165
+ data = EnfApi::API.instance.create_nw domain, hash
143
166
  networks = data[:data]
144
167
 
145
168
  # display table
@@ -211,10 +234,10 @@ module EnfCli
211
234
 
212
235
  # call api
213
236
  data = { :data => [] }
214
- case session[:type]
215
- when "XAPTUM_ADMIN"
237
+
238
+ if EnfCli::CTX.instance.xaptum_admin?
216
239
  data = EnfApi::API.instance.list_domains
217
- when "DOMAIN_ADMIN"
240
+ elsif EnfCli::CTX.instance.has_role?("DOMAIN_ADMIN")
218
241
  data = EnfApi::API.instance.get_domain session[:domain_id]
219
242
  end
220
243
 
@@ -252,13 +275,13 @@ module EnfCli
252
275
  end
253
276
 
254
277
  desc "list-domain-rate-limits", "List domain rate limits"
255
- method_option :network, :type => :string, :required => true, :banner => "</48 Network>"
278
+ method_option :domain, :type => :string, :required => true, :banner => "/48 CIDR"
256
279
  method_option :filter, :type => :string, :enum => ["default", "max"]
257
280
 
258
281
  def list_domain_rate_limits
259
282
  try_with_rescue_in_session do
260
283
  # Call the api
261
- data = EnfApi::API.instance.get_domain_rate_limits options[:network], options[:filter]
284
+ data = EnfApi::API.instance.get_domain_rate_limits options[:domain], options[:filter]
262
285
 
263
286
  # Get the limits
264
287
  limits = data[:data][0]
@@ -274,7 +297,7 @@ module EnfCli
274
297
  end
275
298
 
276
299
  desc "list-network-rate-limits", "List network rate limits"
277
- method_option :network, :type => :string, :required => true
300
+ method_option :network, :type => :string, :required => true, :banner => "/64 CIDR"
278
301
  method_option :filter, :type => :string, :enum => ["default", "max"]
279
302
 
280
303
  def list_network_rate_limits
@@ -318,12 +341,12 @@ module EnfCli
318
341
  end
319
342
 
320
343
  desc "activate-domain", "Activate a customer's /48 domain"
321
- method_option :network, :type => :string, :required => true
344
+ method_option :domain, :type => :string, :required => true, banner: "/48 CIDR"
322
345
 
323
346
  def activate_domain
324
347
  try_with_rescue_in_session do
325
348
  # Call api
326
- data = EnfApi::API.instance.update_domain_status options[:network], { :status => "ACTIVE" }
349
+ data = EnfApi::API.instance.update_domain_status options[:domain], { :status => "ACTIVE" }
327
350
  domains = data[:data]
328
351
 
329
352
  # Display the data
@@ -333,12 +356,12 @@ module EnfCli
333
356
  end
334
357
 
335
358
  desc "deactivate-domain", "Deactivate a customer's /48 domain"
336
- method_option :network, :type => :string, :required => true
359
+ method_option :domain, :type => :string, :required => true, banner: "/48 CIDR"
337
360
 
338
361
  def deactivate_domain
339
362
  try_with_rescue_in_session do
340
363
  # Call api
341
- data = EnfApi::API.instance.update_domain_status options[:network], { :status => "READY" }
364
+ data = EnfApi::API.instance.update_domain_status options[:domain], { :status => "READY" }
342
365
  domains = data[:data]
343
366
 
344
367
  # Display the data
@@ -348,12 +371,12 @@ module EnfCli
348
371
  end
349
372
 
350
373
  desc "set-domain-rate-limits", "Update a customer /48 domain's endpoint rate limits"
351
- method_option :network, :type => :string, :required => true
374
+ method_option :domain, :type => :string, :required => true, banner: "/48 CIDR"
352
375
  method_option :limit, :type => :string, :enum => ["default", "max"], :required => true
353
- method_option :'packets-per-second', :type => :numeric, :required => true
354
- method_option :'packets-burst-size', :type => :numeric, :required => true
355
- method_option :'bytes-per-second', :type => :numeric, :required => true
356
- method_option :'bytes-burst-size', :type => :numeric, :required => true
376
+ method_option :'packets-per-second', :type => :numeric, :required => true, aliases: "-p"
377
+ method_option :'packets-burst-size', :type => :numeric, :required => true, aliases: "-P"
378
+ method_option :'bytes-per-second', :type => :numeric, :required => true, aliases: "-b"
379
+ method_option :'bytes-burst-size', :type => :numeric, :required => true, aliases: "-B"
357
380
 
358
381
  def set_domain_rate_limits
359
382
  try_with_rescue_in_session do
@@ -364,7 +387,7 @@ module EnfCli
364
387
  :bytes_per_second => options["bytes-per-second"],
365
388
  :bytes_burst_size => options["bytes-burst-size"],
366
389
  }
367
- data = EnfApi::API.instance.update_domain_rate_limits options[:network], options[:limit], hash
390
+ data = EnfApi::API.instance.update_domain_rate_limits options[:domain], options[:limit], hash
368
391
  limits = data[:data][0]
369
392
 
370
393
  # The Api returns only the rate limits object. Have to add type explicitly to display
@@ -378,10 +401,10 @@ module EnfCli
378
401
  desc "set-network-rate-limits", "Update a customer /64 network's endpoint rate limits"
379
402
  method_option :network, :type => :string, :required => true
380
403
  method_option :limit, :type => :string, :enum => ["default", "max"], :required => true
381
- method_option :'packets-per-second', :type => :numeric, :required => true
382
- method_option :'packets-burst-size', :type => :numeric, :required => true
383
- method_option :'bytes-per-second', :type => :numeric, :required => true
384
- method_option :'bytes-burst-size', :type => :numeric, :required => true
404
+ method_option :'packets-per-second', :type => :numeric, :required => true, aliases: "-p"
405
+ method_option :'packets-burst-size', :type => :numeric, :required => true, aliases: "-P"
406
+ method_option :'bytes-per-second', :type => :numeric, :required => true, aliases: "-b"
407
+ method_option :'bytes-burst-size', :type => :numeric, :required => true, aliases: "-B"
385
408
 
386
409
  def set_network_rate_limits
387
410
  try_with_rescue_in_session do
@@ -427,10 +450,10 @@ module EnfCli
427
450
  desc "set-endpoint-rate-limits", "Update an ipv6 endpoint rate limits"
428
451
  method_option :ipv6, :type => :string, :required => true
429
452
  method_option :limit, :type => :string, :enum => ["current", "max"], :required => true
430
- method_option :'packets-per-second', :type => :numeric, :required => true
431
- method_option :'packets-burst-size', :type => :numeric, :required => true
432
- method_option :'bytes-per-second', :type => :numeric, :required => true
433
- method_option :'bytes-burst-size', :type => :numeric, :required => true
453
+ method_option :'packets-per-second', :type => :numeric, :required => true, aliases: "-p"
454
+ method_option :'packets-burst-size', :type => :numeric, :required => true, aliases: "-P"
455
+ method_option :'bytes-per-second', :type => :numeric, :required => true, aliases: "-b"
456
+ method_option :'bytes-burst-size', :type => :numeric, :required => true, aliases: "-B"
434
457
 
435
458
  def set_endpoint_rate_limits
436
459
  try_with_rescue_in_session do
@@ -474,17 +497,13 @@ module EnfCli
474
497
  end
475
498
 
476
499
  desc "list-endpoints", "List all connections in a network"
477
- method_option :network, :type => :string, :required => true
500
+ method_option :network, :type => :string, :required => true, banner: "/48 CIDR"
478
501
  method_option :file, :type => :string, :aliases => "-f"
479
502
 
480
503
  def list_endpoints
481
504
  try_with_rescue_in_session do
482
- # verify domain context is set
483
- domain_id = EnfCli::CTX.instance.session[:domain_id]
484
- raise EnfCli::ERROR, "User's domain not available!" if !domain_id || domain_id < 0
485
-
486
505
  # call api
487
- data = EnfApi::API.instance.list_nw_connections domain_id, options.network, options.file
506
+ data = EnfApi::API.instance.list_nw_connections options.network
488
507
  cxns = data[:data]
489
508
 
490
509
  # display table
@@ -550,15 +569,15 @@ module EnfCli
550
569
  end
551
570
 
552
571
  desc "activate-enf-network", "Active a /34 enf network"
553
- method_option :network, :type => :string, :required => true
572
+ method_option :cidr, :type => :string, :required => true
554
573
 
555
574
  def activate_enfnw
556
575
  try_with_rescue_in_session do
557
576
  # Call the api
558
- EnfApi::API.instance.activate_enfnw options.network
577
+ EnfApi::API.instance.activate_enfnw options.cidr
559
578
 
560
579
  # Print success
561
- say "Activated Enf Network #{options.network}!", :green
580
+ say "Activated Enf Network #{options.cidr}!", :green
562
581
  end
563
582
  end
564
583
  end # class
@@ -1,5 +1,5 @@
1
1
  #
2
- # Copyright 2019 Xaptum,Inc
2
+ # Copyright 2019-2020 Xaptum,Inc
3
3
  #
4
4
  # Licensed under the Apache License, Version 2.0 (the "License");
5
5
  # you may not use this file except in compliance with the License.
@@ -14,7 +14,7 @@
14
14
  # limitations under the License.
15
15
  #
16
16
  require "enfthor"
17
- require "enfapi"
17
+ require "enfapi/dns"
18
18
 
19
19
  module EnfCli
20
20
  module Cmd
@@ -46,9 +46,9 @@ module EnfCli
46
46
  end
47
47
 
48
48
  def display_zones_table(zones)
49
- headings = ["Id", "Zone", "Description", "Enf Domain"]
49
+ headings = ["Id", "Zone", "Description", "Privileged", "Enf Domain"]
50
50
  rows = zones.map { |hash|
51
- [hash[:id], hash[:zone_domain_name], hash[:description], hash[:enf_domain]]
51
+ [hash[:id], hash[:zone_domain_name], hash[:description], hash[:privileged], hash[:enf_domain]]
52
52
  }
53
53
  render_table(headings, rows)
54
54
  end
@@ -82,6 +82,7 @@ module EnfCli
82
82
  method_option :'zone-domain-name', :type => :string, :required => true
83
83
  method_option :description, :type => :array, :banner => "DESCRIPTION"
84
84
  method_option :'enf-domain', :type => :string, :banner => "/48 Enf Domain"
85
+ method_option :'enf-network', :type => :string, :banner => "/64 Enf Network"
85
86
 
86
87
  def create_zone
87
88
  try_with_rescue_in_session do
@@ -91,12 +92,16 @@ module EnfCli
91
92
  ## Gather parameters
92
93
  zone_domain_name = options["zone-domain-name"]
93
94
  description = array_option_to_string(options.description) if options.description
94
- case session[:type]
95
- when "XAPTUM_ADMIN"
95
+ if EnfCli::CTX.instance.xaptum_admin?
96
96
  enf_domain = options["enf-domain"]
97
97
  raise "No value provided for required options '--enf-domain'" unless enf_domain
98
98
  else
99
- enf_domain = session[:domain_network]
99
+ enf_domain = session[:domain]
100
+ end
101
+
102
+ enf_network = options["enf-network"]
103
+ unless EnfCli::CTX.instance.edit_domain_role?
104
+ raise "No value provided for required option '--enf-network'" unless enf_network
100
105
  end
101
106
 
102
107
  ## create request hash
@@ -106,6 +111,9 @@ module EnfCli
106
111
  :enf_domain => enf_domain,
107
112
  }
108
113
 
114
+ ## add enf_network to request if present
115
+ new_zone[:enf_network] = enf_network if enf_network
116
+
109
117
  ## call api
110
118
  data = EnfApi::Dns.instance.create_dns_zone new_zone
111
119
  zones = data[:data]
@@ -125,12 +133,11 @@ module EnfCli
125
133
  ## session
126
134
  session = EnfCli::CTX.instance.session
127
135
 
128
- case session[:type]
129
- when "XAPTUM_ADMIN"
136
+ if EnfCli::CTX.instance.xaptum_admin?
130
137
  enf_domain = options["enf-domain"]
131
138
  raise "No value provided for required options '--enf-domain'" unless enf_domain
132
139
  else
133
- enf_domain = session[:domain_network]
140
+ enf_domain = session[:domain]
134
141
  end
135
142
 
136
143
  ## call api
@@ -1,5 +1,5 @@
1
1
  #
2
- # Copyright 2018 Xaptum,Inc
2
+ # Copyright 2018-2020 Xaptum,Inc
3
3
  #
4
4
  # Licensed under the Apache License, Version 2.0 (the "License");
5
5
  # you may not use this file except in compliance with the License.
@@ -14,7 +14,7 @@
14
14
  # limitations under the License.
15
15
  #
16
16
  require "enfthor"
17
- require "enfapi"
17
+ require "enfapi/firewall"
18
18
  require "base64"
19
19
  require "digest"
20
20
  require "openssl"
@@ -44,7 +44,8 @@ module EnfCli
44
44
  def list_firewall_rules
45
45
  try_with_rescue_in_session do
46
46
  # call the api
47
- rules = EnfApi::Firewall.instance.list_firewall_rules options[:network]
47
+ data = EnfApi::Firewall.instance.list_firewall_rules options[:network]
48
+ rules = data[:data]
48
49
 
49
50
  # display empty table and return
50
51
  if rules.length == 0
@@ -90,7 +91,7 @@ module EnfCli
90
91
  end
91
92
 
92
93
  desc "add-firewall-rule", "Add a firewall rule to a /64 network"
93
- method_option :network, :type => :string, :required => true
94
+ method_option :network, :type => :string
94
95
  method_option :priority, :type => :numeric, :required => true
95
96
  method_option :protocol, :type => :string, :required => true, :enum => ["TCP", "UDP", "ICMP6", "6", "17", "58"]
96
97
  method_option :source_ip, :type => :string
@@ -117,10 +118,12 @@ module EnfCli
117
118
  }
118
119
 
119
120
  # call the api
120
- EnfApi::Firewall.instance.add_firewall_rule options[:network], rule
121
+ data = EnfApi::Firewall.instance.add_firewall_rule options[:network], rule
122
+ rules = data[:data]
121
123
 
122
124
  # print success
123
125
  say "Created firewall rule!", :green
126
+ display_firewall_rules rules
124
127
  end
125
128
  end
126
129
 
@@ -14,5 +14,5 @@
14
14
  # limitations under the License.
15
15
  #
16
16
  module EnfCli
17
- VERSION = "4.2.2-alpha"
17
+ VERSION = "5.0.2"
18
18
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: enfcli
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.2.2.pre.alpha
4
+ version: 5.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Venkatakumar Srinivasan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-04-30 00:00:00.000000000 Z
11
+ date: 2020-06-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -243,6 +243,9 @@ files:
243
243
  - enfcli.gemspec
244
244
  - format.sh
245
245
  - lib/enfapi.rb
246
+ - lib/enfapi/dns.rb
247
+ - lib/enfapi/firewall.rb
248
+ - lib/enfapi/user.rb
246
249
  - lib/enfcli.rb
247
250
  - lib/enfcli/commands/captive.rb
248
251
  - lib/enfcli/commands/user.rb
@@ -266,9 +269,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
266
269
  version: '0'
267
270
  required_rubygems_version: !ruby/object:Gem::Requirement
268
271
  requirements:
269
- - - ">"
272
+ - - ">="
270
273
  - !ruby/object:Gem::Version
271
- version: 1.3.1
274
+ version: '0'
272
275
  requirements: []
273
276
  rubygems_version: 3.0.3
274
277
  signing_key: