snow_sync 2.0.3 → 2.0.4

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: 905983c32873b5a04a55c0b4e803bea4b000983d
4
- data.tar.gz: 6d9b92b9565aab913b6ef1425558a409f12ee3af
3
+ metadata.gz: 767c4c759ea7399131d6ac18244530e04ce3adce
4
+ data.tar.gz: 9ae30f53d195d5b30be3af7178db1f7991d901b4
5
5
  SHA512:
6
- metadata.gz: 5a05d068e3a24facb5a9141fa2c84bf3dcec69e8544d6ca62212e033f65faf40e555d9a75d5597410f06e494431a6aab44d6ffc03aefbd9ecb242509c632f760
7
- data.tar.gz: fc220ed96e5b09974f6fd28834f5f01028f745a09ac5f3a0655e1cc58cae7b66907b7eead93df3033b3e0c3041f283863ac5bdda55032d1e1e8a688d35783ed3
6
+ metadata.gz: 1ad5b750d3827b94f06cf70ea3c7fcf0d57be2ab14c1009574538dc6b375f44baeefb814281a87d93633e66f75f85402889be555370d1376656ddf43c5c2d864
7
+ data.tar.gz: fb8306796cc66077ea171110cbd39c687ab352a5474680d8a5ecea8e2ad6934693a44dde5a7351b8c922a1d392287f9c937e4d3dce1cb8a6b6b0b47821a1f5a8
data/README.md CHANGED
@@ -45,6 +45,7 @@ cd /lib/snow_sync
45
45
  ```
46
46
 
47
47
  * Setup the configurations in the configs.yml
48
+ * Only supports single table map configuration (multi coming soon...)
48
49
  * Configuration path is the current working directory
49
50
  * Append /api/now/table/ to the base_url
50
51
 
@@ -52,7 +53,7 @@ cd /lib/snow_sync
52
53
  guard -i
53
54
  ```
54
55
 
55
- Note: if the sync directory is deleted after a previous sync, reset the credential configs in the configs.yml so they can be re-encrypted
56
+ **Note:** if the sync directory is deleted after a successful sync, reset the credential configs in the configs.yml so they can be re-encrypted on the next sync
56
57
 
57
58
 
58
59
  ## Running the Tests
@@ -71,7 +72,7 @@ cd <path>/gems/snow_sync-<version>
71
72
  rspec spec/sync_util_spec.rb
