s2_netbox 0.0.1.pre → 0.0.1

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: 55443e3415036a124d1b1501115d3e3b7535e58f
4
- data.tar.gz: 24205f66709d5862b25c92dc26e21cfb4c4a3eb4
3
+ metadata.gz: b70e6ef03b4e2e70b559e99aed3d310be1a9937f
4
+ data.tar.gz: fca51277062f1225a2362ffdc851439bc37622c6
5
5
  SHA512:
6
- metadata.gz: 689d3c3d2d1cd1f8dff87625d3fa26c1e2ff52d72dbf962e3485a5e3bcc70a6a3c7fec6db4ace1bca66015b8299cb96ab4a94ae8e323c08d008773d371c4d3d9
7
- data.tar.gz: e0eb5a19555ec1278f667908aef345246de75faa8f630af6df56045daf51d5182a00869e255720026d523272e7b62b8fb6d6d4a06420c5bdeb5b0c4340190795
6
+ metadata.gz: d4e62ff92d0d570d6f18f714732da57118e1c0f75ddd06dae914d7ef8eec1a0499cd209bb2eb12371e36e19855591eefc1d2d113cb5cf9d40865f2ab02490e28
7
+ data.tar.gz: 1d6fc17fe9d3188e5488b7ac665186d4de36ee2f9a92a542ffeb5b88462814a6f646f756a6a5305c8d78bb13d5c8d54497653a91ffa1d2d88ebf8398caa5f178
data/.gitignore CHANGED
@@ -8,3 +8,4 @@
8
8
  /spec/reports/
9
9
  /tmp/
10
10
  /.idea
11
+ s2_netbox-*.gem
data/README.md CHANGED
@@ -1,16 +1,20 @@
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)
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
5
 
6
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
+
7
8
  # Currently Supported API methods
9
+
8
10
  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.
11
+
12
+ Through `S2Netbox::ApiRequest` class you **should** be able to invoke any API command on the S2 controller by hand, however only the specific ones we're using have been built out and tested.
10
13
 
11
14
  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
15
 
13
16
  # Installation
17
+
14
18
  Add this line to your application's Gemfile:
15
19
 
16
20
  gem 's2_netbox'
@@ -24,18 +28,23 @@ Or install it yourself as:
24
28
  $ gem install s2_netbox
25
29
 
26
30
  # Configuration
31
+
27
32
  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
33
 
29
34
  ```ruby
30
35
  S2Netbox.configure do |config|
31
- config.controller_url = 'https://controller-host'
36
+ config.controller_url = 'https://controller-host'
32
37
  config.username = 'api'
33
38
  config.password = '[W2tnwoUdE+/97o8nmi#P77t'
34
39
  end
35
- ```
40
+ ```
41
+
36
42
  If you're using the S2Netbox gem in a Rails app, this could be placed in an initializer.
43
+
37
44
  # Usage
45
+
38
46
  All requests are bundled up into the required XML parcel with the required `COMMAND` and `PARAMS`.
47
+
39
48
  Once sent to the configured S2 controller, the response is wrapped up in an instance of `S2Netbox::Response` which includes the following accessors:
40
49
 
41
50
  * `code`
@@ -46,62 +55,85 @@ Once sent to the configured S2 controller, the response is wrapped up in an inst
46
55
  * `raw_response`
47
56
  * `session_id`
48
57
 
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.
58
+ `code` returns the raw code response which is typically either `SUCCESS` or `FAIL`, but sometimes has weird other alternatives, such as `DUPLICATE` or `NOT FOUND` just to keep things interesting.
50
59
 
51
60
  `success` is a boolean indicating if the `code` was `SUCCESS`. Any other value for `code` results in `success` being `false`.
52
61
 
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:
62
+ `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 symbol) so access them like:
54
63
 
55
- @result.details['FIRSTNAME']
56
-
57
- not
64
+ ```ruby
65
+ @result.details['FIRSTNAME']
66
+ ```
58
67
 
59
- @result.details[:first_name]
68
+ not
60
69
 
61
- `error_message` is populated with the error mesage returned from the system assuming `code` is not `SUCCESS`.
70
+ ```ruby
71
+ @result.details[:first_name]
72
+ ```
73
+ `error_message` is populated with the error message returned from the system assuming `code` is not `SUCCESS`.
62
74
 
63
75
  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
76
 
