phoseum-cli 0.0.9 → 0.0.10
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/bin/phoseum-cli +99 -63
- data/lib/phoseum/phoseum-cli-lib.rb +88 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a9472d2d52deb75c37183130fce537c43f87e25d2c5366f73d34e2e39f4b2f67
|
4
|
+
data.tar.gz: 6e37a6d2768e87133c97e5a7d5257595e39b9a97483be4eddc109f38f15e81e6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a249f7bebf5c8621067a8f52a560ad6c24867d09956acd7e1323c79aa60628d8261ae06f73e45e54e1355ba07b673c883176c13273616c7c66683f90536f2f74
|
7
|
+
data.tar.gz: ea4973b4317ee70af953b628fefda619bbc35bc355434bf9c61f2d037ba058194a57959ffa6ef5c976728ae6298bc966af114e269407bf34dd82eca680de569c
|
data/bin/phoseum-cli
CHANGED
@@ -24,16 +24,16 @@ $MULTI = options[:multiple] ? true : false
|
|
24
24
|
client_checks
|
25
25
|
|
26
26
|
def upload(album)
|
27
|
-
|
28
|
-
if $config['TOKEN']
|
29
|
-
headers={ "bearer" => "#{$config['TOKEN']}" }
|
30
|
-
else
|
27
|
+
headers = {}
|
28
|
+
if !validate_token($config['TOKEN'])
|
31
29
|
if token = user_login()
|
32
30
|
headers = { "bearer" => token }
|
33
31
|
else
|
34
32
|
puts "Login Failed".red
|
35
33
|
exit 1
|
36
34
|
end
|
35
|
+
else
|
36
|
+
headers={ "bearer" => "#{$config['TOKEN']}" }
|
37
37
|
end
|
38
38
|
|
39
39
|
list=Dir.entries("./")
|
@@ -154,15 +154,15 @@ end
|
|
154
154
|
|
155
155
|
def health(what='',name='')
|
156
156
|
headers = {}
|
157
|
-
if $config['TOKEN']
|
158
|
-
headers={ "bearer" => "#{$config['TOKEN']}" }
|
159
|
-
else
|
157
|
+
if !validate_token($config['TOKEN'])
|
160
158
|
if token = user_login()
|
161
159
|
headers = { "bearer" => token }
|
162
160
|
else
|
163
161
|
puts "Login Failed".red
|
164
162
|
exit 1
|
165
163
|
end
|
164
|
+
else
|
165
|
+
headers={ "bearer" => "#{$config['TOKEN']}" }
|
166
166
|
end
|
167
167
|
some_uri=''
|
168
168
|
if what == "album"
|
@@ -264,29 +264,28 @@ def user_mgmt(action,user,pass='',role='')
|
|
264
264
|
exit 0
|
265
265
|
end
|
266
266
|
|
267
|
-
def user_login()
|
267
|
+
def user_login(puser='',ppass='')
|
268
268
|
post_body={}
|
269
|
-
user=''
|
270
|
-
pass=''
|
269
|
+
user= !puser ? '' : puser
|
270
|
+
pass= !ppass ? '' : ppass
|
271
271
|
if $config['USER']
|
272
272
|
user=$config['USER']
|
273
273
|
else
|
274
274
|
print "Username: "
|
275
|
-
user=STDIN.
|
275
|
+
user=STDIN.gets.chomp
|
276
276
|
end
|
277
277
|
if $config['PASS']
|
278
278
|
pass=$config['PASS']
|
279
|
-
puts "
|
279
|
+
puts "\nKeeping your password on the configuration file is UNSAFE".red
|
280
280
|
else
|
281
|
-
|
282
|
-
pass=STDIN.noecho(&:gets).chomp
|
281
|
+
pass=STDIN.getpass('Password: ')
|
283
282
|
end
|
284
283
|
post_body=JSON.generate({"action" => "user-login", "user" => "#{user}", "password" => "#{pass}"})
|
285
284
|
base = URI.parse("#{$config['SERVERURL']}")
|
286
285
|
puts "\nLogging to: #{$config['SERVERURL']}".yellow if !$QUIET
|
287
286
|
request = Net::HTTP::Post.new(base)
|
288
287
|
request.body = post_body
|
289
|
-
request.basic_auth("
|
288
|
+
request.basic_auth("cli", "loginNOauth")
|
290
289
|
response = Net::HTTP.start(base.hostname, $config['PORT'],
|
291
290
|
:timeout => $config['CALL_TIMEOUT'],
|
292
291
|
:use_ssl => base.scheme == "https",
|
@@ -323,50 +322,40 @@ end
|
|
323
322
|
|
324
323
|
|
325
324
|
def delete(what='',path='')
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
if confirm == "YES"
|
331
|
-
headers={}
|
332
|
-
if $config['TOKEN']
|
333
|
-
headers={ "bearer" => "#{$config['TOKEN']}" }
|
325
|
+
if !validate_token($config['TOKEN'])
|
326
|
+
if token = user_login()
|
327
|
+
headers = { "bearer" => token }
|
334
328
|
else
|
335
|
-
|
336
|
-
headers = { "bearer" => token }
|
337
|
-
else
|
338
|
-
puts "Login Failed".red
|
339
|
-
exit 1
|
340
|
-
end
|
341
|
-
end
|
342
|
-
|
343
|
-
base = URI.parse("#{$config['SERVERURL']}/#{path}")
|
344
|
-
puts "Connecting to: #{$config['SERVERURL']}".yellow if !$QUIET
|
345
|
-
request = Net::HTTP::Delete.new(base,headers)
|
346
|
-
response = Net::HTTP.start(base.hostname, $config['PORT'],
|
347
|
-
:timeout => $config['CALL_TIMEOUT'],
|
348
|
-
:use_ssl => base.scheme == "https",
|
349
|
-
:verify_mode => OpenSSL::SSL::VERIFY_PEER,
|
350
|
-
:ca_file => $config['CA_TRUST']
|
351
|
-
) do |http|
|
352
|
-
http.request(request)
|
353
|
-
end
|
354
|
-
begin
|
355
|
-
list = JSON.parse(response.body)
|
356
|
-
if list['error']
|
357
|
-
puts list['error'].red
|
358
|
-
exit 1
|
359
|
-
else
|
360
|
-
puts list['success'].green
|
361
|
-
exit 0
|
362
|
-
end
|
363
|
-
rescue
|
364
|
-
puts "\nThe server sent out an Error:".red
|
365
|
-
puts clean_html(response.body)
|
329
|
+
puts "Login Failed".red
|
366
330
|
exit 1
|
367
331
|
end
|
368
332
|
else
|
369
|
-
|
333
|
+
headers={ "bearer" => "#{$config['TOKEN']}" }
|
334
|
+
end
|
335
|
+
base = URI.parse("#{$config['SERVERURL']}/#{path}")
|
336
|
+
puts "Connecting to: #{$config['SERVERURL']}".yellow if !$QUIET
|
337
|
+
request = Net::HTTP::Delete.new(base,headers)
|
338
|
+
response = Net::HTTP.start(base.hostname, $config['PORT'],
|
339
|
+
:timeout => $config['CALL_TIMEOUT'],
|
340
|
+
:use_ssl => base.scheme == "https",
|
341
|
+
:verify_mode => OpenSSL::SSL::VERIFY_PEER,
|
342
|
+
:ca_file => $config['CA_TRUST']
|
343
|
+
) do |http|
|
344
|
+
http.request(request)
|
345
|
+
end
|
346
|
+
begin
|
347
|
+
list = JSON.parse(response.body)
|
348
|
+
if list['error']
|
349
|
+
puts list['error'].red
|
350
|
+
exit 1
|
351
|
+
else
|
352
|
+
puts list['success'].green
|
353
|
+
exit 0
|
354
|
+
end
|
355
|
+
rescue
|
356
|
+
puts "\nThe server sent out an Error:".red
|
357
|
+
puts clean_html(response.body)
|
358
|
+
exit 1
|
370
359
|
end
|
371
360
|
end
|
372
361
|
|
@@ -387,10 +376,10 @@ case options
|
|
387
376
|
puts "You need to select one of the valid Roles".red
|
388
377
|
exit 1
|
389
378
|
else
|
390
|
-
print "Please type the password twice for user #{value}.\n\
|
391
|
-
new_password=STDIN.
|
392
|
-
print "\
|
393
|
-
confirm=STDIN.
|
379
|
+
print "Please type the password twice for user #{value}.\n\t"
|
380
|
+
new_password=STDIN.getpass('Password: ')
|
381
|
+
print "\t"
|
382
|
+
confirm=STDIN.getpass('Confirm: ')
|
394
383
|
if new_password == confirm
|
395
384
|
user_mgmt(what,value,new_password,options[:role])
|
396
385
|
end
|
@@ -405,19 +394,66 @@ case options
|
|
405
394
|
puts "It is Not possible to delete base album".red
|
406
395
|
exit 1
|
407
396
|
end
|
397
|
+
if !confirm_action("Are you sure you want to delete the #{what} #{value}")
|
398
|
+
puts "Deleting #{what} cancelled.".green
|
399
|
+
end
|
408
400
|
end
|
409
401
|
if options[:image]
|
410
402
|
if _found = check_image_exists(options[:image])
|
411
|
-
|
412
|
-
|
403
|
+
if _found =~ /^Signature Found at \[\"(.*)\"\]/
|
404
|
+
capt = _found.match(/^Signature Found at \[\"(.*)\"\]/).captures
|
405
|
+
capt_part = capt[0].match(/.*(Albums.*)$/).captures
|
406
|
+
value = capt_part[0]
|
407
|
+
else
|
408
|
+
img_data = JSON.parse(_found)
|
409
|
+
value="#{img_data['web_path']}/#{img_data['image']}"
|
410
|
+
end
|
413
411
|
what='image'
|
414
412
|
else
|
415
413
|
puts "Image not found on server".red
|
416
414
|
exit 1
|
417
415
|
end
|
416
|
+
if confirm_action("Are you sure you want to delete the #{what} #{value}")
|
417
|
+
puts "Deleting #{what} #{value}".green if !$QUIET
|
418
|
+
delete(what,value)
|
419
|
+
else
|
420
|
+
puts "Deleting #{what} cancelled.".green
|
421
|
+
end
|
422
|
+
end
|
423
|
+
if options[:user]
|
424
|
+
what='user'
|
425
|
+
value=options[:user]
|
426
|
+
if confirm_action("Are you sure you want to delete the #{what} #{value}")
|
427
|
+
puts "Deleting #{what} #{value}".green if !$QUIET
|
428
|
+
if delete_user(value)
|
429
|
+
puts "#{value} successfully deleted.".green
|
430
|
+
else
|
431
|
+
puts "#{value} failed to be deleted.".red
|
432
|
+
end
|
433
|
+
else
|
434
|
+
puts "Deleting #{what} cancelled.".green
|
435
|
+
end
|
436
|
+
end
|
437
|
+
if !what
|
438
|
+
puts "Got no object to delete. Exiting.".red
|
439
|
+
exit 1
|
440
|
+
end
|
441
|
+
when -> (o) { o[:options] }
|
442
|
+
if options[:user]
|
443
|
+
print "Please confirm #{options[:user]} password.\n\t"
|
444
|
+
current_password=STDIN.getpass('Password: ')
|
445
|
+
if token = user_login(options[:user],current_password)
|
446
|
+
print "\n Change [P]assword, [U]sername, [R]ole :[P/U/R]: "
|
447
|
+
confirm=STDIN.gets.chomp
|
448
|
+
else
|
449
|
+
puts "User Check Failed".red
|
450
|
+
exit 1
|
451
|
+
end
|
452
|
+
else
|
453
|
+
# if !what
|
454
|
+
puts "Got no user to work with. Exiting.".red
|
455
|
+
exit 1
|
418
456
|
end
|
419
|
-
puts "Deleting #{what} #{value}".green if !$QUIET
|
420
|
-
delete(what,value)
|
421
457
|
when -> (u) { u[:upload] }
|
422
458
|
puts "Preparing to upload images to API server".green if !$QUIET
|
423
459
|
if !options.key?(:album)
|
@@ -44,6 +44,10 @@ def option_parser(opts)
|
|
44
44
|
options[:role] = r
|
45
45
|
end
|
46
46
|
|
47
|
+
opts.on("-o", "--options", "Update options from object. Use with: [user]") do |o|
|
48
|
+
options[:options] = o
|
49
|
+
end
|
50
|
+
|
47
51
|
opts.on("-q", "--quiet", "Avoid regular info, useful for JSON output") do |q|
|
48
52
|
options[:quiet] = q
|
49
53
|
end
|
@@ -56,6 +60,10 @@ def option_parser(opts)
|
|
56
60
|
options[:upload] = u
|
57
61
|
end
|
58
62
|
|
63
|
+
opts.on("-U", "--User USERNAME", "Username for delete or change password / role. Use with: [delete, options]") do |usr|
|
64
|
+
options[:user] = usr
|
65
|
+
end
|
66
|
+
|
59
67
|
opts.on("-h", "-h", "That is this...") do |h|
|
60
68
|
options[:help] = h
|
61
69
|
end
|
@@ -64,6 +72,17 @@ def option_parser(opts)
|
|
64
72
|
return options
|
65
73
|
end
|
66
74
|
|
75
|
+
def confirm_action(msg)
|
76
|
+
puts "You must write 'YES' to confirm, otherwise NO is assumed".yellow
|
77
|
+
print "#{msg} :[YES/NO]: "
|
78
|
+
confirm=STDIN.gets.chomp
|
79
|
+
if confirm == "YES"
|
80
|
+
return true
|
81
|
+
else
|
82
|
+
return false
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
67
86
|
class String
|
68
87
|
# colorization
|
69
88
|
def colorize(color_code)
|
@@ -145,16 +164,15 @@ def check_image_exists(fpath)
|
|
145
164
|
end
|
146
165
|
|
147
166
|
def search_image(sign,album='')
|
148
|
-
|
149
|
-
if $config['TOKEN']
|
150
|
-
headers={ "bearer" => "#{$config['TOKEN']}" }
|
151
|
-
else
|
167
|
+
if !validate_token($config['TOKEN'])
|
152
168
|
if token = user_login()
|
153
169
|
headers = { "bearer" => token }
|
154
170
|
else
|
155
171
|
puts "Login Failed".red
|
156
172
|
exit 1
|
157
173
|
end
|
174
|
+
else
|
175
|
+
headers={ "bearer" => "#{$config['TOKEN']}" }
|
158
176
|
end
|
159
177
|
some_uri= album == '' ? "?signature=#{sign}" : "?signature=#{sign}&inside_album=#{album}"
|
160
178
|
base = URI.parse("#{$config['SERVERURL']}#{some_uri}")
|
@@ -182,3 +200,69 @@ def search_image(sign,album='')
|
|
182
200
|
exit 1
|
183
201
|
end
|
184
202
|
end
|
203
|
+
|
204
|
+
def validate_token(token)
|
205
|
+
headers = {}
|
206
|
+
if $config['TOKEN']
|
207
|
+
headers={ "bearer" => "#{$config['TOKEN']}" }
|
208
|
+
else
|
209
|
+
return false
|
210
|
+
end
|
211
|
+
base = URI.parse("#{$config['SERVERURL']}")
|
212
|
+
request = Net::HTTP::Post.new(base,headers)
|
213
|
+
request.body = JSON.generate({"action" => "check-token" })
|
214
|
+
response = Net::HTTP.start(base.hostname, $config['PORT'],
|
215
|
+
:timeout => $config['CALL_TIMEOUT'],
|
216
|
+
:use_ssl => base.scheme == "https",
|
217
|
+
:verify_mode => OpenSSL::SSL::VERIFY_PEER,
|
218
|
+
:ca_file => $config['CA_TRUST']
|
219
|
+
) do |http|
|
220
|
+
http.request(request)
|
221
|
+
end
|
222
|
+
begin
|
223
|
+
list = JSON.parse(response.body)
|
224
|
+
if list['error']
|
225
|
+
return false
|
226
|
+
end
|
227
|
+
if list['success']
|
228
|
+
return true
|
229
|
+
end
|
230
|
+
rescue
|
231
|
+
puts "\nThe server sent out an Error:".red
|
232
|
+
puts clean_html(response.body)
|
233
|
+
exit 1
|
234
|
+
end
|
235
|
+
end
|
236
|
+
|
237
|
+
def delete_user(username)
|
238
|
+
headers = {}
|
239
|
+
if $config['TOKEN']
|
240
|
+
headers={ "bearer" => "#{$config['TOKEN']}" }
|
241
|
+
else
|
242
|
+
return false
|
243
|
+
end
|
244
|
+
base = URI.parse("#{$config['SERVERURL']}")
|
245
|
+
request = Net::HTTP::Post.new(base,headers)
|
246
|
+
request.body = JSON.generate({"action" => "delete-user", "username" => username })
|
247
|
+
response = Net::HTTP.start(base.hostname, $config['PORT'],
|
248
|
+
:timeout => $config['CALL_TIMEOUT'],
|
249
|
+
:use_ssl => base.scheme == "https",
|
250
|
+
:verify_mode => OpenSSL::SSL::VERIFY_PEER,
|
251
|
+
:ca_file => $config['CA_TRUST']
|
252
|
+
) do |http|
|
253
|
+
http.request(request)
|
254
|
+
end
|
255
|
+
begin
|
256
|
+
list = JSON.parse(response.body)
|
257
|
+
if list['error']
|
258
|
+
return false
|
259
|
+
end
|
260
|
+
if list['success']
|
261
|
+
return true
|
262
|
+
end
|
263
|
+
rescue
|
264
|
+
puts "\nThe server sent out an Error:".red
|
265
|
+
puts clean_html(response.body)
|
266
|
+
exit 1
|
267
|
+
end
|
268
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: phoseum-cli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Julio C Hegedus
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-09-
|
11
|
+
date: 2020-09-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: yaml
|