mirror of https://github.com/dyne/zuper.git
fixes to restful get/set and execution tracing
This commit is contained in:
parent
fca82a9e74
commit
c3adf9d355
|
|
@ -153,7 +153,7 @@ ckreq reqck() {
|
|||
err=0
|
||||
for v in $req; do
|
||||
[[ "${(P)v}" = "" ]] && {
|
||||
warn "required setting is blank: $v"
|
||||
warn "${fun[(ws: :)1]}(): required setting is blank: $v"
|
||||
err=1
|
||||
}
|
||||
done
|
||||
|
|
@ -266,15 +266,15 @@ destruens+=(_ztmp_destructor)
|
|||
# saves everything in global array tok=()
|
||||
arrs+=(tok)
|
||||
strtok() {
|
||||
fun="strtok $*"
|
||||
fn "strtok $*"
|
||||
_string="$1"
|
||||
_delim="$2"
|
||||
req=(_string _delim)
|
||||
ckreq || return $?
|
||||
|
||||
tok=()
|
||||
local f=0
|
||||
local c=0
|
||||
f=0
|
||||
c=0
|
||||
for c in {1..${#_string}}; do
|
||||
if [[ "${_string[(e)$c]}" == "$_delim" ]]; then
|
||||
# check if not empty
|
||||
|
|
@ -370,35 +370,33 @@ EOF
|
|||
|
||||
zmodload zsh/net/tcp
|
||||
|
||||
|
||||
function restful.put() {
|
||||
fn "restful.put $*"
|
||||
|
||||
# $1 = hostname
|
||||
# $2 = port
|
||||
# $3 = path
|
||||
# $4 = key
|
||||
# $5 = value
|
||||
|
||||
fn "restful.put $*"
|
||||
# value from stdin |
|
||||
|
||||
# to check if the http service is running is up to the caller
|
||||
|
||||
_host=${1} # ip address
|
||||
_port=${2}
|
||||
_path=${3}
|
||||
_k="$4" # key name
|
||||
_v="$5" # value
|
||||
sysread _v
|
||||
|
||||
req=(_host _k _v)
|
||||
req=(_host)
|
||||
ckreq || return $?
|
||||
|
||||
if ztcp $_host $_port; then
|
||||
|
||||
|
||||
# TODO: work out various parsers, this one works with consul.io
|
||||
|
||||
_fd=$REPLY
|
||||
# func "tcp open on fd $fd"
|
||||
cat <<EOF >& $_fd
|
||||
PUT ${_path}${_k} HTTP/1.1
|
||||
PUT ${_path} HTTP/1.1
|
||||
User-Agent: Zuper/$zuper_version
|
||||
Host: ${_host}:${_port}
|
||||
Accept: */*
|
||||
|
|
@ -416,8 +414,10 @@ EOF
|
|||
|
||||
[[ "$_res" =~ "true" ]] || {
|
||||
warn "failed PUT on restful key/value"
|
||||
warn "endpoint: ${_host}:${_port}${_path}"
|
||||
warn "resource: $_k = $_v"
|
||||
warn "host: ${_host}"
|
||||
warn "port: ${_port}"
|
||||
warn "path: ${_path}"
|
||||
warn "value: $_v"
|
||||
print - "$_res"
|
||||
zerr
|
||||
return 1
|
||||
|
|
@ -433,19 +433,16 @@ EOF
|
|||
|
||||
}
|
||||
|
||||
restful.get() {
|
||||
function restful.get() {
|
||||
fn "restful.get $*"
|
||||
|
||||
_host=${1}
|
||||
_port=${2}
|
||||
_path=${3}
|
||||
_k=$4 # key name
|
||||
|
||||
req=(_host _k)
|
||||
req=(_host _port)
|
||||
ckreq || return $?
|
||||
|
||||
_k=$1
|
||||
|
||||
ztcp $_host $_port || {
|
||||
zerr
|
||||
return 1
|
||||
|
|
@ -456,7 +453,7 @@ EOF
|
|||
# TODO: work out various parsers, this one works with consul.io
|
||||
|
||||
cat <<EOF >& $_fd
|
||||
GET ${_path}${_k} HTTP/1.1
|
||||
GET ${_path} HTTP/1.1
|
||||
User-Agent: Zuper/$zuper_version
|
||||
Host: $_host:$_port
|
||||
Accept: */*
|
||||
|
|
|
|||
Loading…
Reference in New Issue