-
Notifications
You must be signed in to change notification settings - Fork 0
/
args.sh
253 lines (215 loc) · 6.91 KB
/
args.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
die() {
local _ret="${2:-1}"
test "${_PRINT_HELP:-}" = yes && print_help >&2
echo "$1" >&2
exit "${_ret}"
}
check_argument() {
if [[ "$1" == -* ]]; then
return 0
else
return 1
fi
}
print_long_help() {
echo "AWS-MICRO() AWS-MICRO()
NAME
$0 -
DESCRIPTION
The AWS MICRO Command Line Interface is a replacement for aws-cli with
minimal dependencies but also with a very limited support for services,
(sub-)commands, parameters and options.
SYNOPSIS
$0 [options] <command> <subcommand> [parameters]
Use aws-micro command help for information on a specific command. For
detailed information use the official aws cli command and the project
page at https://github.com/sengaya/aws-micro
OPTIONS
--debug (boolean)
Turn on debug logging.
--dryrun (boolean)
Displays the operations that would be performed using the specified
command without actually running them.
(Contrary to aws-cli this will work on all commands)
--endpoint-url (string)
Override command's default URL with the given URL.
--profile (string)
Use a specific profile from your credential file.
--region (string)
The region to use. Overrides config/env settings.
--version (string)
Display the version of this tool.
--no-sign-request (boolean)
Do not sign requests. Credentials will not be loaded if this argument
is provided.
AVAILABLE SERVICES
o s3
o s3api
o sts
"
}
print_help() {
echo "usage: $0 [options] <command> <subcommand> [<subcommand> ...] [parameters]
To see help text, you can run:
$0 help
$0 <command> help
"
}
_positionals=()
_arg_acl=
_arg_bucket=
_arg_content_type=
_arg_endpoint_url=
_arg_no_guess_mime_type="off"
_arg_no_sign_request="off"
_arg_profile=
_arg_role_arn=
_arg_role_session_name=
_arg_sse=
_arg_storage_class=
region=
DEBUG=0
curl_output="-s -S"
dryrun=
parse_commandline() {
_positionals_count=0
while test $# -gt 0
do
_key="$1"
case "$_key" in
--debug)
DEBUG=1
curl_output='-v'
;;
--dryrun)
dryrun="echo"
;;
--no-guess-mime-type)
_arg_no_guess_mime_type="on"
;;
--no-sign-request)
_arg_no_sign_request="on"
;;
--acl)
if [[ $# -lt 2 ]] || [[ "${2:---}" == --* ]]; then
_PRINT_HELP=yes die "$0: error: argument --acl: expected one argument" 1
fi
_arg_acl="$2"
shift
valid_acls=("private" "public-read" "public-read-write" "authenti-cated-read" "aws-exec-read" "bucket-owner-read" "bucket-owner-full-control" "log-delivery-write")
if ! array_contains "${_arg_acl}" "${valid_acls[@]}"; then
_PRINT_HELP=yes die "$0: error: argument --acl: Invalid choice, valid choices are:
private | public-read
public-read-write | authenticated-read
aws-exec-read | bucket-owner-read
bucket-owner-full-control | log-delivery-write" 1
fi
acl_header="x-amz-acl:${_arg_acl}"
;;
--content-type)
test $# -lt 2 || check_argument "$2" && die "Missing value for the optional argument '$_key'." 1
_arg_content_type="$2"
shift
;;
--bucket)
test $# -lt 2 || check_argument "$2" && die "Missing value for the optional argument '$_key'." 1
_arg_bucket="$2"
shift
;;
--endpoint-url)
test $# -lt 2 || check_argument "$2" && die "Missing value for the optional argument '$_key'." 1
_arg_endpoint_url="$2"
shift
;;
--key)
test $# -lt 2 || check_argument "$2" && die "Missing value for the optional argument '$_key'." 1
_arg_key="$2"
shift
;;
--profile)
test $# -lt 2 || check_argument "$2" && die "Missing value for the optional argument '$_key'." 1
_arg_profile="$2"
shift
;;
--region)
test $# -lt 2 || check_argument "$2" && die "Missing value for the optional argument '$_key'." 1
region="$2"
shift
;;
--role-arn)
test $# -lt 2 || check_argument "$2" && die "Missing value for the optional argument '$_key'." 1
_arg_role_arn="$2"
shift
;;
--role-session-name)
test $# -lt 2 || check_argument "$2" && die "Missing value for the optional argument '$_key'." 1
_arg_role_session_name="$2"
shift
;;
--sse)
if [[ $# -lt 2 ]] || [[ "${2:---}" == --* ]]; then
_arg_sse="AES256"
elif [[ "$2" = "AES256" ]] || [[ "$2" = "aws:kms" ]]; then
_arg_sse="$2"
shift
else
_PRINT_HELP=yes die "$0: error: argument $_key: Invalid choice, valid choices are:
AES256 | aws:kms" 1
fi
sse_header="x-amz-server-side-encryption:${_arg_sse}"
;;
--storage-class)
if [[ $# -lt 2 ]] || [[ "${2:---}" == --* ]]; then
_PRINT_HELP=yes die "$0: error: argument --storage-class: expected one argument" 1
fi
_arg_storage_class="$2"
shift
valid_storage_classes=("STANDARD" "REDUCED_REDUNDANCY" "STANDARD_IA" "ONEZONE_IA" "INTELLIGENT_TIERING" "GLACIER" "DEEP_ARCHIVE")
if ! array_contains "${_arg_storage_class}" "${valid_storage_classes[@]}"; then
_PRINT_HELP=yes die "$0: error: argument --storage-class: Invalid choice, valid choices are:
STANDARD | REDUCED_REDUNDANCY
STANDARD_IA | ONEZONE_IA
INTELLIGENT_TIERING | GLACIER
DEEP_ARCHIVE
Invalid choice: '${_arg_storage_class}'" 1
fi
storage_class_header="x-amz-storage-class:${_arg_storage_class}"
;;
--version)
echo "$0 ${AWS_MICRO_VERSION}"
exit 0
;;
*)
_last_positional="$1"
_positionals+=("$_last_positional")
_positionals_count=$((_positionals_count + 1))
;;
esac
shift
done
}
handle_passed_args_count() {
test "${_positionals_count}" -ge 1 || _PRINT_HELP=yes die "$0: error: the following arguments are required: command" 1
}
assign_positional_args() {
local _positional_name _shift_for=$1
_positional_names="_arg_command _arg_subcommand"
shift "$_shift_for"
for _positional_name in ${_positional_names}; do
test $# -gt 0 || break
eval "$_positional_name=\${1}" || die "Error during argument parsing, possibly an Argbash bug." 1
shift
done
}
get_args() {
parse_commandline "$@"
handle_passed_args_count
assign_positional_args 1 "${_positionals[@]}"
service="${_arg_command:-}"
if [[ -z "${region}" ]]; then
region="${AWS_DEFAULT_REGION:-}"
fi
if [[ -z "${AWS_CONFIG_FILE:-}" ]]; then
AWS_CONFIG_FILE=~"/.aws/config"
fi
}