65
77
  `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
78
 
67
79
  # 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.
80
+
81
+ The gem supports authentication by username and password only. Although you can configure it to use the `sha_password` method of authentication, at present the MAC signature is not generated or included with any request.
69
82
 
70
83
  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.
84
+
71
85
  ## Login
86
+
72
87
  Login is used to establish a session and obtain a `session_id` which is used in subsequent requests:
73
88
 
89
+ ```ruby
74
90
  @result = S2Netbox::Commands::Authentication.login
91
+ ```
75
92
 
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:
93
+ To get an instance of `S2Netbox::Response` which (assuming log in is successful) will include the `session_id` which can be used in subsequent requests:
77
94
 
95
+ ```ruby
78
96
  @result.session_id
97
+ ```
79
98
 
80
99
  ## Logout
100
+
81
101
  All sessions must be logged out. According to the S2 documentation:
82
102
 
83
103
  > 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
104
 
85
105
  To log out, issue the `logout` command:
86
106
 
87
- @result = S2Netbox::Commands::Authentication.logout('session_id_from_login')
107
+ ```ruby
108
+ @result = S2Netbox::Commands::Authentication.logout('session_id_from_login')
109
+ ```
88
110
 
89
111
  # Version
112
+
90
113
  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
114
  ## GetVersion
92
- @result = S2Netbox::Commands::ApiVersion.get_version('session_id_from_login')
115
+
116
+ ```ruby
117
+ @result = S2Netbox::Commands::ApiVersion.get_version('session_id_from_login')
118
+ ```
119
+
93
120
  The result object will contain the version (assuming you've successfully logged in):
94
121
 
95
- :001 > puts @result.details['APIVERSION']
96
- 4.1
122
+ ```ruby
123
+ :001 > puts @result.details['APIVERSION']
124
+ 4.1
125
+ ```
97
126
 
98
127
  # Person
99
- The `Person` module allows you to add and modfy Pereson records.
128
+
129
+ The `Person` module allows you to add and modify Person records.
130
+
100
131
  ## AddPerson
132
+
101
133
  The `add_person` method accepts 3 arguments:
102
134
 
103
135
  1. Hash of person attributes
104
- 1. List of access levels
136
+ 1. List of access levels
105
137
  1. List of User Defined Fields
106
138
  1. (Optional) session_id
107
139
 
@@ -115,13 +147,16 @@ The `add_person` method accepts 3 arguments:
115
147
  }, %w(AccessLevel1 AccessLevel2), 'UDF1'
116
148
  )
117
149
  ```
150
+
118
151
  Both access levels and user defined fields can be specified either as a single string or as an array of strings.
152
+
119
153
  ## ModifyPerson
154
+
120
155
  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
156
 
122
157
  1. Person ID
123
158
  1. Hash of person attributes
124
- 1. List of access levels
159
+ 1. List of access levels
125
160
  1. List of User Defined Fields
126
161
  1. (Optional) session_id
127
162
 
@@ -133,9 +168,80 @@ The `modify_person` method allows you to modify an existing person, and is simil
133
168
  :act_date => '10/10/2016'
134
169
  }, %w(AccessLevel1 AccessLevel2), 'UDF1')
