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