s2_netbox 0.0.1.pre
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.rspec +2 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +157 -0
- data/Rakefile +6 -0
- data/bin/console +13 -0
- data/bin/setup +8 -0
- data/circle.yml +3 -0
- data/lib/s2_netbox/api_request.rb +75 -0
- data/lib/s2_netbox/api_response.rb +22 -0
- data/lib/s2_netbox/commands/api_version.rb +7 -0
- data/lib/s2_netbox/commands/authentication.rb +11 -0
- data/lib/s2_netbox/commands/credential.rb +3 -0
- data/lib/s2_netbox/commands/person.rb +40 -0
- data/lib/s2_netbox/commands.rb +3 -0
- data/lib/s2_netbox/configuration.rb +55 -0
- data/lib/s2_netbox/error.rb +6 -0
- data/lib/s2_netbox/errors/configuration_error.rb +2 -0
- data/lib/s2_netbox/helpers.rb +16 -0
- data/lib/s2_netbox/version.rb +3 -0
- data/lib/s2_netbox.rb +58 -0
- data/s2_netbox.gemspec +33 -0
- metadata +209 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 55443e3415036a124d1b1501115d3e3b7535e58f
|
4
|
+
data.tar.gz: 24205f66709d5862b25c92dc26e21cfb4c4a3eb4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 689d3c3d2d1cd1f8dff87625d3fa26c1e2ff52d72dbf962e3485a5e3bcc70a6a3c7fec6db4ace1bca66015b8299cb96ab4a94ae8e323c08d008773d371c4d3d9
|
7
|
+
data.tar.gz: e0eb5a19555ec1278f667908aef345246de75faa8f630af6df56045daf51d5182a00869e255720026d523272e7b62b8fb6d6d4a06420c5bdeb5b0c4340190795
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Michael Shimmins
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,157 @@
|
|
1
|
+
[![CircleCI](https://circleci.com/gh/teamsquare/s2_netbox/tree/develop.svg?style=svg)](https://circleci.com/gh/teamsquare/s2_netbox/tree/develop)
|
2
|
+
[![Code Climate](https://codeclimate.com/github/teamsquare/s2_netbox/badges/gpa.svg)](https://codeclimate.com/github/teamsquare/s2_netbox)
|
3
|
+
[![Test Coverage](https://codeclimate.com/github/teamsquare/s2_netbox/badges/coverage.svg)](https://codeclimate.com/github/teamsquare/s2_netbox/coverage)
|
4
|
+
[![Issue Count](https://codeclimate.com/github/teamsquare/s2_netbox/badges/issue_count.svg)](https://codeclimate.com/github/teamsquare/s2_netbox)
|
5
|
+
|
6
|
+
This gem provides Ruby bindings to the [S2 NetBox](http://s2sys.com/products/access-control-systems/netbox/) API for [S2 Security Systems](http://s2sys.com/) products.
|
7
|
+
# Currently Supported API methods
|
8
|
+
This Gem has been written pretty specifically for the needs of Teamsquare's internal management systems.
|
9
|
+
Although every method **should** work if you follow the right conventions, only the specific ones we're using have been built out and tested.
|
10
|
+
|
11
|
+
The specific methods we're using have been documented under the Usage section. See the section "Other Commands" for details on how to invoke any arbitrary command in addition to the list of "supported" commands below.
|
12
|
+
|
13
|
+
# Installation
|
14
|
+
Add this line to your application's Gemfile:
|
15
|
+
|
16
|
+
gem 's2_netbox'
|
17
|
+
|
18
|
+
And then execute:
|
19
|
+
|
20
|
+
$ bundle
|
21
|
+
|
22
|
+
Or install it yourself as:
|
23
|
+
|
24
|
+
$ gem install s2_netbox
|
25
|
+
|
26
|
+
# Configuration
|
27
|
+
A call to `S2Netbox.configure` must be made before API requests can be made. This sets up the controller's base URL as well as the username and password used when logging in.
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
S2Netbox.configure do |config|
|
31
|
+
config.controller_url = 'https://controller-host'
|
32
|
+
config.username = 'api'
|
33
|
+
config.password = '[W2tnwoUdE+/97o8nmi#P77t'
|
34
|
+
end
|
35
|
+
```
|
36
|
+
If you're using the S2Netbox gem in a Rails app, this could be placed in an initializer.
|
37
|
+
# Usage
|
38
|
+
All requests are bundled up into the required XML parcel with the required `COMMAND` and `PARAMS`.
|
39
|
+
Once sent to the configured S2 controller, the response is wrapped up in an instance of `S2Netbox::Response` which includes the following accessors:
|
40
|
+
|
41
|
+
* `code`
|
42
|
+
* `success`
|
43
|
+
* `details`
|
44
|
+
* `error_message`
|
45
|
+
* `raw_request`
|
46
|
+
* `raw_response`
|
47
|
+
* `session_id`
|
48
|
+
|
49
|
+
`code` returns the raw code response which is typcially either `SUCCESS` or `FAIL`, but sometimes has weird other alternatives, such as `DUPLICATE` or `NOT FOUND` just to keep things interesting.
|
50
|
+
|
51
|
+
`success` is a boolean indicating if the `code` was `SUCCESS`. Any other value for `code` results in `success` being `false`.
|
52
|
+
|
53
|
+
`details` is a hash of the returned details. For example, when getting a Person object, this will contain the person's attributes, such as `FIRSTNAME` and `LASTNAME` as well as a hash of `ACCESSLEVELS`. The details hash is keyed off the raw names of the XML attributes in the response (uppercase names, as a string, not symbole) so access them like:
|
54
|
+
|
55
|
+
@result.details['FIRSTNAME']
|
56
|
+
|
57
|
+
not
|
58
|
+
|
59
|
+
@result.details[:first_name]
|
60
|
+
|
61
|
+
`error_message` is populated with the error mesage returned from the system assuming `code` is not `SUCCESS`.
|
62
|
+
|
63
|
+
The `raw_request` and `raw_response` store the contents of the HTTP Post request and response respectively, so you can troubleshoot exactly what XML was sent and received by the systems.
|
64
|
+
|
65
|
+
`session_id` contains the value of the `session_id` attribute if it exists on the root `<NETBOX>` element in the `raw_response`. This is only populated in response to the `Login` command. Use this when parsing the result of a `Login` attempt and store the `session_id` for future requests.
|
66
|
+
|
67
|
+
# Authentication
|
68
|
+
The gem supports authentication by username and password only. Although you can configure it to use the `sha_password` method of authentication, at pesent the MAC signature is not generated or included with any request.
|
69
|
+
|
70
|
+
If your S2 system requires authentication via the `sha_password` and MAC signing, feel free to open a pull request :) Our systems are partitioned and don't use this form of authentication, but we'd love to accept a pull request to add this fucntionaltiy for other users.
|
71
|
+
## Login
|
72
|
+
Login is used to establish a session and obtain a `session_id` which is used in subsequent requests:
|
73
|
+
|
74
|
+
@result = S2Netbox::Commands::Authentication.login
|
75
|
+
|
76
|
+
To get an instance of `S2Netbox::Response` which (assuming log in is succesful) will include the `session_id` which can be used in subsequent requests:
|
77
|
+
|
78
|
+
@result.session_id
|
79
|
+
|
80
|
+
## Logout
|
81
|
+
All sessions must be logged out. According to the S2 documentation:
|
82
|
+
|
83
|
+
> WARNING: Failure to match every call to ‘Login’ with a call to ‘Logout’ will result in the accumulation of session files, consuming potentially large amounts of disk space.
|
84
|
+
|
85
|
+
To log out, issue the `logout` command:
|
86
|
+
|
87
|
+
@result = S2Netbox::Commands::Authentication.logout('session_id_from_login')
|
88
|
+
|
89
|
+
# Version
|
90
|
+
The `Version` module allows you to query the current API version. This is really just an easy way to validate you're successfully connected to the S2 Controller and have a valid session.
|
91
|
+
## GetVersion
|
92
|
+
@result = S2Netbox::Commands::ApiVersion.get_version('session_id_from_login')
|
93
|
+
The result object will contain the version (assuming you've successfully logged in):
|
94
|
+
|
95
|
+
:001 > puts @result.details['APIVERSION']
|
96
|
+
4.1
|
97
|
+
|
98
|
+
# Person
|
99
|
+
The `Person` module allows you to add and modfy Pereson records.
|
100
|
+
## AddPerson
|
101
|
+
The `add_person` method accepts 3 arguments:
|
102
|
+
|
103
|
+
1. Hash of person attributes
|
104
|
+
1. List of access levels
|
105
|
+
1. List of User Defined Fields
|
106
|
+
1. (Optional) session_id
|
107
|
+
|
108
|
+
```ruby
|
109
|
+
@result = S2Netbox::Commands::Person.add({
|
110
|
+
:person_id => '8a806ed6-0246-49d0-b7a7-ab6402da01e3',
|
111
|
+
:first_name => 'John',
|
112
|
+
:last_name => 'Appleseed',
|
113
|
+
:exp_date => nil,
|
114
|
+
:act_date => '10/10/2016'
|
115
|
+
}, %w(AccessLevel1 AccessLevel2), 'UDF1'
|
116
|
+
)
|
117
|
+
```
|
118
|
+
Both access levels and user defined fields can be specified either as a single string or as an array of strings.
|
119
|
+
## ModifyPerson
|
120
|
+
The `modify_person` method allows you to modify an existing person, and is similar to the `add_person` method, but has an additional argument:
|
121
|
+
|
122
|
+
1. Person ID
|
123
|
+
1. Hash of person attributes
|
124
|
+
1. List of access levels
|
125
|
+
1. List of User Defined Fields
|
126
|
+
1. (Optional) session_id
|
127
|
+
|
128
|
+
```ruby
|
129
|
+
@result = S2Netbox::Commands::Person.modify('8a806ed6-0246-49d0-b7a7-ab6402da01e3', {
|
130
|
+
:first_name => 'John',
|
131
|
+
:last_name => 'Appleseed',
|
132
|
+
:exp_date => nil,
|
133
|
+
:act_date => '10/10/2016'
|
134
|
+
}, %w(AccessLevel1 AccessLevel2), 'UDF1')
|
135
|
+
```
|
136
|
+
Access levels and user defined fields are replaced with those values specified in this call, and aren't additive to existing access levels or user defined fields.
|
137
|
+
# Credentials
|
138
|
+
|
139
|
+
|
140
|
+
# Development
|
141
|
+
|
142
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
143
|
+
|
144
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
145
|
+
|
146
|
+
## Contributing
|
147
|
+
|
148
|
+
1. Fork it
|
149
|
+
1. Create your feature branch (`git checkout -b my-new-feature`)
|
150
|
+
1. Commit your changes (`git add -p ./path/to/files; git commit -m 'Add some feature'`)
|
151
|
+
1. Push to the branch (`git push origin my-new-feature`)
|
152
|
+
1. Create new Pull Request
|
153
|
+
|
154
|
+
# License
|
155
|
+
|
156
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
157
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
data/bin/setup
ADDED
data/circle.yml
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
require 'facets/string/titlecase'
|
2
|
+
|
3
|
+
class S2Netbox::ApiRequest
|
4
|
+
include S2Netbox::Helpers
|
5
|
+
|
6
|
+
def self.provides_command(*command_names)
|
7
|
+
define_singleton_method(:supported_operations) do
|
8
|
+
Array.wrap(command_names)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.send_request(command_name, attributes, session_id=nil)
|
13
|
+
S2Netbox.request(S2Netbox::BASIC_ENDPOINT, build_command(command_name, attributes), session_id)
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.method_missing(method_name, *arguments, &block)
|
17
|
+
return super unless supported_operations.include?(method_name)
|
18
|
+
|
19
|
+
send_request(command_for_method(method_name), map_attributes(arguments[0]), arguments[1])
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.respond_to_missing?(method_name, include_private = false)
|
23
|
+
return true if supported_operations.include?(method_name.to_s)
|
24
|
+
|
25
|
+
super
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.command_map
|
29
|
+
nil
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.supported_operations
|
33
|
+
[]
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.command_for_method(method_name)
|
37
|
+
if command_map && command_map[method_name]
|
38
|
+
return command_map[method_name]
|
39
|
+
else
|
40
|
+
return "#{method_name.to_s.gsub('_', ' ').titlecase.gsub(' ', '')}#{name.split('::').last}"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.build_params(params={})
|
45
|
+
res = '<PARAMS>'
|
46
|
+
|
47
|
+
params.each do |k, v|
|
48
|
+
if v.is_a?(Hash)
|
49
|
+
res << "<#{k.to_s}>"
|
50
|
+
|
51
|
+
singular = v[:singular_node_name]
|
52
|
+
|
53
|
+
v[:values].each do |inner_value|
|
54
|
+
res << "<#{singular}>#{inner_value}</#{singular}>"
|
55
|
+
end
|
56
|
+
|
57
|
+
res << "</#{k.to_s}>"
|
58
|
+
else
|
59
|
+
res << "<#{k.to_s}>#{v}</#{k.to_s}>"
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
res << '</PARAMS>'
|
64
|
+
end
|
65
|
+
|
66
|
+
def self.build_command(name, params=nil)
|
67
|
+
"<COMMAND name='#{name}' num='1'>#{params ? build_params(params) : ''}</COMMAND>"
|
68
|
+
end
|
69
|
+
|
70
|
+
def self.map_attributes(attributes)
|
71
|
+
return unless attributes
|
72
|
+
|
73
|
+
attributes.reject { |_,v| blank?(v) }.map { |k, v| [k.to_s.gsub('_', '').upcase, v] }.to_h
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'active_support/core_ext/hash'
|
2
|
+
|
3
|
+
class S2Netbox::ApiResponse
|
4
|
+
attr_accessor :code, :success, :details, :error_message, :raw_request, :raw_response, :session_id
|
5
|
+
|
6
|
+
def initialize(raw_request, raw_response)
|
7
|
+
response_hash = Hash.from_xml(raw_response)
|
8
|
+
|
9
|
+
@code = response_hash['NETBOX']['RESPONSE']['CODE']
|
10
|
+
@success = @code == 'SUCCESS'
|
11
|
+
@details = response_hash['NETBOX']['RESPONSE']['DETAILS']
|
12
|
+
@error_message = details['ERRMSG'] if details
|
13
|
+
|
14
|
+
@raw_request = raw_request
|
15
|
+
@raw_response = raw_response
|
16
|
+
@session_id = response_hash['NETBOX']['sessionid']
|
17
|
+
end
|
18
|
+
|
19
|
+
def successful?
|
20
|
+
@success
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
class S2Netbox::Commands::Authentication < S2Netbox::ApiRequest
|
2
|
+
include S2Netbox::Helpers
|
3
|
+
|
4
|
+
def self.login
|
5
|
+
S2Netbox.request(S2Netbox::BASIC_ENDPOINT, build_command('Login', {:'USERNAME' => S2Netbox.configuration.username, :'PASSWORD' => S2Netbox.configuration.password}))
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.logout(session_id)
|
9
|
+
S2Netbox.request(S2Netbox::BASIC_ENDPOINT, build_command('Logout'), session_id)
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
class S2Netbox::Commands::Person < S2Netbox::ApiRequest
|
2
|
+
include S2Netbox::Helpers
|
3
|
+
|
4
|
+
def self.add(attributes={}, access_levels=[], user_defined_fields=[], session_id=nil)
|
5
|
+
send_request('AddPerson', build_attributes(attributes, access_levels, user_defined_fields), session_id)
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.modify(person_id, attributes={}, access_levels=[], user_defined_fields=[], session_id=nil)
|
9
|
+
person_attributes = build_attributes(attributes, access_levels, user_defined_fields)
|
10
|
+
person_attributes['PERSONID'] = person_id
|
11
|
+
|
12
|
+
send_request('ModifyPerson', person_attributes, session_id)
|
13
|
+
end
|
14
|
+
|
15
|
+
protected
|
16
|
+
|
17
|
+
def self.build_attributes(attributes, access_levels, user_defined_fields)
|
18
|
+
hash = map_attributes(attributes)
|
19
|
+
hash = build_user_defined_fields(hash, user_defined_fields)
|
20
|
+
hash = build_access_level(hash, access_levels)
|
21
|
+
|
22
|
+
hash
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.build_access_level(hash, access_levels)
|
26
|
+
unless access_levels.empty?
|
27
|
+
hash['ACCESSLEVELS'] = {:singular_node_name => 'ACCESSLEVEL', :values => access_levels}
|
28
|
+
end
|
29
|
+
|
30
|
+
hash
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.build_user_defined_fields(hash, user_defined_fields)
|
34
|
+
Array.wrap(user_defined_fields).each_with_index do |udf, index|
|
35
|
+
hash["UDF#{index+1}"] = udf
|
36
|
+
end
|
37
|
+
|
38
|
+
hash
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
class S2Netbox::Configuration
|
2
|
+
include S2Netbox::Helpers
|
3
|
+
|
4
|
+
attr_accessor :controller_url
|
5
|
+
attr_accessor :sha_password
|
6
|
+
attr_accessor :username
|
7
|
+
attr_accessor :password
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
@controller_url = nil
|
11
|
+
@sha_password = nil
|
12
|
+
@username = nil
|
13
|
+
@password = nil
|
14
|
+
end
|
15
|
+
|
16
|
+
def sign_with_mac?
|
17
|
+
!blank?(sha_password)
|
18
|
+
end
|
19
|
+
|
20
|
+
def validate!
|
21
|
+
validate_controller_url!
|
22
|
+
|
23
|
+
if !blank?(sha_password) && (!blank?(username) || !blank?(password))
|
24
|
+
raise S2Netbox::Errors::ConfigurationError.new 'Must specify either sha_password or username and password (not both)'
|
25
|
+
end
|
26
|
+
|
27
|
+
if blank?(username) && blank?(password)
|
28
|
+
validate_sha_password!
|
29
|
+
else
|
30
|
+
validate_username_and_password!
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def validate_controller_url!
|
37
|
+
raise_error_unless(controller_url, 'Must specify sha_password')
|
38
|
+
end
|
39
|
+
|
40
|
+
def validate_sha_password!
|
41
|
+
raise_error_unless(sha_password, 'Must specify sha_password')
|
42
|
+
end
|
43
|
+
|
44
|
+
def validate_username_and_password!
|
45
|
+
if blank?(username) || blank?(password)
|
46
|
+
raise S2Netbox::Errors::ConfigurationError.new 'Must specify either sha_password or username and password'
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def raise_error_unless(value, message=nil)
|
51
|
+
if blank? value
|
52
|
+
raise S2Netbox::Errors::ConfigurationError.new message
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
data/lib/s2_netbox.rb
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
|
3
|
+
require 's2_netbox/version'
|
4
|
+
require 's2_netbox/helpers'
|
5
|
+
require 's2_netbox/commands'
|
6
|
+
|
7
|
+
require 's2_netbox/error'
|
8
|
+
require 's2_netbox/errors/configuration_error'
|
9
|
+
|
10
|
+
require 's2_netbox/configuration'
|
11
|
+
|
12
|
+
require 's2_netbox/api_request'
|
13
|
+
require 's2_netbox/api_response'
|
14
|
+
|
15
|
+
require 's2_netbox/commands/authentication'
|
16
|
+
require 's2_netbox/commands/api_version'
|
17
|
+
require 's2_netbox/commands/person'
|
18
|
+
require 's2_netbox/commands/credential'
|
19
|
+
|
20
|
+
module S2Netbox
|
21
|
+
include S2Netbox::Helpers
|
22
|
+
|
23
|
+
BASIC_ENDPOINT = '/goforms/nbapi'
|
24
|
+
class << self
|
25
|
+
def configure
|
26
|
+
yield configuration
|
27
|
+
|
28
|
+
configuration
|
29
|
+
ensure
|
30
|
+
configuration.validate!
|
31
|
+
end
|
32
|
+
|
33
|
+
def configuration
|
34
|
+
@configuration ||= S2Netbox::Configuration.new
|
35
|
+
end
|
36
|
+
|
37
|
+
def clear_configuration
|
38
|
+
@configuration = nil
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.request(url, command, session_id=nil)
|
43
|
+
uri = URI("#{S2Netbox.configuration.controller_url}#{url}")
|
44
|
+
|
45
|
+
req = Net::HTTP::Post.new(uri)
|
46
|
+
|
47
|
+
req.body = "APIcommand=<NETBOX-API#{blank?(session_id) ? '' : " sessionid='#{session_id}'"}>#{command}</NETBOX-API>"
|
48
|
+
req.content_type = 'text/xml'
|
49
|
+
|
50
|
+
response = nil
|
51
|
+
|
52
|
+
Net::HTTP.start(uri.hostname, uri.port, :use_ssl => uri.scheme == 'https' ) {|http|
|
53
|
+
response = http.request(req)
|
54
|
+
}
|
55
|
+
|
56
|
+
S2Netbox::ApiResponse.new(req.body, response.body )
|
57
|
+
end
|
58
|
+
end
|
data/s2_netbox.gemspec
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 's2_netbox/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 's2_netbox'
|
8
|
+
spec.version = S2Netbox::VERSION
|
9
|
+
spec.authors = ['Teamsquare']
|
10
|
+
spec.email = ['hello@teamsquare.co']
|
11
|
+
|
12
|
+
spec.summary = %q{Ruby wrapper for S2 NetBox API.}
|
13
|
+
spec.description = %q{S2 is an enterprise class, feature-rich web-based access control and event monitoring system. This Ruby wrapper makes integrating with the API on NetBox controllers easy. See http://s2sys.com/ for more information.}
|
14
|
+
spec.homepage = 'https://github.com/teamsquare/s2_netbox'
|
15
|
+
spec.license = 'MIT'
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = 'exe'
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ['lib']
|
21
|
+
|
22
|
+
spec.add_runtime_dependency 'httparty'
|
23
|
+
spec.add_runtime_dependency 'activesupport'
|
24
|
+
spec.add_runtime_dependency 'facets'
|
25
|
+
|
26
|
+
spec.add_development_dependency 'bundler', '~> 1.12'
|
27
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
28
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
29
|
+
spec.add_development_dependency 'rspec_junit_formatter', '0.2.2'
|
30
|
+
spec.add_development_dependency 'simplecov', '~> 0.7.1'
|
31
|
+
spec.add_development_dependency 'webmock'
|
32
|
+
spec.add_development_dependency 'factory_girl'
|
33
|
+
end
|
metadata
ADDED
@@ -0,0 +1,209 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: s2_netbox
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1.pre
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Teamsquare
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-11-10 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: httparty
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: activesupport
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: facets
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: bundler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.12'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.12'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '10.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '10.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '3.0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '3.0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rspec_junit_formatter
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 0.2.2
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - '='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 0.2.2
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: simplecov
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 0.7.1
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: 0.7.1
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: webmock
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: factory_girl
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
description: S2 is an enterprise class, feature-rich web-based access control and
|
154
|
+
event monitoring system. This Ruby wrapper makes integrating with the API on NetBox
|
155
|
+
controllers easy. See http://s2sys.com/ for more information.
|
156
|
+
email:
|
157
|
+
- hello@teamsquare.co
|
158
|
+
executables: []
|
159
|
+
extensions: []
|
160
|
+
extra_rdoc_files: []
|
161
|
+
files:
|
162
|
+
- ".gitignore"
|
163
|
+
- ".rspec"
|
164
|
+
- Gemfile
|
165
|
+
- LICENSE.txt
|
166
|
+
- README.md
|
167
|
+
- Rakefile
|
168
|
+
- bin/console
|
169
|
+
- bin/setup
|
170
|
+
- circle.yml
|
171
|
+
- lib/s2_netbox.rb
|
172
|
+
- lib/s2_netbox/api_request.rb
|
173
|
+
- lib/s2_netbox/api_response.rb
|
174
|
+
- lib/s2_netbox/commands.rb
|
175
|
+
- lib/s2_netbox/commands/api_version.rb
|
176
|
+
- lib/s2_netbox/commands/authentication.rb
|
177
|
+
- lib/s2_netbox/commands/credential.rb
|
178
|
+
- lib/s2_netbox/commands/person.rb
|
179
|
+
- lib/s2_netbox/configuration.rb
|
180
|
+
- lib/s2_netbox/error.rb
|
181
|
+
- lib/s2_netbox/errors/configuration_error.rb
|
182
|
+
- lib/s2_netbox/helpers.rb
|
183
|
+
- lib/s2_netbox/version.rb
|
184
|
+
- s2_netbox.gemspec
|
185
|
+
homepage: https://github.com/teamsquare/s2_netbox
|
186
|
+
licenses:
|
187
|
+
- MIT
|
188
|
+
metadata: {}
|
189
|
+
post_install_message:
|
190
|
+
rdoc_options: []
|
191
|
+
require_paths:
|
192
|
+
- lib
|
193
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
194
|
+
requirements:
|
195
|
+
- - ">="
|
196
|
+
- !ruby/object:Gem::Version
|
197
|
+
version: '0'
|
198
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
199
|
+
requirements:
|
200
|
+
- - ">"
|
201
|
+
- !ruby/object:Gem::Version
|
202
|
+
version: 1.3.1
|
203
|
+
requirements: []
|
204
|
+
rubyforge_project:
|
205
|
+
rubygems_version: 2.4.8
|
206
|
+
signing_key:
|
207
|
+
specification_version: 4
|
208
|
+
summary: Ruby wrapper for S2 NetBox API.
|
209
|
+
test_files: []
|