72
73
  ```
73
74
 
74
- Note: if the sync directory is deleted after a previous sync, reset the credential configs in the test_configs.yml so they can be re-encrypted
75
+ **Note:** if the sync directory is deleted after a successful sync, reset the credential configs in the test_configs.yml so they can be re-encrypted on the next sync
75
76
 
76
77
  ## License
77
78
 
@@ -11,8 +11,8 @@ module SnowSync
11
11
 
12
12
  attr_accessor :cf, :configs, :logger
13
13
 
14
- # creates utility object
15
- # initializes encapsulated data
14
+ # creates a utility object
15
+ # sets the encapsulated data
16
16
  # opts {string}: optional configuration
17
17
 
18
18
  def initialize(opts = nil)
@@ -20,11 +20,11 @@ module SnowSync
20
20
  @configs = YAML::load_file(@cf)
21
21
  @logger = Logger.new(STDERR)
22
22
  end
23
-
24
- # creates directory if directory doesn't exist
23
+
24
+ # creates a directory if no directory exists
25
25
  # name {string}: required directory name
26
26
  # &block {object}: optional directory path
27
-
27
+
28
28
  def create_directory(name, &block)
29
29
  yield block if block_given?
30
30
  unless File.directory?(name)
@@ -34,7 +34,7 @@ module SnowSync
34
34
  end
35
35
 
36
36
  # creates a js file
37
- # logs out the file created
37
+ # logs the file creation
38
38
  # name {string}: required file name
39
39
  # json {object}: required json object
40
40
  # &block {object}: optional file path
@@ -48,50 +48,29 @@ module SnowSync
48
48
  end
49
49
 
50
50
  # checks required configurations
51
- # raises an exception when required configs aren't found
51
+ # raises an exception when configs aren't found
52
52
 
53
53
  def check_required_configs
54
- conf_path = File.directory?(@configs["conf_path"])
55
- missing_credentials = @configs["creds"].values.any? do |e|
56
- e.nil?
57
- end
54
+ missing_path = @configs["conf_path"].nil?
55
+ missing_url = @configs["base_url"].nil?
56
+ missing_creds = @configs["creds"].values.any? { |val| val.nil? }
58
57
  keys = @configs["table_map"].keys
59
58
  keys.each do |key|
60
- # set as instance variable to reference outside block
61
- @missing_table_map = @configs["table_map"][key].values.any? do |e|
62
- e.nil?
59
+ missing_map = @configs["table_map"][key].values.any? { |val| val.nil? }
60
+ if missing_path or missing_url or missing_creds or missing_map
61
+ raise "EXCEPTION: Required configs missing in configs.yml. " \
62
+ "Check the configuration path, base url, credentials or table to sync."
63
63
  end
64
- end
65
- if missing_credentials or @missing_table_map or !conf_path
66
- raise "EXCEPTION: Required configs missing in configs.yml. " \
67
- "Please check the configuration path, credentials or table to sync."
68
- else
69
- @configs
70
- end
64
+ end
71
65
  end
72
66
 
73
- # encrypts the configured credentials based on
74
- # whether a previous sync setup has occurred
67
+ # encrypts config credentials based on previous sync
75
68
 
76
69
  def encrypt_credentials
77
70
  previous_sync = File.directory?("sync")
78
- # sets up the configs object
79
- configs_path = @configs["conf_path"] + @cf
80
- configs = YAML::load_file(configs_path)
81
- if previous_sync
82
- # local configuration changes
71
+ if !previous_sync
72
+ configs_path = @configs["conf_path"] + @cf
83
73
  configs = YAML::load_file(configs_path)
84
- user = Base64.strict_decode64(@configs["creds"]["user"])
85
- pass = Base64.strict_decode64(@configs["creds"]["pass"])
86
- userb64 = Base64.strict_encode64(user)
87
- passb64 = Base64.strict_encode64(pass)
88
- configs["creds"]["user"] = userb64
89
- configs["creds"]["pass"] = passb64
90
- File.open(configs_path, 'w') { |f| YAML::dump(configs, f) }
91
- # object state configuration changes
92
- @configs["creds"]["user"] = userb64
93
- @configs["creds"]["pass"] = passb64
94
- else
95
74
  # local configuration changes
96
75
  userb64 = Base64.strict_encode64(@configs["creds"]["user"])
97
76
  passb64 = Base64.strict_encode64(@configs["creds"]["pass"])
@@ -100,7 +79,7 @@ module SnowSync
100
79
  File.open(configs_path, 'w') { |f| YAML::dump(configs, f) }
101
80
  # object state configuration changes
102
81
  @configs["creds"]["user"] = userb64
103
- @configs["creds"]["pass"] = passb64
82
+ @configs["creds"]["pass"] = passb64
104
83
  end
105
84
  end
106
85
 
@@ -153,7 +132,7 @@ module SnowSync
153
132
  end
154
133
  end
155
134
 
156
- # replaces the encapsulated table reponse value
135
+ # replaces the encapsulated table response value
157
136
  # with the current js file updates
158
137
  # file {string}: js file path
159
138
  # table_hash {hash}: configured SN table hash
@@ -165,10 +144,9 @@ module SnowSync
165
144
  FileUtils.cd("../..")
166
145
  end
167
146
 
168
- # start sync process
169
147
  # check required configurations
170
148
  # encrypt configured credentials
171
- # retrieve and set up the script file locally
149
+ # retrieve, set up the script file locally
172
150
 
173
151
  def start_sync
174
152
  check_required_configs
@@ -177,7 +155,7 @@ module SnowSync
177
155
  end
178
156
 
179
157
  # merges all js file changes
180
- # updates SN instance with the js file changes
158
+ # updates a SN instance with the changes
181
159
  # files {array}: array of js file paths
182
160
 
183
161
  def push_modifications(files)
@@ -1,3 +1,3 @@
1
1
  module SnowSync
2
- VERSION = "2.0.3"
2
+ VERSION = "2.0.4"
3
3
  end
@@ -74,25 +74,30 @@ describe "check_required_configs" do
74
74
  end
75
75
 
76
76
  it "should raise an exception when there is no config path" do
77
- util.configs["conf_path"] = "test/bad/path"
78
- expect{util.check_required_configs}.to raise_error(/Please check the configuration path, credentials or table to sync/)
77
+ util.configs["conf_path"] = nil
78
+ expect{util.check_required_configs}.to raise_error(/Check the configuration path, base url, credentials or table to sync/)
79
+ end
80
+
81
+ it "should raise an exception when there is no base url" do
82
+ util.configs["base_url"] = nil
83
+ expect{util.check_required_configs}.to raise_error(/Check the configuration path, base url, credentials or table to sync/)
79
84
  end
80
85
 
81
86
  it "should raise an exception when there is no username" do
82
87
  util.configs["creds"]["user"] = nil
83
- expect{util.check_required_configs}.to raise_error(/Please check the configuration path, credentials or table to sync/)
88
+ expect{util.check_required_configs}.to raise_error(/Check the configuration path, base url, credentials or table to sync/)
84
89
  end
85
90
 
86
91
  it "should raise an exception when there is no password" do
87
92
  util.configs["creds"]["pass"] = nil
88
- expect{util.check_required_configs}.to raise_error(/Please check the configuration path, credentials or table to sync/)
93
+ expect{util.check_required_configs}.to raise_error(/Check the configuration path, base url, credentials or table to sync/)
89
94
  end
90
95
 
91
96
  it "should raise an exception when there are no tables mapped" do
92
97
  tables = util.configs["table_map"].keys
93
98
  tables.each do |table|
94
99
  util.configs["table_map"][table]["table"] = nil
95
- expect{util.check_required_configs}.to raise_error(/Please check the configuration path, credentials or table to sync/)
100
+ expect{util.check_required_configs}.to raise_error(/Check the configuration path, base url, credentials or table to sync/)
96
101
  end
97
102
  end
98
103
 
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: 2.0.3
4
+ version: 2.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Wallace
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-12-12 00:00:00.000000000 Z
11
+ date: 2016-12-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler