Skip to content

Commit

Permalink
Renaming SHIELD_TARGET to SHIELD_API
Browse files Browse the repository at this point in the history
  • Loading branch information
xiujiao committed Jan 25, 2016
1 parent 64dd467 commit d9b3a27
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 20 deletions.
2 changes: 1 addition & 1 deletion api/api.go
Expand Up @@ -48,7 +48,7 @@ func (yn *YesNo) Given() bool {
}

func ShieldURI(p string, args ...interface{}) *URL {
endpoint := strings.TrimSuffix(os.Getenv("SHIELD_TARGET"), "/")
endpoint := strings.TrimSuffix(os.Getenv("SHIELD_API"), "/")
if endpoint == "" {
endpoint = "https://shield"
}
Expand Down
22 changes: 11 additions & 11 deletions bin/bkp
Expand Up @@ -70,7 +70,7 @@ need() {
}

need_target() {
need "--shield http://address.of.your.shield:8080 option" ${SHIELD_TARGET}
need "--shield http://address.of.your.shield:8080 option" ${SHIELD_API}
}

tempfile() {
Expand Down Expand Up @@ -101,14 +101,14 @@ editor() {

GET() {
url=${1}
curl -Ls ${curl_opts} -X GET ${SHIELD_TARGET}${url} | jq ${jq_opts} .
curl -Ls ${curl_opts} -X GET ${SHIELD_API}${url} | jq ${jq_opts} .
}

evalGET() {
url=${1}
prefix=${2}

eval $(curl -Ls ${SHIELD_TARGET}${url} | \
eval $(curl -Ls ${SHIELD_API}${url} | \
jq -rM 'to_entries | map("'$prefix'_\(.key)=\"\(.value)\"") | .[]' | \
grep "^${prefix}_.*=")
}
Expand All @@ -118,9 +118,9 @@ POST() {
file=${2}

if [[ -z ${file} ]]; then
curl -Ls ${curl_opts} -X POST ${SHIELD_TARGET}${url} | jq ${jq_opts} .
curl -Ls ${curl_opts} -X POST ${SHIELD_API}${url} | jq ${jq_opts} .
else
curl -Ls ${curl_opts} -X POST ${SHIELD_TARGET}${url} \
curl -Ls ${curl_opts} -X POST ${SHIELD_API}${url} \
--data-binary "$(cat ${file} | yaml2json)" | jq ${jq_opts} .
fi
}
Expand All @@ -130,16 +130,16 @@ PUT() {
file=${2}

if [[ -z ${file} ]]; then
curl -Ls ${curl_opts} -X PUT ${SHIELD_TARGET}${url} | jq ${jq_opts} .
curl -Ls ${curl_opts} -X PUT ${SHIELD_API}${url} | jq ${jq_opts} .
else
curl -Ls ${curl_opts} -X PUT ${SHIELD_TARGET}${url} \
curl -Ls ${curl_opts} -X PUT ${SHIELD_API}${url} \
--data-binary "$(cat ${file} | yaml2json)" | jq ${jq_opts} .
fi
}

DELETE() {
url=${1}
curl -Ls ${curl_opts} -X DELETE ${SHIELD_TARGET}${url} | jq ${jq_opts} .
curl -Ls ${curl_opts} -X DELETE ${SHIELD_API}${url} | jq ${jq_opts} .
}

list_schedules() {
Expand Down Expand Up @@ -591,8 +591,8 @@ while (( "$#" )); do
exit 0
;;

(-t|--target) shift ; SHIELD_TARGET=${1} ; shift ;;
(--shield) shift ; SHIELD_TARGET=${1} ; shift ;;
(-t|--target) shift ; SHIELD_API=${1} ; shift ;;
(--shield) shift ; SHIELD_API=${1} ; shift ;;
(-r|--raw) shift ; jq_opts="-rM" ;;
(-v|--verbose) shift ; curl_opts="-v" ;;

Expand Down Expand Up @@ -802,7 +802,7 @@ while (( "$#" )); do

(key)
need_target
curl -Ls ${curl_opts} -X GET ${SHIELD_TARGET}/v1/meta/pubkey
curl -Ls ${curl_opts} -X GET ${SHIELD_API}/v1/meta/pubkey
exit $?
;;

Expand Down
12 changes: 6 additions & 6 deletions cmd/shield/main.go
Expand Up @@ -88,14 +88,14 @@ func main() {
debug = *options.Debug
DEBUG("shield cli starting up")
if *options.Shield != "" {
DEBUG("setting SHIELD_TARGET to '%s'", *options.Shield)
os.Setenv("SHIELD_TARGET", *options.Shield)
DEBUG("setting SHIELD_API to '%s'", *options.Shield)
os.Setenv("SHIELD_API", *options.Shield)
} else {
variable_value, variable_set := os.LookupEnv("SHIELD_TARGET")
variable_value, variable_set := os.LookupEnv("SHIELD_API")
if variable_set && len(variable_value) > 6 {
DEBUG("SHIELD_TARGET is currently set to '%s'", *options.Shield)
DEBUG("SHIELD_API is currently set to '%s'", *options.Shield)
} else {
fmt.Fprintf(os.Stderr, "shield IP:port unspecified. Please use either SHIELD_TARGET or `shield -H'.\n")
fmt.Fprintf(os.Stderr, "shield IP:port unspecified. Please use either SHIELD_API or `shield -H'.\n")
}
}

Expand All @@ -111,7 +111,7 @@ func main() {
fmt.Fprintf(os.Stderr, "shield\n")
fmt.Fprintf(os.Stderr, "USAGE: shield [options] <command>\n\n")
fmt.Fprintf(os.Stderr, "Recommended:\n")
fmt.Fprintf(os.Stderr, " Use SHIELD_TARGET environmental variable to store shield's IP:port.\n\n")
fmt.Fprintf(os.Stderr, " Use SHIELD_API environmental variable to store shield's IP:port.\n\n")
fmt.Fprintf(os.Stderr, "Commands:\n")
fmt.Fprintf(os.Stderr, c.Usage())
return nil
Expand Down
4 changes: 2 additions & 2 deletions share/setup
Expand Up @@ -2,8 +2,8 @@

rootdir=$(cd $(dirname $BASH_SOURCE[0])/.. ; pwd)

if [[ -z ${SHIELD_TARGET} ]]; then
echo "Missing SHIELD_TARGET=http://... environment variable\!"
if [[ -z ${SHIELD_API} ]]; then
echo "Missing SHIELD_API=http://... environment variable\!"
exit 2
fi
PATH=$PATH:${rootdir}/bin
Expand Down

0 comments on commit d9b3a27

Please sign in to comment.