forked from keithweaver/aws-s3-github-action
-
Notifications
You must be signed in to change notification settings - Fork 0
/
entrypoint.sh
127 lines (116 loc) · 3.36 KB
/
entrypoint.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
#!/bin/sh
function usage_docs {
echo ""
echo "- uses: abletech/[email protected]"
echo " with:"
echo " command: cp"
echo " source: ./local_file.txt"
echo " destination: s3://yourbucket/folder/local_file.txt"
echo " aws_access_key_id: \${{ secret.AWS_ACCESS_KEY_ID }}"
echo " aws_secret_access_key: \${{ secret.AWS_SECRET_ACCESS_KEY }}"
echo ""
}
function get_configuration_settings {
if [ -z "$INPUT_AWS_ACCESS_KEY_ID" ]
then
echo "AWS Access Key Id was not found. Using configuration from previous step."
else
aws configure set aws_access_key_id "$INPUT_AWS_ACCESS_KEY_ID"
fi
if [ -z "$INPUT_AWS_SECRET_ACCESS_KEY" ]
then
echo "AWS Secret Access Key was not found. Using configuration from previous step."
else
aws configure set aws_secret_access_key "$INPUT_AWS_SECRET_ACCESS_KEY"
fi
if [ -z "$INPUT_AWS_SESSION_TOKEN" ]
then
echo "AWS Session Token was not found. Using configuration from previous step."
else
aws configure set aws_session_token "$INPUT_AWS_SESSION_TOKEN"
fi
if [ -z "$INPUT_METADATA_SERVICE_TIMEOUT" ]
then
echo "Metadata service timeout was not found. Using configuration from previous step."
else
aws configure set metadata_service_timeout "$INPUT_METADATA_SERVICE_TIMEOUT"
fi
if [ -z "$INPUT_AWS_REGION" ]
then
echo "AWS region not found. Using configuration from previous step."
else
aws configure set region "$INPUT_AWS_REGION"
fi
}
function get_command {
VALID_COMMANDS=("sync" "mb" "rb" "ls" "cp" "mv" "rm")
COMMAND="cp"
if [ -z "$INPUT_COMMAND" ]
then
echo "Command not set using cp"
elif [[ ! ${VALID_COMMANDS[*]} =~ "$INPUT_COMMAND" ]]
then
echo ""
echo "Invalid command provided :: [$INPUT_COMMAND]"
usage_docs
exit 1
else
echo "Using provided command"
COMMAND=$INPUT_COMMAND
fi
}
function validate_source_and_destination {
if [ "$COMMAND" == "cp" ] || [ "$COMMAND" == "mv" ] || [ "$COMMAND" == "sync" ]
then
# Require source and target
if [ -z "$INPUT_SOURCE" ] && [ "$INPUT_DESTINATION" ]
then
echo ""
echo "Error: Requires source and destination."
usage_docs
exit 1
fi
# Verify at least one source or target have s3:// as prefix
# if [[] || []]
if [[ ! "$INPUT_SOURCE" =~ ^s3:// ]] && [[ ! "$INPUT_DESTINATION" =~ ^s3:// ]]
then
echo ""
echo "Error: Source or target must have s3:// as prefix."
usage_docs
exit 1
fi
else
# Require source
if [ -z "$INPUT_SOURCE" ]
then
echo "Error: Requires source."
usage_docs
exit 1
fi
# Verify at source has s3:// as prefix
if [[ ! $INPUT_SOURCE =~ ^s3:// ]]
then
echo "Error: Source must have s3:// as prefix."
usage_docs
exit 1
fi
fi
}
function main {
echo "v1.0.0"
get_configuration_settings
get_command
validate_source_and_destination
# Increase the max concurrent requests for s3
aws configure set default.s3.max_concurrent_requests 1000
aws --version
if [ "$COMMAND" == "cp" ] || [ "$COMMAND" == "mv" ] || [ "$COMMAND" == "sync" ]
then
echo aws s3 $COMMAND "$INPUT_SOURCE" "$INPUT_DESTINATION" $INPUT_FLAGS
aws s3 "$COMMAND" "$INPUT_SOURCE" "$INPUT_DESTINATION" $INPUT_FLAGS
else
echo aws s3 $COMMAND "$INPUT_SOURCE" $INPUT_FLAGS
aws s3 "$COMMAND" "$INPUT_SOURCE" $INPUT_FLAGS
fi
}
main