-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathallas-add-S3-permissions
executable file
·88 lines (70 loc) · 2.08 KB
/
allas-add-S3-permissions
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
#!/bin/bash
help=0
obj_path=0
id=0
inst_root="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
source $inst_root/allas-lib
#Process command line
while [[ $# -ge 1 ]]
do
case "$1" in
'--bucket' | '-b' )
obj_path=($2)
obj_path=$(remove_slash_from_ends $obj_path)
bucket=$(echo $obj_path | awk -F / '{print $1}')
#split bucket and object if needed
if [[ $obj_path != $bucket ]]; then
prefix_string=$(echo $1 | sed -e s/"${bucket}\/"/""/)
fi
shift
shift
;;
'--id' | '-i' )
project_id="$2"
shift
shift
;;
'--help' | '-h' )
help=1
shift
;;
esac
done
if [[ $obj_path == "0" ]];then
echo ""
echo "ERROR: target bucket was not defined"
echo "Please use -b to define bucket, and pseudofolder if needed, for this operation"
echo ""
help=1
fi
if [[ $project_id == "0" ]];then
echo ""
echo "ERROR: target object was not defined"
echo "Please use -i to define the ID string of the project for which the S3 permissions are granted."
echo ""
help=1
fi
if [[ $help -eq 1 ]]; then
cat <<EOF
Command syntax:
allas-add-S3-permissions -b bucket -i project-id-string
EOF
exit
fi
echo "Giving S3 read and write permissions for project $project_id"
echo " to every object in: $obj_path ."
for obj in $(a-list $obj_path)
do
#echo $obj
#echo " s3cmd setacl --acl-grant=read:$project_id s3://$obj"
s3cmd setacl --acl-grant=all:$project_id s3://$obj
#check of this has segments to fix
obj_only=$(echo $obj | sed -e s/"${bucket}\/"/""/)
manifest=$(swift stat $bucket $obj_only | grep "Manifest:" | awk '{print $2}')
if [[ $manifest != "" ]]; then
for seg in $(a-list $manifest)
do
s3cmd setacl --acl-grant=all:$project_id s3://$seg
done
fi
done