135
170
  ```
171
+
136
172
  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
173
 
174
+ # Credential
175
+
176
+ ## Add
177
+
178
+ The `add` method accepts 2 arguments:
179
+
180
+ 1. Hash of credential attributes
181
+ 1. (Optional) session_id
182
+
183
+ ```ruby
184
+ @result = S2Netbox::Commands::Credential.add({
185
+ :person_id => '8a806ed6-0246-49d0-b7a7-ab6402da01e3',
186
+ :encoded_num => '3113',
187
+ :card_format => '26 bit Wiegand'
188
+ })
189
+ ```
190
+
191
+ This will add a 26 bit Wiegand encoded card with card number 3113 to the Person record identified by ID `8a806ed6-0246-49d0-b7a7-ab6402da01e3` in the S2 controller.
192
+
193
+
194
+ ## Modify
195
+
196
+ The `modify` method accepts 2 arguments:
197
+
198
+ 1. Hash of credential attributes
199
+ 1. (Optional) session_id
200
+
201
+ ```ruby
202
+ @result = S2Netbox::Commands::Credential.add({
203
+ :encoded_num => '3113',
204
+ :disabled => 1
205
+ })
206
+ ```
207
+
208
+ This example will set `disabled` to `1` (a truthy value) for the credential identified with the `ENCODEDNUM` of `3113` in the S2 Controller.
209
+
210
+ # Other Commands
211
+
212
+ By using the `S2Netbox::ApiRequest` class directly, you can send any command to the S2 Controller.
213
+
214
+ The `send_request` method allows commands to be sent to the S2 Controller and accepts the following arguments:
215
+
216
+ 1. The command name
217
+ 1. A hash of the command attributes
218
+ 1. (Optional) session_id
219
+
220
+ For instance, although untested, you should be able to set a lockdown level by sending the command:
221
+
222
+ ```ruby
223
+ S2Netbox::ApiRequest.send_request('SetThreatLevel', {:level_group_name => 'Elevated'})
224
+ ```
225
+
226
+ Will set the current threat level to the threat level with a name of `Elevated` in the S2 Controller.
227
+
228
+ ## Sending commands to other endpoints
229
+
230
+ The `S2Netbox::ApiRequest.send_request` method sends requests to the `/goforms/nbapi` endpoint.
231
+
232
+ For finer grained control and advanced requests, including the ability to change this path, you can call the lower level `S2Netbox.request` method.
233
+
234
+ The `S2Netbox::request` method takes three arguments:
235
+
236
+ 1. Url
237
+ 1. Command
238
+ 1. (Optional) session_id
239
+
240
+ The `url` argument is the path to the API endpoint, such as `/goforms/nbapi`.
241
+
242
+ The `command` argument is the raw XML command that will be placed within the `<NETBOX-API>` element.
243
+
244
+ Pass in the optional `session_id` if you’re using username and password based authentication.
139
245
 
140
246
  # Development
141
247
 
@@ -153,5 +259,4 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
153
259
 
154
260
  # License
155
261
 
156
- The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
157
-
262
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -16,7 +16,16 @@ class S2Netbox::ApiRequest
16
16
  def self.method_missing(method_name, *arguments, &block)
17
17
  return super unless supported_operations.include?(method_name)
18
18
 
19
- send_request(command_for_method(method_name), map_attributes(arguments[0]), arguments[1])
19
+ attributes = arguments[0]
20
+ session_id = arguments[1]
21
+
22
+ if arguments.length == 1 && !arguments[0].is_a?(Hash)
23
+ # there is only a single argument, and it isn't a hash - assume it is session_id
24
+ attributes = nil
25
+ session_id = arguments[0]
26
+ end
27
+
28
+ send_request(command_for_method(method_name), map_attributes(attributes), session_id)
20
29
  end
21
30
 
22
31
  def self.respond_to_missing?(method_name, include_private = false)
@@ -37,7 +46,7 @@ class S2Netbox::ApiRequest
37
46
  if command_map && command_map[method_name]
38
47
  return command_map[method_name]
39
48
  else
40
- return "#{method_name.to_s.gsub('_', ' ').titlecase.gsub(' ', '')}#{name.split('::').last}"
49
+ return "#{method_name.to_s.tr('_', ' ').titlecase.delete(' ')}#{name.split('::').last}"
41
50
  end
42
51
  end
43
52
 
@@ -46,7 +55,7 @@ class S2Netbox::ApiRequest
46
55
 
47
56
  params.each do |k, v|
48
57
  if v.is_a?(Hash)
49
- res << "<#{k.to_s}>"
58
+ res << "<#{k}>"
50
59
 
51
60
  singular = v[:singular_node_name]
52
61
 
@@ -54,9 +63,9 @@ class S2Netbox::ApiRequest
54
63
  res << "<#{singular}>#{inner_value}</#{singular}>"
55
64
  end
56
65
 
57
- res << "</#{k.to_s}>"
66
+ res << "</#{k}>"
58
67
  else
59
- res << "<#{k.to_s}>#{v}</#{k.to_s}>"
68
+ res << "<#{k}>#{v}</#{k}>"
60
69
  end
61
70
  end
62
71
 
@@ -70,6 +79,6 @@ class S2Netbox::ApiRequest
70
79
  def self.map_attributes(attributes)
71
80
  return unless attributes
72
81
 
73
- attributes.reject { |_,v| blank?(v) }.map { |k, v| [k.to_s.gsub('_', '').upcase, v] }.to_h
82
+ attributes.reject { |_,v| blank?(v) }.map { |k, v| [k.to_s.delete('_').upcase, v] }.to_h
74
83
  end
75
84
  end
@@ -12,8 +12,6 @@ class S2Netbox::Commands::Person < S2Netbox::ApiRequest
12
12
  send_request('ModifyPerson', person_attributes, session_id)
13
13
  end
14
14
 
15
- protected
16
-
17
15
  def self.build_attributes(attributes, access_levels, user_defined_fields)
18
16
  hash = map_attributes(attributes)
19
17
  hash = build_user_defined_fields(hash, user_defined_fields)
@@ -24,7 +22,7 @@ class S2Netbox::Commands::Person < S2Netbox::ApiRequest
24
22
 
25
23
  def self.build_access_level(hash, access_levels)
26
24
  unless access_levels.empty?
27
- hash['ACCESSLEVELS'] = {:singular_node_name => 'ACCESSLEVEL', :values => access_levels}
25
+ hash['ACCESSLEVELS'] = {:singular_node_name => 'ACCESSLEVEL', :values => Array.wrap(access_levels)}
28
26
  end
29
27
 
30
28
  hash
@@ -1,3 +1,3 @@
1
1
  module S2Netbox
2
- VERSION = '0.0.1.pre'
2
+ VERSION = '0.0.1'
3
3
  end
data/s2_netbox.gemspec CHANGED
@@ -19,15 +19,15 @@ Gem::Specification.new do |spec|
19
19
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
20
  spec.require_paths = ['lib']
21
21
 
22
- spec.add_runtime_dependency 'httparty'
23
- spec.add_runtime_dependency 'activesupport'
24
- spec.add_runtime_dependency 'facets'
22
+ spec.add_runtime_dependency 'httparty', '~> 0.14'
23
+ spec.add_runtime_dependency 'activesupport', '~> 4.0'
24
+ spec.add_runtime_dependency 'facets', '~> 3.1'
25
25
 
26
26
  spec.add_development_dependency 'bundler', '~> 1.12'
27
27
  spec.add_development_dependency 'rake', '~> 10.0'
28
28
  spec.add_development_dependency 'rspec', '~> 3.0'
29
29
  spec.add_development_dependency 'rspec_junit_formatter', '0.2.2'
30
30
  spec.add_development_dependency 'simplecov', '~> 0.7.1'
31
- spec.add_development_dependency 'webmock'
32
- spec.add_development_dependency 'factory_girl'
31
+ spec.add_development_dependency 'webmock', '~> 2.1'
32
+ spec.add_development_dependency 'factory_girl', '~> 4.7'
33
33
  end
metadata CHANGED
@@ -1,57 +1,57 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: s2_netbox
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1.pre
4
+ version: 0.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Teamsquare
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-11-10 00:00:00.000000000 Z
11
+ date: 2016-11-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: '0.14'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: '0.14'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: activesupport
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: '4.0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '0'
40
+ version: '4.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: facets
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ">="
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '0'
47
+ version: '3.1'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ">="
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '0'
54
+ version: '3.1'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: bundler
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -126,30 +126,30 @@ dependencies:
126
126
  name: webmock
127
127
  requirement: !ruby/object:Gem::Requirement
128
128
  requirements:
129
- - - ">="
129
+ - - "~>"
130
130
  - !ruby/object:Gem::Version
131
- version: '0'
131
+ version: '2.1'
132
132
  type: :development
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
- - - ">="
136
+ - - "~>"
137
137
  - !ruby/object:Gem::Version
138
- version: '0'
138
+ version: '2.1'
139
139
  - !ruby/object:Gem::Dependency
140
140
  name: factory_girl
141
141
  requirement: !ruby/object:Gem::Requirement
142
142
  requirements:
143
- - - ">="
143
+ - - "~>"
144
144
  - !ruby/object:Gem::Version
145
- version: '0'
145
+ version: '4.7'
146
146
  type: :development
147
147
  prerelease: false
148
148
  version_requirements: !ruby/object:Gem::Requirement
149
149
  requirements:
150
- - - ">="
150
+ - - "~>"
151
151
  - !ruby/object:Gem::Version
152
- version: '0'
152
+ version: '4.7'
153
153
  description: S2 is an enterprise class, feature-rich web-based access control and
154
154
  event monitoring system. This Ruby wrapper makes integrating with the API on NetBox
155
155
  controllers easy. See http://s2sys.com/ for more information.
@@ -197,9 +197,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
197
197
  version: '0'
198
198
  required_rubygems_version: !ruby/object:Gem::Requirement
199
199
  requirements:
200
- - - ">"
200
+ - - ">="
201
201
  - !ruby/object:Gem::Version
202
- version: 1.3.1
202
+ version: '0'
203
203
  requirements: []
204
204
  rubyforge_project:
205
205
  rubygems_version: 2.4.8