snow_sync 2.0.7 → 3.0.0
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.
- checksums.yaml +4 -4
- data/lib/snow_sync/configs.yml +1 -1
- data/lib/snow_sync/sync_util.rb +35 -16
- data/lib/snow_sync/version.rb +1 -1
- data/spec/sync_util_spec.rb +50 -10
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 291450da560ad042fd30195c1d5af042c4ff48b4
|
4
|
+
data.tar.gz: 1760e8efa915a578052e08cefc5873becf7a128d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 351fe385067754cccb985ae275e12616e5727dc6753a8c602a75542df3e5cc3a4ae33ffe41f7f85d01e98c1b6940d0a81d31122ccb8bce8feb4d43267e92f5f3
|
7
|
+
data.tar.gz: 42568f36c2e279d3dd3cade31af8af0449a3f7483a3f03bfe5b0968ecc65de5d3f9202da209c60fda7536549f5d1d26c8a95c4863475ce96200d072686988a25
|
data/lib/snow_sync/configs.yml
CHANGED
data/lib/snow_sync/sync_util.rb
CHANGED
@@ -32,6 +32,14 @@ module SnowSync
|
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
|
+
# Creates a subdirectory if no directory exists
|
36
|
+
# @param [String] name Required directory name
|
37
|
+
# @param [Object] &block Optional directory path
|
38
|
+
|
39
|
+
def create_subdirectory(name, &block)
|
40
|
+
create_directory(name, &block)
|
41
|
+
end
|
42
|
+
|
35
43
|
# Creates a JS file & logs the file creation
|
36
44
|
# @param [String] name Required file name
|
37
45
|
# @param [Object] json Required json object
|
@@ -81,25 +89,34 @@ module SnowSync
|
|
81
89
|
end
|
82
90
|
end
|
83
91
|
|
84
|
-
#
|
92
|
+
# Creates the dir structure, requests, retrieves & sets up JS files locally
|
85
93
|
|
86
|
-
def
|
94
|
+
def run_setup_and_sync
|
95
|
+
# sync directory boolean tracks sync dir creation
|
96
|
+
# necessary for iterative subdir creation and re-syncs
|
97
|
+
sync_directory = File.directory?("sync")
|
98
|
+
directory_name = "sync"
|
87
99
|
@configs["table_map"].each do |key, value|
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
100
|
+
subdirectory_name = key
|
101
|
+
if sync_directory
|
102
|
+
path = proc { FileUtils.cd(directory_name) }
|
103
|
+
create_subdirectory(subdirectory_name, &path)
|
104
|
+
else
|
105
|
+
create_directory(directory_name)
|
106
|
+
path = proc { FileUtils.cd(directory_name) }
|
107
|
+
create_subdirectory(subdirectory_name, &path)
|
108
|
+
sync_directory = "true"
|
109
|
+
end
|
93
110
|
begin
|
94
111
|
user = Base64.strict_decode64(@configs["creds"]["user"])
|
95
112
|
pass = Base64.strict_decode64(@configs["creds"]["pass"])
|
96
113
|
response = RestClient.get(
|
97
114
|
"#{@configs['base_url']}#{value["table"]}?sysparm_query=sys_id%3D" +
|
98
|
-
"#{value["
|
115
|
+
"#{value["sys_id"]}%5Ename%3D#{value["name"]}",
|
99
116
|
{:authorization => "#{"Basic " + Base64.strict_encode64("#{user}:#{pass}")}",
|
100
117
|
:accept => "application/json"})
|
101
|
-
path = proc { FileUtils.cd(
|
102
|
-
@configs[
|
118
|
+
path = proc { FileUtils.cd(subdirectory_name) }
|
119
|
+
@configs["table_map"][key]["response"] = JSON.parse(response)["result"][0]
|
103
120
|
json = JSON.parse(response)["result"][0][value["field"]]
|
104
121
|
name = value["name"].snakecase
|
105
122
|
create_file(name, json, &path)
|
@@ -133,12 +150,13 @@ module SnowSync
|
|
133
150
|
|
134
151
|
# Merges JS file changes with the encapsulated table response value
|
135
152
|
# @param [String] file JS file path
|
153
|
+
# @param [String] type Servicenow script type
|
136
154
|
# @param [Hash] table_hash Configured servicenow table hash
|
137
155
|
|
138
|
-
def merge_update(file, table_hash)
|
156
|
+
def merge_update(file, type, table_hash)
|
139
157
|
FileUtils.cd(file.split("/")[0..1].join("/"))
|
140
158
|
script_body = File.open(file.split("/").last).read
|
141
|
-
@configs[
|
159
|
+
@configs["table_map"][type]["mod"] = script_body
|
142
160
|
FileUtils.cd("../..")
|
143
161
|
end
|
144
162
|
|
@@ -147,7 +165,7 @@ module SnowSync
|
|
147
165
|
def start_sync
|
148
166
|
check_required_configs
|
149
167
|
encrypt_credentials
|
150
|
-
|
168
|
+
run_setup_and_sync
|
151
169
|
end
|
152
170
|
|
153
171
|
# Merges all JS file changes & pushes to the configured servicenow instance
|
@@ -156,15 +174,16 @@ module SnowSync
|
|
156
174
|
def push_modifications(files)
|
157
175
|
files.each do |file|
|
158
176
|
file.downcase!
|
177
|
+
type = file.split("/")[1]
|
159
178
|
table_hash = table_lookup(file)
|
160
|
-
merge_update(file, table_hash)
|
179
|
+
merge_update(file, type, table_hash)
|
161
180
|
begin
|
162
181
|
user = Base64.strict_decode64(@configs["creds"]["user"])
|
163
182
|
pass = Base64.strict_decode64(@configs["creds"]["pass"])
|
164
183
|
request_body_map = {
|
165
|
-
table_hash["field"].to_sym => @configs[
|
184
|
+
table_hash["field"].to_sym => @configs["table_map"][type]["mod"]
|
166
185
|
}
|
167
|
-
response = RestClient.patch("#{@configs['base_url']}#{table_hash["table"]}/#{table_hash["
|
186
|
+
response = RestClient.patch("#{@configs['base_url']}#{table_hash["table"]}/#{table_hash["sys_id"]}",
|
168
187
|
request_body_map.to_json,
|
169
188
|
{:authorization => "#{"Basic " + Base64.strict_encode64("#{user}:#{pass}")}",
|
170
189
|
:content_type => "application/json", :accept => "application/json"})
|
data/lib/snow_sync/version.rb
CHANGED
data/spec/sync_util_spec.rb
CHANGED
@@ -125,7 +125,7 @@ describe "table_lookup" do
|
|
125
125
|
|
126
126
|
it "should return configured SN table" do
|
127
127
|
table_map = util.table_lookup("sync/script_include/test_class.js")
|
128
|
-
expect(table_map.keys).to eq ["name", "table", "
|
128
|
+
expect(table_map.keys).to eq ["name", "table", "sys_id", "field"]
|
129
129
|
expect(table_map["table"]).to eq "sys_script_include"
|
130
130
|
end
|
131
131
|
|
@@ -137,20 +137,22 @@ describe "merge_update" do
|
|
137
137
|
SnowSync::SyncUtil.new(opts = "test")
|
138
138
|
end
|
139
139
|
|
140
|
-
it "should merge
|
140
|
+
it "should merge script with the configs object" do
|
141
141
|
FileUtils.mkdir_p("sync")
|
142
142
|
FileUtils.mkdir_p("sync/test_sub_dir")
|
143
|
-
|
143
|
+
json_resp = "var test = 'test'; \n" +
|
144
|
+
"var testing = function(arg) { \n\tgs.print(arg) \n}; \n" +
|
145
|
+
"testing('test');"
|
144
146
|
name = "TestClass".snakecase
|
145
147
|
path = proc do
|
146
148
|
FileUtils.cd("sync/test_sub_dir")
|
147
149
|
end
|
148
|
-
util.create_file(name,
|
150
|
+
util.create_file(name, json_resp, &path)
|
149
151
|
FileUtils.cd("../..")
|
150
152
|
file = "sync/test_sub_dir/test_class.js"
|
151
153
|
table_map = util.table_lookup(file)
|
152
|
-
util.merge_update(file, table_map)
|
153
|
-
expect(util.configs["
|
154
|
+
util.merge_update(file, "script_include", table_map)
|
155
|
+
expect(util.configs["table_map"]["script_include"]["mod"] != nil).to eq true
|
154
156
|
end
|
155
157
|
|
156
158
|
end
|
@@ -163,7 +165,7 @@ describe "setup_sync_directories" do
|
|
163
165
|
end
|
164
166
|
|
165
167
|
it "should setup and synchronize field from the SN instance" do
|
166
|
-
util.
|
168
|
+
util.run_setup_and_sync
|
167
169
|
file = File.open("sync/script_include/test_class.js")
|
168
170
|
expect(file.is_a?(Object)).to eq true
|
169
171
|
FileUtils.rm_rf("sync")
|
@@ -171,14 +173,14 @@ describe "setup_sync_directories" do
|
|
171
173
|
|
172
174
|
end
|
173
175
|
|
174
|
-
describe "push_modifications" do
|
176
|
+
describe "push_modifications - single table configuration" do
|
175
177
|
|
176
178
|
let! :util do
|
177
179
|
SnowSync::SyncUtil.new(opts = "test")
|
178
180
|
end
|
179
181
|
|
180
182
|
it "should push modifications to a configured instance" do
|
181
|
-
util.
|
183
|
+
util.run_setup_and_sync
|
182
184
|
file = File.open("sync/script_include/test_class.js", "r+")
|
183
185
|
lines = file.readlines
|
184
186
|
file.close
|
@@ -189,7 +191,7 @@ describe "push_modifications" do
|
|
189
191
|
end
|
190
192
|
newfile.close
|
191
193
|
util.push_modifications(["sync/script_include/test_class.js"])
|
192
|
-
util.
|
194
|
+
util.run_setup_and_sync
|
193
195
|
file = File.open("sync/script_include/test_class.js", "r+")
|
194
196
|
lines = file.readlines
|
195
197
|
file.close
|
@@ -197,3 +199,41 @@ describe "push_modifications" do
|
|
197
199
|
end
|
198
200
|
|
199
201
|
end
|
202
|
+
|
203
|
+
describe "push_modifications - mutli-table configuration" do
|
204
|
+
|
205
|
+
let! :util do
|
206
|
+
SnowSync::SyncUtil.new(opts = "test")
|
207
|
+
end
|
208
|
+
|
209
|
+
it "should sync, update, queue, push, re-sync mods for a configured instance" do
|
210
|
+
def do_edit(file, edit)
|
211
|
+
file = File.open(file, "r+")
|
212
|
+
lines = file.readlines
|
213
|
+
file.close
|
214
|
+
lines[0] = edit
|
215
|
+
newfile = File.new(file, "w")
|
216
|
+
lines.each do |line|
|
217
|
+
newfile.write(line)
|
218
|
+
end
|
219
|
+
newfile.close
|
220
|
+
end
|
221
|
+
def run_check(file, edit)
|
222
|
+
file = File.open(file, "r+")
|
223
|
+
lines = file.readlines
|
224
|
+
file.close
|
225
|
+
expect(lines[0]).to eq edit
|
226
|
+
end
|
227
|
+
util.run_setup_and_sync
|
228
|
+
# sys_script_include
|
229
|
+
do_edit("sync/script_include/test_class.js", "// test comment -\n")
|
230
|
+
# sys_ui_action
|
231
|
+
do_edit("sync/ui_action/test.js", "// test comment -\n")
|
232
|
+
# queued mods, push in sequence
|
233
|
+
util.push_modifications(["sync/script_include/test_class.js", "sync/ui_action/test.js"])
|
234
|
+
util.run_setup_and_sync
|
235
|
+
run_check("sync/script_include/test_class.js", "// test comment -\n")
|
236
|
+
run_check("sync/ui_action/test.js", "// test comment -\n")
|
237
|
+
end
|
238
|
+
|
239
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: snow_sync
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andy Wallace
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-05-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|