Skip to content

Commit f73bf2f

Browse files
authored
Merge pull request #109 from JoshuaUrrutia/files_reversion
reverting the files commands from python to bash versions to buy us time to release tapis-cli-ng
2 parents 64f2d00 + 6f9054f commit f73bf2f

19 files changed

+2529
-539
lines changed

bin/files-common.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
#
3+
# files-common.sh
4+
#
5+
# author: opensource@tacc.cloud
6+
#
7+
# URL filter for file services
8+
#
9+
10+
filter_service_url() {
11+
if [[ -z $hosturl ]]; then
12+
if ((development)); then
13+
hosturl="$devurl/files/"
14+
else
15+
hosturl="$baseurl/files/$version/"
16+
fi
17+
fi
18+
}
19+

bin/files-copy

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
#!/bin/bash
2+
#
3+
# files-copy
4+
#
5+
# author: opensource@tacc.cloud
6+
#
7+
# This script is part of the Agave API command line interface (CLI).
8+
# Copies a file or folder from one location to another on a remote system.
9+
#
10+
11+
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
12+
13+
source "$DIR/common.sh"
14+
15+
# Script logic -- TOUCH THIS {{{
16+
17+
# A list of all variables to prompt in interactive mode. These variables HAVE
18+
# to be named exactly as the longname option definition in usage().
19+
interactive_opts=(apisecret apikey, destination)
20+
21+
# Print usage
22+
usage() {
23+
echo -n "$(basename $0) [OPTION]... [PATH]
24+
25+
Copies a file or folder from one location to another on a remote system. If no
26+
system is specified, your default storage system will be used. By specifying a
27+
system, the path given will be resolved on that remote system. Note that the
28+
system id, not hostname must be given.
29+
30+
Options:
31+
-z, --access_token Access token
32+
-S, --systemId Specify the system id
33+
-D, --destination Full target path of the copied file/folder
34+
--filter Comma separated list of fields to return in the response
35+
-H, --hosturl URL of the service
36+
-d, --development Run in dev mode using default dev server
37+
-f, --force Skip all user interaction
38+
-i, --interactive Prompt for values
39+
-q, --quiet Quiet (no output)
40+
-v, --verbose Verbose output
41+
-V, --veryverbose Very verbose output
42+
-h, --help Display this help and exit
43+
--version Output version information and exit
44+
"
45+
}
46+
47+
##################################################################
48+
##################################################################
49+
# Begin Script Logic #
50+
##################################################################
51+
##################################################################
52+
53+
source "$DIR/files-common.sh"
54+
55+
main() {
56+
#echo -n
57+
#set -x
58+
59+
if [ -z "$args" ]; then
60+
err "Please specify a valid source path to copy"
61+
else
62+
if [ -n "$systemId" ]; then
63+
filesurl="${hosturl}media/system/${systemId}/${args}?pretty=true"
64+
else
65+
filesurl="${hosturl}media/${args}?pretty=true"
66+
fi
67+
68+
cmd="curl -sk -H \"${authheader}\" -X PUT -d \"action=copy&path=${destination}\" '${filesurl}'"
69+
70+
if ((veryverbose)); then
71+
[ "$piped" -eq 0 ] && log "Calling $cmd"
72+
fi
73+
74+
response=`curl -sk -H "${authheader}" -X PUT -d "action=copy&path=${destination}" "${filesurl}"`
75+
76+
if [[ $(jsonquery "$response" "status") = 'success' ]]; then
77+
result=$(format_api_json "$response")
78+
success "$result"
79+
else
80+
errorresponse=$(jsonquery "$response" "message")
81+
err "$errorresponse"
82+
fi
83+
fi
84+
85+
}
86+
87+
format_api_json() {
88+
89+
if ((veryverbose)); then
90+
echo "$1"
91+
elif [[ $verbose -eq 1 ]]; then
92+
result=$(jsonquery "$1" "result" 1)
93+
json_prettyify "${result}"
94+
else
95+
echo "Successfully copied ${args} to ${destination}"
96+
fi
97+
}
98+
99+
##################################################################
100+
##################################################################
101+
# End Script Logic #
102+
##################################################################
103+
##################################################################
104+
105+
# }}}
106+
107+
# Parse command line options
108+
source "$DIR/options.sh"
109+
110+
# Main loop {{{
111+
112+
# Print help if no arguments were passed.
113+
#[[ $# -eq 0 ]] && set -- "--help"
114+
115+
# Read the options and set stuff
116+
while [[ $1 = -?* ]]; do
117+
case $1 in
118+
-h|--help) usage >&2; safe_exit ;;
119+
--version) version; copyright; disclaimer; safe_exit ;;
120+
-z|--access_token) shift; access_token=$1 ;;
121+
-S|--systemId) shift; systemId=$1 ;;
122+
-D|--destination) shift; destination=$1 ;;
123+
--filter) shift; responsefilter=$1 ;;
124+
-H|--hosturl) shift; hosturl=$1;;
125+
-d|--development) development=1 ;;
126+
-v|--verbose) verbose=1 ;;
127+
-V|--veryverbose) veryverbose=1; verbose=1 ;;
128+
-q|--quiet) quiet=1 ;;
129+
-i|--interactive) interactive=1 ;;
130+
-f|--force) force=1 ;;
131+
--endopts) shift; break ;;
132+
*) die "invalid option: $1" ;;
133+
esac
134+
shift
135+
done
136+
137+
# Store the remaining part as arguments.
138+
args+=("$@")
139+
140+
# }}}
141+
142+
# Run the script logic
143+
source "$DIR/runner.sh"

