kinetic_sdk 1.0.0 → 1.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
  SHA256:
3
- metadata.gz: 2d9d1454174a1ad6358bfa3c1dd12d52cd24eef89c5a1464bca51c7a96829152
4
- data.tar.gz: 4b0ef0d1c31e02566d8f00cc6aee0b796046e90284a5fef271280f4f9b587230
3
+ metadata.gz: b7d44ee22259297d53b3443c3e86cc3d8b724cef8ab996f2b3a378900a1a12c5
4
+ data.tar.gz: '09fbb57c03e9e6a7ab21a0dac2eb104e2fd8917e91bb221083bc4635513110f5'
5
5
  SHA512:
6
- metadata.gz: a4a0b0aef4fd8f4be9897d083b93c4370cfaeb82c6e8c39d7a98af40ecbe60b883fc5ac9699f8b4eba0d8df18306663445079a6073d8f2fe4d1243a1b9b93744
7
- data.tar.gz: 8f4fa17ba3124ed7d2d6386670d4bf695f07a3babd4284d831436067baba2b90811e86ef5b294b5d9991eaf509d3d326bc28ec699e122697ced2547521fe4f9d
6
+ metadata.gz: ab9121e76bc6f9ec5f6c4ef704fc98c3070ae8d79461087deb173762a6331469b300d66867c513735c4f56da17596675dcf40e2977219b91cc99dfa7459dfa0e
7
+ data.tar.gz: 2d11b876d8419d4ffd89182cd51e698ce60056227392d229c7b7e9291a32e345577eda84eedcb7b8ef5a131e8df5402b2003de773c41fb42dd49bd83bdcee0b3
@@ -18,7 +18,9 @@ module KineticSdk
18
18
  #
19
19
  def add_policy_rule(policy, headers=default_headers)
20
20
  @logger.info("Adding policy rule \"#{policy['type']} - #{policy['name']}\"")
21
- post("#{@api_url}/policyRules/#{encode(policy['type'])}", policy, headers)
21
+ payload = policy
22
+ payload["consolePolicyRules"] = consoleNames(payload) if payload.has_key?("consolePolicyRules")
23
+ post("#{@api_url}/policyRules/#{encode(policy['type'])}", payload, headers)
22
24
  end
23
25
 
24
26
  # Delete a Policy Rule.
@@ -111,7 +113,11 @@ module KineticSdk
111
113
  @logger.info("Importing all Policy Rules in Export Directory")
112
114
  Dir["#{@options[:export_directory]}/policyRules/*.json"].sort.each do |file|
113
115
  policy_rule = JSON.parse(File.read(file))
114
- add_policy_rule(policy_rule, headers)
116
+ if find_policy_rule({ "type" => policy_rule["type"], "name" => policy_rule["name"] }).status == 200
117
+ update_policy_rule({ "type" => policy_rule["type"], "name" => policy_rule["name"] }, policy_rule, headers)
118
+ else
119
+ add_policy_rule(policy_rule, headers)
120
+ end
115
121
  end
116
122
  end
117
123
 
@@ -172,7 +178,40 @@ module KineticSdk
172
178
  #
173
179
  def update_policy_rule(policy_rule, body={}, headers=default_headers)
174
180
  @logger.info("Updating the \"#{policy_rule['type']} - #{policy_rule['name']}\" Policy Rule")
175
- put("#{@api_url}/policyRules/#{encode(policy_rule['type'])}/#{encode(policy_rule['name'])}", body, headers)
181
+ payload = body
182
+ payload["consolePolicyRules"] = consoleNames(payload) if payload.has_key?("consolePolicyRules")
183
+
184
+ @logger.info("UPDATE: #{payload}")
185
+ put("#{@api_url}/policyRules/#{encode(policy_rule['type'])}/#{encode(policy_rule['name'])}", payload, headers)
186
+ end
187
+
188
+ private
189
+
190
+ # Returns a list of console names from a list of consolePolicyRules hash
191
+ # objects.
192
+ #
193
+ # This is used to convert a console policy hash to a simple string containing
194
+ # the console name:
195
+ #
196
+ # {
197
+ # "name" => "Foo",
198
+ # "type" => "Console Access"
199
+ # }
200
+ #
201
+ def consoleNames(policyRule)
202
+ consoles = nil
203
+ # if consolePolicyRules are to be applied, change to a list of console names
204
+ if policyRule.has_key?("consolePolicyRules")
205
+ consoles = []
206
+ (policyRule['consolePolicyRules'] || []).each { |console_policy_rule|
207
+ if console_policy_rule.is_a? Hash
208
+ consoles << console_policy_rule["name"]
209
+ else
210
+ consoles << console_policy_rule
211
+ end
212
+ }
213
+ end
214
+ consoles
176
215
  end
177
216
 
178
217
  end
@@ -3,5 +3,5 @@ module KineticSdk
3
3
  # Version of Kinetic SDK
4
4
  #
5
5
  # @return [String] Version of the SDK
6
- VERSION = "1.0.0"
6
+ VERSION = "1.0.1"
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kinetic_sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kinetic Data
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-12-10 00:00:00.000000000 Z
11
+ date: 2019-12-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement