16
16
17
17
put_object_tagging () {
18
18
if [ $# -ne 5 ]; then
19
- log 2 " 'put-object-tagging' command missing command type, object name, file, key, and/or value"
19
+ log 2 " 'put-object-tagging' command missing command type, bucket, object name, file, key, and/or value"
20
20
return 1
21
21
fi
22
22
local error
@@ -26,6 +26,8 @@ put_object_tagging() {
26
26
error=$( aws --no-verify-ssl s3api put-object-tagging --bucket " $2 " --key " $3 " --tagging " TagSet=[{Key=$4 ,Value=$5 }]" 2>&1 ) || result=$?
27
27
elif [[ $1 == ' mc' ]]; then
28
28
error=$( mc --insecure tag set " $MC_ALIAS " /" $2 " /" $3 " " $4 =$5 " 2>&1 ) || result=$?
29
+ elif [[ $1 == ' rest' ]]; then
30
+ put_object_tagging_rest " $2 " " $3 " " $4 " " $5 " || result=$?
29
31
else
30
32
log 2 " invalid command type $1 "
31
33
return 1
@@ -35,4 +37,56 @@ put_object_tagging() {
35
37
return 1
36
38
fi
37
39
return 0
38
- }
40
+ }
41
+
42
+ put_object_tagging_rest () {
43
+ if [ $# -ne 4 ]; then
44
+ log 2 " 'put_object_tagging' requires bucket, key, tag key, tag value"
45
+ return 1
46
+ fi
47
+
48
+ tagging=" <?xml version=\" 1.0\" encoding=\" UTF-8\" ?>
49
+ <Tagging xmlns=\" http://s3.amazonaws.com/doc/2006-03-01/\" >
50
+ <TagSet>
51
+ <Tag>
52
+ <Key>$3 </Key>
53
+ <Value>$4 </Value>
54
+ </Tag>
55
+ </TagSet>
56
+ </Tagging>"
57
+
58
+ generate_hash_for_payload " $tagging "
59
+
60
+ current_date_time=$( date -u +" %Y%m%dT%H%M%SZ" )
61
+ aws_endpoint_url_address=${AWS_ENDPOINT_URL#*// }
62
+ header=$( echo " $AWS_ENDPOINT_URL " | awk -F: ' {print $1}' )
63
+ # shellcheck disable=SC2154
64
+ canonical_request=" PUT
65
+ /$1 /$2
66
+ tagging=
67
+ host:$aws_endpoint_url_address
68
+ x-amz-content-sha256:$payload_hash
69
+ x-amz-date:$current_date_time
70
+
71
+ host;x-amz-content-sha256;x-amz-date
72
+ $payload_hash "
73
+
74
+ if ! generate_sts_string " $current_date_time " " $canonical_request " ; then
75
+ log 2 " error generating sts string"
76
+ return 1
77
+ fi
78
+ get_signature
79
+ # shellcheck disable=SC2154
80
+ reply=$( curl -ks -w " %{http_code}" -X PUT " $header ://$aws_endpoint_url_address /$1 /$2 ?tagging" \
81
+ -H " Authorization: AWS4-HMAC-SHA256 Credential=$AWS_ACCESS_KEY_ID /$ymd /$AWS_REGION /s3/aws4_request,SignedHeaders=host;x-amz-content-sha256;x-amz-date,Signature=$signature " \
82
+ -H " x-amz-content-sha256: $payload_hash " \
83
+ -H " x-amz-date: $current_date_time " \
84
+ -d " $tagging " -o " $TEST_FILE_FOLDER " /put_tagging_error.txt 2>&1 )
85
+ log 5 " reply status code: $reply "
86
+ if [[ " $reply " != " 200" ]]; then
87
+ log 2 " reply error: $reply "
88
+ log 2 " put object tagging command returned error: $( cat " $TEST_FILE_FOLDER " /put_tagging_error.txt) "
89
+ return 1
90
+ fi
91
+ return 0
92
+ }
0 commit comments