Skip to content

Commit 21c4bf0

Browse files
committed
updated based on review
1 parent 33aaee7 commit 21c4bf0

1 file changed

Lines changed: 27 additions & 21 deletions

File tree

s3cmd

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2183,22 +2183,20 @@ def cmd_getacl(args):
21832183
acl = s3.get_acl(uri)
21842184
acl_grant_list = acl.getGrantList()
21852185
owner = acl.getOwner()
2186-
output(u"Bucket: %s" % uri.bucket())
2187-
output(u"Owner: %s (ID: %s)" % (owner['nick'], owner['id']))
2186+
output(u"%s (bucket):" % uri.uri())
2187+
if owner['nick'] is None or owner['nick'] == "":
2188+
output(u" Owner: %s" % (owner['id']))
2189+
else:
2190+
output(u" Owner: %s (Nick: %s)" % (owner['id'], owner['nick']))
21882191
for grant in acl_grant_list:
21892192
output(u" ACL: %s: %s" % (grant['grantee'], grant['permission']))
21902193
if acl.isAnonRead():
21912194
output(u" URL: %s" % uri.public_url())
2192-
output(u"\nRaw ACL Output: \n %s" % acl)
21932195
except S3Error as exc:
21942196
# Ignore the exception and don't fail the info
21952197
# if the server doesn't support setting ACLs
2196-
if exc.status not in [404, 501]:
2197-
raise exc
2198-
else:
2199-
output(u" ACL: none")
2200-
2201-
return acl
2198+
output(u" ACL: none")
2199+
return EX_OK
22022200

22032201
def cmd_setacl(args):
22042202
cfg = Config()
@@ -2375,21 +2373,29 @@ def cmd_setpolicy(args):
23752373
output(u"%s: Policy updated" % uri)
23762374
return EX_OK
23772375

2378-
def cmd_listpolicy(args):
2376+
def cmd_getpolicy(args):
23792377
cfg = Config()
23802378
s3 = S3(cfg)
23812379
uri = S3Uri(args[0])
23822380

2383-
if len(args) != 1:
2384-
raise ParameterError("Too few parameters! Expected: <bucket>")
2385-
if not uri.has_bucket():
2386-
raise ParameterError("Invalid bucket name: '%s'" % args[0])
2387-
if uri.has_object():
2388-
raise ParameterError("No Object Names allowed: '%s'" % args[0])
2381+
if uri.type != "s3" or not uri.has_bucket():
2382+
raise ParameterError("Expecting S3 URI instead of '%s'" % args[0])
23892383

2390-
response = s3.get_policy(uri)
2391-
2392-
return response
2384+
try:
2385+
policy = s3.get_policy(uri)
2386+
output(u" Policy: %s" % policy)
2387+
except S3Error as exc:
2388+
# Ignore the exception and don't fail the info
2389+
# if the server doesn't support setting ACLs
2390+
if exc.status == 403:
2391+
output(u" Policy: Not available: GetPolicy permission is needed to read the policy")
2392+
elif exc.status == 405:
2393+
output(u" Policy: Not available: Only the bucket owner can read the policy")
2394+
elif exc.status not in [404, 501]:
2395+
raise exc
2396+
else:
2397+
output(u" Policy: none")
2398+
return EX_OK
23932399

23942400
def cmd_delpolicy(args):
23952401
cfg = Config()
@@ -3025,7 +3031,7 @@ def get_commands_list():
30253031
{"cmd":"cp", "label":"Copy object", "param":"s3://BUCKET1/OBJECT1 s3://BUCKET2[/OBJECT2]", "func":cmd_cp, "argc":2},
30263032
{"cmd":"modify", "label":"Modify object metadata", "param":"s3://BUCKET1/OBJECT", "func":cmd_modify, "argc":1},
30273033
{"cmd":"mv", "label":"Move object", "param":"s3://BUCKET1/OBJECT1 s3://BUCKET2[/OBJECT2]", "func":cmd_mv, "argc":2},
3028-
{"cmd":"getacl", "label":"List Access control list for Bucket or Files", "param":"s3://BUCKET[/OBJECT]", "func":cmd_getacl, "argc":0},
3034+
{"cmd":"getacl", "label":"List Access control list for Bucket or Files", "param":"s3://BUCKET[/OBJECT]", "func":cmd_getacl, "argc":1},
30293035
{"cmd":"setacl", "label":"Modify Access control list for Bucket or Files", "param":"s3://BUCKET[/OBJECT]", "func":cmd_setacl, "argc":1},
30303036
{"cmd":"setversioning", "label":"Modify Bucket Versioning", "param":"s3://BUCKET enable|disable", "func":cmd_setversioning, "argc":2},
30313037
{"cmd":"setownership", "label":"Modify Bucket Object Ownership", "param":"s3://BUCKET BucketOwnerPreferred|BucketOwnerEnforced|ObjectWriter", "func":cmd_setownership, "argc":2},
@@ -3035,7 +3041,7 @@ def get_commands_list():
30353041
{"cmd":"setobjectretention", "label":"Modify Object Retention", "param":"MODE RETAIN_UNTIL_DATE s3://BUCKET/OBJECT", "func":cmd_setobjectretention, "argc":3},
30363042

30373043
{"cmd":"setpolicy", "label":"Modify Bucket Policy", "param":"FILE s3://BUCKET", "func":cmd_setpolicy, "argc":2},
3038-
{"cmd":"listpolicy", "label":"List Bucket Policy", "param":"FILE s3://BUCKET", "func":cmd_listpolicy, "argc":0},
3044+
{"cmd":"getpolicy", "label":"Get Bucket Policy", "param":"FILE s3://BUCKET", "func":cmd_getpolicy, "argc":1},
30393045
{"cmd":"delpolicy", "label":"Delete Bucket Policy", "param":"s3://BUCKET", "func":cmd_delpolicy, "argc":1},
30403046
{"cmd":"setcors", "label":"Modify Bucket CORS", "param":"FILE s3://BUCKET", "func":cmd_setcors, "argc":2},
30413047
{"cmd":"delcors", "label":"Delete Bucket CORS", "param":"s3://BUCKET", "func":cmd_delcors, "argc":1},

0 commit comments

Comments
 (0)