gaddygaddy 0.1.91 → 0.1.92
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/gaddygaddy-client.rb +30 -6
- data/lib/utils/request.rb +4 -4
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7e6782e2bf303d99fae32b38e8db4d562551e5cc
|
4
|
+
data.tar.gz: 704427a3b6d16fd477a715b96e75dd70e46095aa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 46d81cef9ed49f4b342160a24ac3e51dc606bd11243688f35355e518bd94935f5b446a8fd31125aebafb7b1074a2e354e5fbb1d9d63af1d5d759010e4f351fbf
|
7
|
+
data.tar.gz: 6ab4d3f7305f6ddf06a84785d65b634207a04103b1931fdb40d021da87e7c64487ef5089b66ea0e479eda7aea8b6e4228b557de054e41a1cdfa3211b852a75b4
|
data/lib/gaddygaddy-client.rb
CHANGED
@@ -292,6 +292,21 @@ class GaddyGaddy_Client
|
|
292
292
|
conf_content
|
293
293
|
end
|
294
294
|
|
295
|
+
# Create a new user
|
296
|
+
def create_user(user_name, password)
|
297
|
+
url = Request.get_base_url(get_host) + "/user/1"
|
298
|
+
params = {
|
299
|
+
:model =>
|
300
|
+
{
|
301
|
+
:user_email => URI.encode(user_name),
|
302
|
+
:user_password => password
|
303
|
+
}
|
304
|
+
}.to_json
|
305
|
+
response = Request.client_service_post url, params
|
306
|
+
logger.debug "The response for the request is #{response} #{response.class}"
|
307
|
+
raise JCouldNotPostClientDataException.new({:message=> "Could not post data to the gaddygaddy service, error code is #{response.body}"}) unless response[:status].to_i == 0
|
308
|
+
end
|
309
|
+
|
295
310
|
def create_gaddy(gaddy_name, user_name, password)
|
296
311
|
url = Request.get_base_url(get_host) + "/installation/device/1"
|
297
312
|
params = {:device_name => gaddy_name,
|
@@ -303,10 +318,10 @@ class GaddyGaddy_Client
|
|
303
318
|
raise JCouldNotPostClientDataException.new({:message=> "Could not post data to the gaddygaddy service, error code is #{response.body}"}) unless response[:status].to_i == 0
|
304
319
|
end
|
305
320
|
|
306
|
-
def create_new(name)
|
321
|
+
def create_new?(name, type)
|
307
322
|
inp = ''
|
308
323
|
unless @options[:create]
|
309
|
-
puts "
|
324
|
+
puts "#{type} #{name} doesn't exist, would you like to create it (Y/N)"
|
310
325
|
answer = nil
|
311
326
|
while answer.nil?
|
312
327
|
inp = gets.chomp.upcase
|
@@ -314,7 +329,7 @@ class GaddyGaddy_Client
|
|
314
329
|
answer = ['Y','N'].index(inp[0]) ? inp : nil
|
315
330
|
else
|
316
331
|
puts
|
317
|
-
puts "
|
332
|
+
puts "#{type} #{name} doesn't exist, would you like to create it (Y/N)"
|
318
333
|
end
|
319
334
|
end
|
320
335
|
end
|
@@ -329,8 +344,18 @@ class GaddyGaddy_Client
|
|
329
344
|
rescue Exception => e
|
330
345
|
raise e.inspect
|
331
346
|
end
|
332
|
-
|
333
|
-
|
347
|
+
puts "1"
|
348
|
+
begin
|
349
|
+
status_gaddy = get_conf_file['status']
|
350
|
+
rescue RestClient::Unauthorized => e
|
351
|
+
if create_new?(user_name, 'User')
|
352
|
+
logger.info "Will create a new user #{user_name}"
|
353
|
+
create_user(user_name, password)
|
354
|
+
end
|
355
|
+
status_gaddy = get_conf_file['status']
|
356
|
+
end
|
357
|
+
if status_gaddy == 12 || status_gaddy == 4
|
358
|
+
if create_new?(gaddy_name, 'Gaddy')
|
334
359
|
logger.info "Will create a new gaddy named #{gaddy_name}"
|
335
360
|
create_gaddy(gaddy_name, user_name, password)
|
336
361
|
if get_conf_file['status'] == 12
|
@@ -341,7 +366,6 @@ class GaddyGaddy_Client
|
|
341
366
|
puts 'If you would like to create it add parameter --create to the command'
|
342
367
|
end
|
343
368
|
end
|
344
|
-
|
345
369
|
end
|
346
370
|
|
347
371
|
# Check that the config file exist and has valid content, this will also be validated toward the server
|
data/lib/utils/request.rb
CHANGED
@@ -34,18 +34,18 @@ class Request
|
|
34
34
|
# path will be evaluated so there could be parameters in that one and then use '' for the string
|
35
35
|
# to have the parameters evaluated in this function
|
36
36
|
#
|
37
|
-
def self.client_service_get(host, path)
|
37
|
+
def self.client_service_get(host, path, retries = 1)
|
38
38
|
url = get_base_url(host) + path
|
39
39
|
logger.debug "Will request url #{url}"
|
40
|
-
result = with_retries(:limit =>
|
40
|
+
result = with_retries(:limit => retries, :sleep=> 5) { RestClient.get url }
|
41
41
|
result_json = JSON.parse(result)
|
42
42
|
logger.debug "The result of the request is #{result.inspect}"
|
43
43
|
result_json
|
44
44
|
end
|
45
45
|
|
46
|
-
def self.client_service_post(url, param)
|
46
|
+
def self.client_service_post(url, param, retries = 1)
|
47
47
|
logger.debug "Will request url #{url}"
|
48
|
-
result = with_retries(:limit =>
|
48
|
+
result = with_retries(:limit => retries, :sleep=> 5) { RestClient.post url, param }
|
49
49
|
JSON.parse(result)
|
50
50
|
end
|
51
51
|
|