enfcli 4.0.0 → 4.1.0.pre.alpha
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/Dockerfile +2 -2
- data/.circleci/config.yml +5 -0
- data/Gemfile.lock +37 -25
- data/Makefile +7 -0
- data/README.md +52 -7
- data/enfcli.gemspec +28 -26
- data/format.sh +9 -0
- data/lib/enfapi.rb +86 -97
- data/lib/enfcli.rb +166 -94
- data/lib/enfcli/commands/captive.rb +149 -149
- data/lib/enfcli/commands/user.rb +23 -20
- data/lib/enfcli/commands/xcr.rb +95 -82
- data/lib/enfcli/commands/xdns.rb +53 -50
- data/lib/enfcli/commands/xfw.rb +37 -37
- data/lib/enfcli/commands/xiam.rb +87 -80
- data/lib/enfcli/version.rb +1 -1
- data/lib/enfthor.rb +38 -14
- metadata +62 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6c9800b36ddca58b6dbb8bb6b046377eedf93cbc48ca19b8c98c8088941515e6
|
4
|
+
data.tar.gz: 1a0bd51b13fbf5eba7359fd8517b2a6c0cf4d905edde572b907f9d0d3b5e66c6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f773cff7b8db6fb7d8b707cff76907d74f4c5089276b6eecd0b1297ab54fbf1a9c54cb59fc887a25055299502307a1649c4a85efe84d3c5f975d6a3b613909d4
|
7
|
+
data.tar.gz: d5c1a47a07f9e95ec52a73ba241743acece46e9b91761ed2022f9785dd3355570a2713b2cc294f87dbb021eb8cac8bb9308d39a6e25f37bcae1feec54e96f602
|
data/.circleci/Dockerfile
CHANGED
data/.circleci/config.yml
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,10 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
enfcli (4.0.
|
4
|
+
enfcli (4.1.0.pre.alpha)
|
5
|
+
clipboard
|
6
|
+
ffi
|
7
|
+
readline
|
5
8
|
rest-client (~> 2.0)
|
6
9
|
terminal-table
|
7
10
|
thor (~> 0.20.0)
|
@@ -9,49 +12,57 @@ PATH
|
|
9
12
|
GEM
|
10
13
|
remote: https://rubygems.org/
|
11
14
|
specs:
|
12
|
-
addressable (2.
|
13
|
-
public_suffix (>= 2.0.2, <
|
14
|
-
bump (0.
|
15
|
+
addressable (2.7.0)
|
16
|
+
public_suffix (>= 2.0.2, < 5.0)
|
17
|
+
bump (0.8.0)
|
18
|
+
clipboard (1.3.3)
|
15
19
|
crack (0.4.3)
|
16
20
|
safe_yaml (~> 1.0.0)
|
17
21
|
diff-lcs (1.3)
|
18
22
|
domain_name (0.5.20190701)
|
19
23
|
unf (>= 0.0.5, < 1.0.0)
|
20
|
-
|
24
|
+
ffi (1.11.3)
|
25
|
+
fuubar (2.5.0)
|
21
26
|
rspec-core (~> 3.0)
|
22
27
|
ruby-progressbar (~> 1.4)
|
23
|
-
hashdiff (0.
|
28
|
+
hashdiff (1.0.0)
|
24
29
|
http-accept (1.7.0)
|
25
30
|
http-cookie (1.0.3)
|
26
31
|
domain_name (~> 0.5)
|
27
|
-
|
32
|
+
io-console (0.5.4)
|
33
|
+
mime-types (3.3.1)
|
28
34
|
mime-types-data (~> 3.2015)
|
29
35
|
mime-types-data (3.2019.1009)
|
30
36
|
netrc (0.11.0)
|
31
|
-
public_suffix (
|
37
|
+
public_suffix (4.0.3)
|
32
38
|
rake (10.5.0)
|
39
|
+
readline (0.0.2)
|
40
|
+
reline
|
41
|
+
reline (0.1.2)
|
42
|
+
io-console (~> 0.5)
|
33
43
|
rest-client (2.1.0)
|
34
44
|
http-accept (>= 1.7.0, < 2.0)
|
35
45
|
http-cookie (>= 1.0.2, < 2.0)
|
36
46
|
mime-types (>= 1.16, < 4.0)
|
37
47
|
netrc (~> 0.8)
|
38
|
-
rspec (3.
|
39
|
-
rspec-core (~> 3.
|
40
|
-
rspec-expectations (~> 3.
|
41
|
-
rspec-mocks (~> 3.
|
42
|
-
rspec-core (3.
|
43
|
-
rspec-support (~> 3.
|
44
|
-
rspec-expectations (3.
|
48
|
+
rspec (3.9.0)
|
49
|
+
rspec-core (~> 3.9.0)
|
50
|
+
rspec-expectations (~> 3.9.0)
|
51
|
+
rspec-mocks (~> 3.9.0)
|
52
|
+
rspec-core (3.9.1)
|
53
|
+
rspec-support (~> 3.9.1)
|
54
|
+
rspec-expectations (3.9.0)
|
45
55
|
diff-lcs (>= 1.2.0, < 2.0)
|
46
|
-
rspec-support (~> 3.
|
47
|
-
rspec-mocks (3.
|
56
|
+
rspec-support (~> 3.9.0)
|
57
|
+
rspec-mocks (3.9.1)
|
48
58
|
diff-lcs (>= 1.2.0, < 2.0)
|
49
|
-
rspec-support (~> 3.
|
50
|
-
rspec-support (3.
|
59
|
+
rspec-support (~> 3.9.0)
|
60
|
+
rspec-support (3.9.2)
|
51
61
|
rspec_junit_formatter (0.4.1)
|
52
62
|
rspec-core (>= 2, < 4, != 2.12.0)
|
53
|
-
ruby-progressbar (1.10.
|
54
|
-
|
63
|
+
ruby-progressbar (1.10.1)
|
64
|
+
rufo (0.8.1)
|
65
|
+
safe_yaml (1.0.5)
|
55
66
|
terminal-table (1.8.0)
|
56
67
|
unicode-display_width (~> 1.1, >= 1.1.1)
|
57
68
|
thor (0.20.3)
|
@@ -59,11 +70,11 @@ GEM
|
|
59
70
|
unf_ext
|
60
71
|
unf_ext (0.0.7.6)
|
61
72
|
unicode-display_width (1.6.0)
|
62
|
-
vcr (
|
63
|
-
webmock (3.
|
73
|
+
vcr (5.0.0)
|
74
|
+
webmock (3.7.6)
|
64
75
|
addressable (>= 2.3.6)
|
65
76
|
crack (>= 0.3.2)
|
66
|
-
hashdiff
|
77
|
+
hashdiff (>= 0.4.0, < 2.0.0)
|
67
78
|
|
68
79
|
PLATFORMS
|
69
80
|
ruby
|
@@ -76,8 +87,9 @@ DEPENDENCIES
|
|
76
87
|
rake (~> 10.0)
|
77
88
|
rspec
|
78
89
|
rspec_junit_formatter
|
90
|
+
rufo
|
79
91
|
vcr
|
80
92
|
webmock
|
81
93
|
|
82
94
|
BUNDLED WITH
|
83
|
-
2.
|
95
|
+
2.1.4
|
data/Makefile
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# enfcli
|
2
2
|
|
3
|
-
|
3
|
+
The `enfcli` - Xaptum's CLI tool - allows you to easily manage your ENF resources. Check out [the docs](https://docs.xaptum.com/api) for examples of the various `enfcli` commands available for you to use.
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -24,16 +24,62 @@ $ gem install enfcli --pre
|
|
24
24
|
|
25
25
|
## Usage
|
26
26
|
|
27
|
-
|
27
|
+
There are two ways to connect to the ENF through the `enfcli`.
|
28
|
+
|
29
|
+
1. Configuration file
|
30
|
+
|
31
|
+
The recommended way to connect to the ENF through the `enfcli` is by creating a configuration file (`.xaptum_config.json`) in your home directory. The `enfcli` will read your configuration from this file whenever you attempt to connect, and will save you from entering in your `host` and `username` parameters each time. The following command creates a config file in your home directory.
|
32
|
+
|
33
|
+
```
|
34
|
+
$ enfcli create-config-file --host=<HOST> --user=<USERNAME>
|
35
|
+
Config file created successfully at /Users/dylanirlbeck/.xaptum_config.json!
|
36
|
+
```
|
37
|
+
|
38
|
+
You can view your current configuration at any time by doing the following:
|
39
|
+
|
40
|
+
```
|
41
|
+
$ enfcli display-config-file
|
42
|
+
{"host":<HOST>,"user":<USERNAME>}
|
43
|
+
```
|
44
|
+
|
45
|
+
With your configuration file created, connect to the ENF by simply doing
|
46
|
+
```
|
47
|
+
$ enfcli
|
48
|
+
Connecting to <HOST>.....
|
49
|
+
Enter Password: <PASSWORD>
|
50
|
+
```
|
51
|
+
|
52
|
+
2. CLI parameters
|
53
|
+
|
54
|
+
Instead of a configuration file, you can always connect to the ENF through the `enfcli` by providing your host and username as command line parameters
|
55
|
+
|
56
|
+
```bash
|
57
|
+
$ enfcli --host <host> --user <user>
|
58
|
+
```
|
59
|
+
|
60
|
+
Whichever way you choose, you'll be prompted for your account password as the final step of authentication. Once authenticated, type `help` in `enfcli` prompt to list all available `enfcli` commands
|
61
|
+
|
62
|
+
```bash
|
63
|
+
enfcli-user@acme> help
|
64
|
+
```
|
65
|
+
|
66
|
+
## Development
|
67
|
+
- Clone the repository
|
68
|
+
- Create a new branch
|
28
69
|
```bash
|
29
|
-
|
70
|
+
git checkout -b <GIT_USER_NAME>/<BRANCH_NAME>
|
30
71
|
```
|
31
|
-
|
32
|
-
|
72
|
+
- Bump the version
|
33
73
|
```bash
|
34
|
-
|
74
|
+
make bump-pre
|
75
|
+
```
|
76
|
+
- Ensure code is formatted using `rufo`. The build process will fail if the code is not formatted.
|
77
|
+
```bash
|
78
|
+
make format
|
35
79
|
```
|
36
80
|
|
81
|
+
**NOTE: Do not fork the repository**
|
82
|
+
|
37
83
|
## Release
|
38
84
|
`enfcli` pre-release and release versions are automatically published to [RubyGems](https://rubygems.org) by the build process. Each commit to `master` branch publishes a pre-release version of the gem.
|
39
85
|
|
@@ -64,4 +110,3 @@ distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
64
110
|
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
65
111
|
License for the specific language governing permissions and limitations under
|
66
112
|
the License.
|
67
|
-
|
data/enfcli.gemspec
CHANGED
@@ -1,16 +1,15 @@
|
|
1
1
|
# coding: utf-8
|
2
|
-
lib = File.expand_path(
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require
|
4
|
+
require "enfcli/version"
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name
|
8
|
-
spec.version
|
9
|
-
spec.authors
|
10
|
-
spec.email
|
11
|
-
|
12
|
-
spec.
|
13
|
-
spec.homepage = "https://www.xaptum.com"
|
7
|
+
spec.name = "enfcli"
|
8
|
+
spec.version = EnfCli::VERSION
|
9
|
+
spec.authors = ["Venkatakumar Srinivasan"]
|
10
|
+
spec.email = ["venkat@xaptum.com"]
|
11
|
+
spec.summary = "Xaptum ENF CLI."
|
12
|
+
spec.homepage = "https://www.xaptum.com"
|
14
13
|
|
15
14
|
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
16
15
|
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
@@ -20,27 +19,30 @@ Gem::Specification.new do |spec|
|
|
20
19
|
# raise "RubyGems 2.0 or newer is required to protect against " \
|
21
20
|
# "public gem pushes."
|
22
21
|
#end
|
23
|
-
|
24
|
-
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
22
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
25
23
|
f.match(%r{^(test|spec|features)/})
|
26
24
|
end
|
27
|
-
|
28
|
-
spec.
|
25
|
+
|
26
|
+
spec.bindir = "bin"
|
27
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
29
28
|
spec.require_paths = ["lib"]
|
30
29
|
|
31
|
-
spec.add_dependency
|
32
|
-
spec.add_dependency
|
33
|
-
spec.add_dependency
|
30
|
+
spec.add_dependency("thor", "~> 0.20.0")
|
31
|
+
spec.add_dependency("rest-client", "~> 2.0")
|
32
|
+
spec.add_dependency("terminal-table")
|
33
|
+
spec.add_dependency("clipboard")
|
34
|
+
spec.add_dependency("ffi")
|
35
|
+
spec.add_dependency("readline")
|
36
|
+
|
34
37
|
#spec.add_dependency "websocket-client-simple"
|
35
38
|
#spec.add_dependency "colorize"
|
36
|
-
|
37
|
-
spec.add_development_dependency "
|
38
|
-
spec.add_development_dependency
|
39
|
-
spec.add_development_dependency
|
40
|
-
spec.add_development_dependency
|
41
|
-
spec.add_development_dependency
|
42
|
-
spec.add_development_dependency
|
43
|
-
spec.add_development_dependency
|
44
|
-
spec.add_development_dependency
|
45
|
-
|
39
|
+
spec.add_development_dependency("bundler")
|
40
|
+
spec.add_development_dependency("rake", "~> 10.0")
|
41
|
+
spec.add_development_dependency("bump")
|
42
|
+
spec.add_development_dependency("rspec")
|
43
|
+
spec.add_development_dependency("rspec_junit_formatter")
|
44
|
+
spec.add_development_dependency("fuubar")
|
45
|
+
spec.add_development_dependency("vcr")
|
46
|
+
spec.add_development_dependency("webmock")
|
47
|
+
spec.add_development_dependency("rufo")
|
46
48
|
end
|
data/format.sh
ADDED
data/lib/enfapi.rb
CHANGED
@@ -13,11 +13,11 @@
|
|
13
13
|
# See the License for the specific language governing permissions and
|
14
14
|
# limitations under the License.
|
15
15
|
#
|
16
|
-
require
|
17
|
-
require
|
18
|
-
require
|
19
|
-
require
|
20
|
-
require
|
16
|
+
require "rest-client"
|
17
|
+
require "singleton"
|
18
|
+
require "json"
|
19
|
+
require "date"
|
20
|
+
require "cgi"
|
21
21
|
|
22
22
|
#
|
23
23
|
# NOTE: When api's are refactored into individual classes
|
@@ -26,13 +26,12 @@ require 'cgi'
|
|
26
26
|
#
|
27
27
|
|
28
28
|
module EnfApi
|
29
|
-
|
30
29
|
def self.to_json(hash)
|
31
30
|
JSON.generate(hash)
|
32
31
|
end
|
33
32
|
|
34
33
|
def self.url_encode(str)
|
35
|
-
CGI.escape(
|
34
|
+
CGI.escape(str).gsub("+", "%20")
|
36
35
|
end
|
37
36
|
|
38
37
|
class ERROR < StandardError
|
@@ -118,7 +117,6 @@ module EnfApi
|
|
118
117
|
def delete_dns_record(record_id)
|
119
118
|
EnfApi::API.instance.delete "#{@xdns_base_url}/records/#{record_id}"
|
120
119
|
end
|
121
|
-
|
122
120
|
end
|
123
121
|
|
124
122
|
class Firewall
|
@@ -188,7 +186,6 @@ module EnfApi
|
|
188
186
|
json = EnfApi::to_json(credentials)
|
189
187
|
EnfApi::API.instance.post "/api/xiam/v1/endpoints/#{ipv6}/credentials", json
|
190
188
|
end
|
191
|
-
|
192
189
|
end
|
193
190
|
|
194
191
|
##############################################################################
|
@@ -229,13 +226,13 @@ module EnfApi
|
|
229
226
|
## NO_TEST
|
230
227
|
def create_device(new_dev_hash)
|
231
228
|
json = EnfApi.to_json(new_dev_hash)
|
232
|
-
EnfApi::API.instance.post
|
229
|
+
EnfApi::API.instance.post "/api/captive/v1/device", json
|
233
230
|
end
|
234
231
|
|
235
232
|
# Get the list of devices
|
236
233
|
## NO_TEST
|
237
234
|
def list_devices(network)
|
238
|
-
url =
|
235
|
+
url = "/api/captive/v1/device"
|
239
236
|
url = "#{url}?#{network}" if network
|
240
237
|
EnfApi::API.instance.get url
|
241
238
|
end
|
@@ -253,7 +250,6 @@ module EnfApi
|
|
253
250
|
EnfApi::API.instance.put "/api/captive/v1/device/#{id}", json
|
254
251
|
end
|
255
252
|
|
256
|
-
|
257
253
|
# Get the status of a device
|
258
254
|
## NO_TEST
|
259
255
|
def get_device_status(dev_id)
|
@@ -267,7 +263,6 @@ module EnfApi
|
|
267
263
|
EnfApi::API.instance.post "/api/captive/v1/profile", json
|
268
264
|
end
|
269
265
|
|
270
|
-
|
271
266
|
# Get the list of profiles
|
272
267
|
# name is a substring of the profile names to be returned
|
273
268
|
## NO_TEST
|
@@ -279,13 +274,13 @@ module EnfApi
|
|
279
274
|
|
280
275
|
# Get detail on a specific profile
|
281
276
|
## NO_TEST
|
282
|
-
def get_profile
|
277
|
+
def get_profile(profile_id)
|
283
278
|
EnfApi::API.instance.get "/api/captive/v1/profile/#{profile_id}"
|
284
279
|
end
|
285
280
|
|
286
281
|
# Send update PUT request for profile
|
287
282
|
## NO_TEST
|
288
|
-
def update_profile
|
283
|
+
def update_profile(id, profile_updates)
|
289
284
|
json = EnfApi.to_json(profile_updates)
|
290
285
|
EnfApi::API.instance.put "/api/captive/v1/profile/#{id}", json
|
291
286
|
end
|
@@ -312,10 +307,10 @@ module EnfApi
|
|
312
307
|
|
313
308
|
# Create request json
|
314
309
|
hash = { :username => user, :token => password }
|
315
|
-
json = to_json(
|
310
|
+
json = to_json(hash)
|
316
311
|
|
317
312
|
# call api
|
318
|
-
@api["/api/xcr/v2/xauth"].post(
|
313
|
+
@api["/api/xcr/v2/xauth"].post(json, { content_type: :json, accept: :json }) { |response, request, result|
|
319
314
|
case response.code
|
320
315
|
when 200
|
321
316
|
# get resp from json
|
@@ -323,7 +318,7 @@ module EnfApi
|
|
323
318
|
|
324
319
|
# set request headers for subsequent api calls
|
325
320
|
token = resp[:data][0][:token]
|
326
|
-
@headers = {content_type: :json, accept: :json, "Authorization" => "Bearer #{token}"}
|
321
|
+
@headers = { content_type: :json, accept: :json, "Authorization" => "Bearer #{token}" }
|
327
322
|
|
328
323
|
# return resp
|
329
324
|
resp
|
@@ -334,80 +329,80 @@ module EnfApi
|
|
334
329
|
end
|
335
330
|
|
336
331
|
def get(request_uri)
|
337
|
-
@api[request_uri].get(@headers) {|response, request, result|
|
332
|
+
@api[request_uri].get(@headers) { |response, request, result|
|
338
333
|
process_api_response response, request, result
|
339
334
|
}
|
340
335
|
end
|
341
336
|
|
342
|
-
def post(request_uri, request_body =
|
343
|
-
@api[request_uri].post(request_body, @headers) {|response, request, result|
|
337
|
+
def post(request_uri, request_body = "")
|
338
|
+
@api[request_uri].post(request_body, @headers) { |response, request, result|
|
344
339
|
process_api_response response, request, result
|
345
340
|
}
|
346
341
|
end
|
347
342
|
|
348
|
-
def put(request_uri, request_body =
|
349
|
-
@api[request_uri].put(request_body, @headers) {|response, request, result|
|
343
|
+
def put(request_uri, request_body = "")
|
344
|
+
@api[request_uri].put(request_body, @headers) { |response, request, result|
|
350
345
|
process_api_response response, request, result
|
351
346
|
}
|
352
347
|
end
|
353
348
|
|
354
349
|
def delete(request_uri)
|
355
|
-
@api[request_uri].delete(@headers) {|response, request, result|
|
350
|
+
@api[request_uri].delete(@headers) { |response, request, result|
|
356
351
|
process_api_response response, request, result
|
357
352
|
}
|
358
353
|
end
|
359
354
|
|
360
|
-
############################################################################################################################
|
361
|
-
# NOT READY API. MOVE ABOVE THIS LINE AFTER RSPEC OR INTO OWN CLASS
|
362
|
-
############################################################################################################################
|
355
|
+
############################################################################################################################
|
356
|
+
# NOT READY API. MOVE ABOVE THIS LINE AFTER RSPEC OR INTO OWN CLASS
|
357
|
+
############################################################################################################################
|
363
358
|
def list_domain_nws(domain_id)
|
364
|
-
@api["/api/xcr/v2/domains/#{domain_id}/nws"].get(@headers) {|response, request, result|
|
359
|
+
@api["/api/xcr/v2/domains/#{domain_id}/nws"].get(@headers) { |response, request, result|
|
365
360
|
process_api_response response, request, result
|
366
361
|
}
|
367
362
|
end
|
368
363
|
|
369
364
|
def list_enfnws
|
370
|
-
@api["/api/xcr/v2/enfnws"].get(
|
365
|
+
@api["/api/xcr/v2/enfnws"].get(@headers) { |response, request, result|
|
371
366
|
process_api_response response, request, result
|
372
367
|
}
|
373
368
|
end
|
374
369
|
|
375
370
|
def list_domains
|
376
|
-
@api["/api/xcr/v2/domains"].get(
|
371
|
+
@api["/api/xcr/v2/domains"].get(@headers) { |response, request, result|
|
377
372
|
process_api_response response, request, result
|
378
373
|
}
|
379
374
|
end
|
380
375
|
|
381
376
|
def get_domain(domain_id)
|
382
|
-
@api["/api/xcr/v2/domains/#{domain_id}"].get(
|
377
|
+
@api["/api/xcr/v2/domains/#{domain_id}"].get(@headers) { |response, request, result|
|
383
378
|
process_api_response response, request, result
|
384
379
|
}
|
385
380
|
end
|
386
381
|
|
387
382
|
def create_domain(domain_hash)
|
388
|
-
json = to_json(
|
389
|
-
@api["/api/xcr/v2/domains"].post(
|
383
|
+
json = to_json(domain_hash)
|
384
|
+
@api["/api/xcr/v2/domains"].post(json, @headers) { |response, request, result|
|
390
385
|
process_api_response response, request, result
|
391
386
|
}
|
392
387
|
end
|
393
388
|
|
394
389
|
def update_domain_rate_limits(domain_network, limit, limits_hash)
|
395
|
-
json = to_json(
|
396
|
-
@api["/api/xcr/v2/domains/#{domain_network}/ep_rate_limits/#{limit}"].put(
|
390
|
+
json = to_json(limits_hash)
|
391
|
+
@api["/api/xcr/v2/domains/#{domain_network}/ep_rate_limits/#{limit}"].put(json, @headers) { |response, request, result|
|
397
392
|
process_api_response response, request, result
|
398
393
|
}
|
399
394
|
end
|
400
395
|
|
401
396
|
def update_network_rate_limits(network, limit, limits_hash)
|
402
|
-
json = to_json(
|
403
|
-
@api["/api/xcr/v2/nws/#{network}/ep_rate_limits/#{limit}"].put(
|
397
|
+
json = to_json(limits_hash)
|
398
|
+
@api["/api/xcr/v2/nws/#{network}/ep_rate_limits/#{limit}"].put(json, @headers) { |response, request, result|
|
404
399
|
process_api_response response, request, result
|
405
400
|
}
|
406
401
|
end
|
407
402
|
|
408
403
|
def update_ep_rate_limits(ipv6, limit, limits_hash)
|
409
|
-
json = to_json(
|
410
|
-
@api["/api/xcr/v2/cxns/#{ipv6}/ep_rate_limits/#{limit}"].put(
|
404
|
+
json = to_json(limits_hash)
|
405
|
+
@api["/api/xcr/v2/cxns/#{ipv6}/ep_rate_limits/#{limit}"].put(json, @headers) { |response, request, result|
|
411
406
|
process_api_response response, request, result
|
412
407
|
}
|
413
408
|
end
|
@@ -416,7 +411,7 @@ module EnfApi
|
|
416
411
|
api_url = "/api/xcr/v2/domains/#{domain_network}/ep_rate_limits"
|
417
412
|
api_url = "#{api_url}/#{filter}" if filter
|
418
413
|
|
419
|
-
@api[api_url].get(
|
414
|
+
@api[api_url].get(@headers) { |response, request, result|
|
420
415
|
process_api_response response, request, result
|
421
416
|
}
|
422
417
|
end
|
@@ -425,7 +420,7 @@ module EnfApi
|
|
425
420
|
api_url = "/api/xcr/v2/nws/#{network}/ep_rate_limits"
|
426
421
|
api_url = "#{api_url}/#{filter}" if filter
|
427
422
|
|
428
|
-
@api[api_url].get(
|
423
|
+
@api[api_url].get(@headers) { |response, request, result|
|
429
424
|
process_api_response response, request, result
|
430
425
|
}
|
431
426
|
end
|
@@ -434,14 +429,14 @@ module EnfApi
|
|
434
429
|
api_url = "/api/xcr/v2/cxns/#{ipv6}/ep_rate_limits"
|
435
430
|
api_url = "#{api_url}/#{filter}" if filter
|
436
431
|
|
437
|
-
@api[api_url].get(
|
432
|
+
@api[api_url].get(@headers) { |response, request, result|
|
438
433
|
process_api_response response, request, result
|
439
434
|
}
|
440
435
|
end
|
441
436
|
|
442
437
|
def update_domain_status(domain_network, status)
|
443
438
|
json = to_json(status)
|
444
|
-
@api["/api/xcr/v2/domains/#{domain_network}/status"].put(json, @headers) {|response, request, result|
|
439
|
+
@api["/api/xcr/v2/domains/#{domain_network}/status"].put(json, @headers) { |response, request, result|
|
445
440
|
process_api_response response, request, result
|
446
441
|
}
|
447
442
|
end
|
@@ -449,145 +444,139 @@ module EnfApi
|
|
449
444
|
def create_nw(nw_hash)
|
450
445
|
json = to_json(nw_hash)
|
451
446
|
domain_id = nw_hash[:domain_id]
|
452
|
-
@api["/api/xcr/v2/domains/#{domain_id}/nws"].post(json, @headers) {|response, request, result|
|
447
|
+
@api["/api/xcr/v2/domains/#{domain_id}/nws"].post(json, @headers) { |response, request, result|
|
453
448
|
process_api_response response, request, result
|
454
449
|
}
|
455
450
|
end
|
456
451
|
|
457
452
|
def update_nw(network_cidr, nw_hash)
|
458
453
|
json = to_json(nw_hash)
|
459
|
-
@api["/api/xcr/v2/nws/#{network_cidr}"].put(json, @headers) {|response, request, result|
|
454
|
+
@api["/api/xcr/v2/nws/#{network_cidr}"].put(json, @headers) { |response, request, result|
|
460
455
|
process_api_response response, request, result
|
461
456
|
}
|
462
457
|
end
|
463
458
|
|
464
459
|
def get_nw(network_cidr)
|
465
|
-
@api["/api/xcr/v2/nws/#{network_cidr}"].get(@headers) {|response, request, result|
|
460
|
+
@api["/api/xcr/v2/nws/#{network_cidr}"].get(@headers) { |response, request, result|
|
466
461
|
process_api_response response, request, result
|
467
462
|
}
|
468
463
|
end
|
469
464
|
|
470
465
|
def list_nw_connections(domain_id, network_cidr, file = nil)
|
471
|
-
@api["/api/xcr/v2/domains/#{domain_id}/nws/#{network_cidr}/cxns"].get(@headers) {|response, request, result|
|
466
|
+
@api["/api/xcr/v2/domains/#{domain_id}/nws/#{network_cidr}/cxns"].get(@headers) { |response, request, result|
|
472
467
|
process_api_response response, request, result
|
473
468
|
}
|
474
469
|
end
|
475
470
|
|
476
471
|
def list_endpoint_events(ipv6)
|
477
|
-
@api["/api/xcr/v2/cxns/#{ipv6}/events"].get(@headers) {|response, request, result|
|
472
|
+
@api["/api/xcr/v2/cxns/#{ipv6}/events"].get(@headers) { |response, request, result|
|
478
473
|
process_api_response response, request, result
|
479
474
|
}
|
480
475
|
end
|
481
476
|
|
482
477
|
def list_network_events(network_cidr)
|
483
|
-
@api["/api/xcr/v2/nws/#{network_cidr}/events"].get(@headers) {|response, request, result|
|
478
|
+
@api["/api/xcr/v2/nws/#{network_cidr}/events"].get(@headers) { |response, request, result|
|
484
479
|
process_api_response response, request, result
|
485
480
|
}
|
486
481
|
end
|
487
482
|
|
488
483
|
def get_endpoint(ipv6)
|
489
|
-
@api["/api/xcr/v2/cxns/#{ipv6}"].get(@headers) {|response, request, result|
|
484
|
+
@api["/api/xcr/v2/cxns/#{ipv6}"].get(@headers) { |response, request, result|
|
490
485
|
process_api_response response, request, result
|
491
486
|
}
|
492
487
|
end
|
493
488
|
|
494
489
|
def update_endpoint(ipv6, name)
|
495
490
|
hash = { :ipv6 => ipv6, :name => name }
|
496
|
-
json = to_json(
|
491
|
+
json = to_json(hash)
|
497
492
|
|
498
|
-
@api["/api/xcr/v2/cxns/#{ipv6}"].put(
|
493
|
+
@api["/api/xcr/v2/cxns/#{ipv6}"].put(json, @headers) { |response, request, result|
|
499
494
|
process_api_response response, request, result
|
500
495
|
}
|
501
496
|
end
|
502
497
|
|
503
498
|
def activate_enfnw(subnet)
|
504
|
-
@api["/api/xcr/v2/enfnws/#{subnet}"].put(
|
499
|
+
@api["/api/xcr/v2/enfnws/#{subnet}"].put("", @headers) { |response, request, result|
|
505
500
|
process_api_response response, request, result
|
506
501
|
}
|
507
502
|
end
|
508
503
|
|
509
504
|
def list_domain_users(domain_network)
|
510
|
-
@api["/api/xcr/v2/domains/#{domain_network}/users"].get(
|
505
|
+
@api["/api/xcr/v2/domains/#{domain_network}/users"].get(@headers) { |response, request, result|
|
511
506
|
process_api_response response, request, result
|
512
507
|
}
|
513
508
|
end
|
514
509
|
|
515
510
|
def list_domain_invites(domain_network)
|
516
|
-
@api["/api/xcr/v2/domains/#{domain_network}/invites"].get(@headers) {|response, request, result|
|
511
|
+
@api["/api/xcr/v2/domains/#{domain_network}/invites"].get(@headers) { |response, request, result|
|
517
512
|
process_api_response response, request, result
|
518
513
|
}
|
519
514
|
end
|
520
515
|
|
521
516
|
def invite(domain_network, hash)
|
522
|
-
json = to_json(
|
523
|
-
@api["/api/xcr/v2/domains/#{domain_network}/invites"].post(
|
517
|
+
json = to_json(hash)
|
518
|
+
@api["/api/xcr/v2/domains/#{domain_network}/invites"].post(json, @headers) { |response, request, result|
|
524
519
|
process_api_response response, request, result
|
525
520
|
}
|
526
521
|
end
|
527
522
|
|
528
523
|
def cancel_invite(email)
|
529
|
-
@api["/api/xcr/v2/invites/#{email}"].delete(
|
524
|
+
@api["/api/xcr/v2/invites/#{email}"].delete(@headers) { |response, request, result|
|
530
525
|
process_api_response response, request, result
|
531
526
|
}
|
532
527
|
end
|
533
528
|
|
534
529
|
def resend_invite(email)
|
535
|
-
@api["/api/xcr/v2/invites/#{email}"].put(
|
530
|
+
@api["/api/xcr/v2/invites/#{email}"].put("{}", @headers) { |response, request, result|
|
536
531
|
process_api_response response, request, result
|
537
532
|
}
|
538
533
|
end
|
539
534
|
|
540
535
|
def update_user_status(user_id, status)
|
541
|
-
json = to_json(
|
542
|
-
@api["/api/xcr/v2/users/#{user_id}/status"].put(
|
536
|
+
json = to_json(status)
|
537
|
+
@api["/api/xcr/v2/users/#{user_id}/status"].put(json, @headers) { |response, request, result|
|
543
538
|
process_api_response response, request, result
|
544
539
|
}
|
545
540
|
end
|
546
541
|
|
547
|
-
############################################################################################################################
|
548
|
-
# Private functions
|
549
|
-
############################################################################################################################
|
542
|
+
############################################################################################################################
|
543
|
+
# Private functions
|
544
|
+
############################################################################################################################
|
550
545
|
def process_api_response(response, request, result)
|
551
546
|
case response.code
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
547
|
+
when 200
|
548
|
+
# return json
|
549
|
+
from_json(response.body)
|
550
|
+
when 201
|
551
|
+
# return response body
|
552
|
+
from_json(response.body)
|
553
|
+
when 400
|
554
|
+
# api returns and error
|
555
|
+
raise EnfApi::ERROR, api_error_msg(from_json(response.body))
|
556
|
+
when 401
|
557
|
+
# api returns and error
|
558
|
+
raise EnfApi::ERROR, api_error_msg(from_json(response.body))
|
559
|
+
when 403
|
560
|
+
# api returns and error
|
561
|
+
raise EnfApi::ERROR, "AUTHORIZATION_ERROR: User is not authorized to perform this operation!"
|
562
|
+
when 404
|
563
|
+
# api returns an error
|
564
|
+
# for the 404, we're going to check if it is JSON before parsing the
|
565
|
+
# error message
|
566
|
+
begin
|
567
|
+
JSON.parse(response.body)
|
566
568
|
raise EnfApi::ERROR, api_error_msg(from_json(response.body))
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
|
572
|
-
when 404
|
573
|
-
# api returns an error
|
574
|
-
# for the 404, we're going to check if it is JSON before parsing the
|
575
|
-
# error message
|
576
|
-
begin
|
577
|
-
JSON.parse(response.body)
|
578
|
-
raise EnfApi::ERROR, api_error_msg(from_json(response.body))
|
579
|
-
rescue JSON::ParserError => e
|
580
|
-
raise EnfApi::ERROR, "Not Found"
|
581
|
-
end
|
582
|
-
|
583
|
-
else
|
584
|
-
raise EnfApi::ERROR, "Unexpected error! Please try again!"
|
569
|
+
rescue JSON::ParserError => e
|
570
|
+
raise EnfApi::ERROR, "Not Found"
|
571
|
+
end
|
572
|
+
else
|
573
|
+
raise EnfApi::ERROR, "Unexpected error! Please try again!"
|
585
574
|
end
|
586
575
|
end
|
587
576
|
|
588
577
|
def from_json(string)
|
589
578
|
begin
|
590
|
-
JSON.parse(string, {:symbolize_names => true})
|
579
|
+
JSON.parse(string, { :symbolize_names => true })
|
591
580
|
rescue
|
592
581
|
raise EnfApi::ERROR, "Unable to parse api response json!"
|
593
582
|
end
|