Browse Source

fixes to restful get/set and execution tracing

Jaromil 4 years ago
parent
commit
c3adf9d355
1 changed files with 18 additions and 21 deletions
  1. 18 21
      zuper

+ 18 - 21
zuper

@@ -153,7 +153,7 @@ ckreq reqck() {
153 153
     err=0
154 154
     for v in $req; do
155 155
         [[ "${(P)v}" = "" ]] && {
156
-            warn "required setting is blank: $v"
156
+            warn "${fun[(ws: :)1]}(): required setting is blank: $v"
157 157
             err=1
158 158
         }
159 159
     done
@@ -266,15 +266,15 @@ destruens+=(_ztmp_destructor)
266 266
 # saves everything in global array tok=()
267 267
 arrs+=(tok)
268 268
 strtok() {
269
-    fun="strtok $*"
269
+    fn "strtok $*"
270 270
     _string="$1"
271 271
     _delim="$2"
272 272
     req=(_string _delim)
273 273
     ckreq || return $?
274 274
 
275 275
     tok=()
276
-    local f=0
277
-    local c=0
276
+    f=0
277
+    c=0
278 278
     for c in {1..${#_string}}; do
279 279
         if [[ "${_string[(e)$c]}" == "$_delim" ]]; then
280 280
             # check if not empty
@@ -370,35 +370,33 @@ EOF
370 370
 
371 371
     zmodload zsh/net/tcp
372 372
 
373
+
373 374
     function restful.put() {
375
+        fn "restful.put $*"
376
+
374 377
         # $1 = hostname
375 378
         # $2 = port
376 379
         # $3 = path
377
-        # $4 = key
378
-        # $5 = value
379
-
380
-        fn "restful.put $*"
380
+        # value from stdin |
381 381
 
382 382
         # to check if the http service is running is up to the caller
383 383
 
384 384
         _host=${1} # ip address
385 385
         _port=${2}
386 386
         _path=${3}
387
-        _k="$4" # key name
388
-        _v="$5" # value
387
+        sysread _v
389 388
 
390
-        req=(_host _k _v)
389
+        req=(_host)
391 390
         ckreq || return $?
392 391
 
393 392
         if ztcp $_host $_port; then
394 393
 
395
-
396 394
             # TODO: work out various parsers, this one works with consul.io
397 395
 
398 396
             _fd=$REPLY
399 397
             #    func "tcp open on fd $fd"
400 398
             cat <<EOF >& $_fd
401
-PUT ${_path}${_k} HTTP/1.1
399
+PUT ${_path} HTTP/1.1
402 400
 User-Agent: Zuper/$zuper_version
403 401
 Host: ${_host}:${_port}
404 402
 Accept: */*
@@ -416,8 +414,10 @@ EOF
416 414
 
417 415
             [[ "$_res" =~ "true" ]] || {
418 416
                 warn "failed PUT on restful key/value"
419
-                warn "endpoint: ${_host}:${_port}${_path}"
420
-                warn "resource: $_k = $_v"
417
+                warn "host: ${_host}"
418
+                warn "port: ${_port}"
419
+                warn "path: ${_path}"
420
+                warn "value: $_v"
421 421
                 print - "$_res"
422 422
                 zerr
423 423
                 return 1
@@ -433,19 +433,16 @@ EOF
433 433
 
434 434
     }
435 435
 
436
-    restful.get() {
436
+    function restful.get() {
437 437
         fn "restful.get $*"
438 438
 
439 439
         _host=${1}
440 440
         _port=${2}
441 441
         _path=${3}
442
-        _k=$4 # key name
443 442
 
444
-        req=(_host _k)
443
+        req=(_host _port)
445 444
         ckreq || return $?
446 445
 
447
-        _k=$1
448
-
449 446
         ztcp $_host $_port || {
450 447
             zerr
451 448
             return 1
@@ -456,7 +453,7 @@ EOF
456 453
         # TODO: work out various parsers, this one works with consul.io
457 454
 
458 455
         cat <<EOF >& $_fd
459
-GET ${_path}${_k} HTTP/1.1
456
+GET ${_path} HTTP/1.1
460 457
 User-Agent: Zuper/$zuper_version
461 458
 Host: $_host:$_port
462 459
 Accept: */*