-
Notifications
You must be signed in to change notification settings - Fork 28
/
s3_mfa_delete.py
executable file
·38 lines (31 loc) · 1.34 KB
/
s3_mfa_delete.py
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
import boto
def configure_mfa_delete(bucket_name,
mfa_serial_number,
mfa_token,
enable=True):
"""
Enable versioning on a bucket.
bucket_name Bucket to be configured.
mfa_serial_number The serial number of the MFA device associated
with your account.
mfa_token The current token displayed on the MFA device.
enable A boolean value to indicate whether MFA Delete
is being enabled or disabled.
"""
s3 = boto.connect_s3()
bucket = s3.lookup(bucket_name)
# Get the current status of versioning on the bucket
# and print the value out.
config = bucket.get_versioning_status()
print 'Current Versioning Status: ', config
if 'Versioning' in config and config['Versioning'] == 'Enabled':
versioning = True
else:
versioning = False
# Make change to configuration. This method takes a tuple
# consisting of the mfa serial # and token.
bucket.configure_versioning(versioning=versioning, mfa_delete=enable,
mfa_token=(mfa_serial_number, mfa_token))
# Update the status of versioning and print the new value.
config = bucket.get_versioning_status()
print 'New Versioning Status: ', config