bin/files-cp

Lines changed: 0 additions & 92 deletions
This file was deleted.

bin/files-delete

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
#!/bin/bash
2+
#
3+
# files-get
4+
#
5+
# author: opensource@tacc.cloud
6+
#
7+
# This script is part of the Agave API command line interface (CLI).
8+
# Deletes a file or folder from a remote system.
9+
#
10+
11+
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
12+
13+
source "$DIR/common.sh"
14+
15+
# Script logic -- TOUCH THIS {{{
16+
17+
# A list of all variables to prompt in interactive mode. These variables HAVE
18+
# to be named exactly as the longname option definition in usage().
19+
interactive_opts=(apisecret apikey)
20+
21+
# Print usage
22+
usage() {
23+
echo -n "$(basename $0) [OPTION]... [PATH]
24+
25+
Deletes a remote file or folder. If no system is specified, your default storage
26+
system will be used. By specifying a system, the path given will be resolved on
27+
that remote system. Note that the system id, not hostname must be given.
28+
29+
Options:
30+
-z, --access_token Access token
31+
-S, --systemId Specify the system id
32+
-P, --print Print contents to stdout
33+
-H, --hosturl URL of the service
34+
-d, --development Run in dev mode using default dev server
35+
-f, --force Skip all user interaction
36+
-i, --interactive Prompt for values
37+
-q, --quiet Quiet (no output)
38+
-v, --verbose Verbose output
39+
-V, --veryverbose Very verbose output
40+
-h, --help Display this help and exit
41+
--version Output version information and exit
42+
"
43+
}
44+
45+
##################################################################
46+
##################################################################
47+
# Begin Script Logic #
48+
##################################################################
49+
##################################################################
50+
51+
source "$DIR/files-common.sh"
52+
53+
main() {
54+
#echo -n
55+
#set -x
56+
57+
if [ -z "$args" ]; then
58+
err "Please specify a valid file path to download. Directory downloads are not yet supported."
59+
else
60+
61+
if [ -n "$systemId" ]; then
62+
filesurl="${hosturl}media/system/${systemId}/${args}?pretty=true"
63+
else
64+
filesurl="${hosturl}media/${args}?pretty=true"
65+
fi
66+
67+
cmd="curl -sk -H \"${authheader}\" -X DELETE '${filesurl}'"
68+
69+
if ((veryverbose)); then
70+
[ "$piped" -eq 0 ] && log "Calling $cmd"
71+
fi
72+
73+
response=`curl -sk -H "${authheader}" -X DELETE "${filesurl}"`
74+
75+
if [[ $(jsonquery "$response" "status") = 'success' ]]; then
76+
result=$(format_api_json "$response")
77+
success "$result"
78+
else
79+
errorresponse=$(jsonquery "$response" "message")
80+
err "$errorresponse"
81+
fi
82+
83+
fi
84+
}
85+
86+
format_api_json() {
87+
88+
if ((veryverbose)); then
89+
echo "$1"
90+
elif [[ $verbose -eq 1 ]]; then
91+
result=$(jsonquery "$1" "result" 1)
92+
json_prettyify "${result}"
93+
else
94+
echo "Successfully deleted ${args}"
95+
fi
96+
}
97+
98+
##################################################################
99+
##################################################################
100+
# End Script Logic #
101+
##################################################################
102+
##################################################################
103+
104+
# }}}
105+
106+
# Parse command line options
107+
source "$DIR/options.sh"
108+
109+
# Main loop {{{
110+
111+
# Print help if no arguments were passed.
112+
#[[ $# -eq 0 ]] && set -- "--help"
113+
114+
# Read the options and set stuff
115+
while [[ $1 = -?* ]]; do
116+
case $1 in
117+
-h|--help) usage >&2; safe_exit ;;
118+
--version) version; copyright; disclaimer; safe_exit ;;
119+
-z|--access_token) shift; access_token=$1 ;;
120+
-S|--systemId) shift; systemId=$1 ;;
121+
-P|--print) print=$1 ;;
122+
-H|--hosturl) shift; hosturl=$1;;
123+
-d|--development) development=1 ;;
124+
-v|--verbose) verbose=1 ;;
125+
-V|--veryverbose) veryverbose=1; verbose=1 ;;
126+
-q|--quiet) quiet=1 ;;
127+
-i|--interactive) interactive=1 ;;
128+
-f|--force) force=1 ;;
129+
--endopts) shift; break ;;
130+
*) die "invalid option: $1" ;;
131+
esac
132+
shift
133+
done
134+
135+
# Store the remaining part as arguments.
136+
args+=("$@")
137+
138+
# }}}
139+
140+
# Run the script logic
141+
source "$DIR/runner.sh"

0 commit comments

Comments
 (0)