@@ -1397,9 +1397,10 @@ def validate_buckets(filename, comp_ids):
1397
1397
log (f'ROW { i + 3 } : Value of "Auto Tiering" can be only either "Enabled" or "Disabled".' )
1398
1398
buckets_invalid_check = True
1399
1399
1400
+ # Check for the Object Versioning column
1400
1401
if columnname == 'Object Versioning' :
1401
- if columnvalue .lower () not in ['enabled' ,'disabled' ]:
1402
- log (f'ROW { i + 3 } : Value of "Object Versioning" can be only either "Enabled" or "Disabled".' )
1402
+ if columnvalue .lower () not in ['enabled' , 'disabled' ]:
1403
+ log (f'ROW { i + 3 } : Value of "Object Versioning" can only be "Enabled" or "Disabled".' )
1403
1404
buckets_invalid_check = True
1404
1405
1405
1406
if columnname == 'Emit Object Events' :
@@ -1438,69 +1439,74 @@ def validate_buckets(filename, comp_ids):
1438
1439
#Check for the retention policy details
1439
1440
if columnname == 'Retention Rules' :
1440
1441
rule_values = columnvalue .split ("\n " )
1441
- retention_rules = []
1442
- for rule in rule_values :
1443
- rule_components = rule .split ("::" )
1444
- if len (rule_components ) >= 1 :
1445
- retention_rule_display_name = rule_components [0 ]
1446
- time_unit = None
1447
- time_amount = None
1448
- time_rule_locked = None
1449
-
1450
- if len (rule_components ) >= 2 :
1451
- if rule_components [1 ].lower () == 'indefinite' :
1452
- time_amount = None
1453
- else :
1454
- time_amount = rule_components [1 ]
1455
- if not time_amount .isdigit ():
1456
- log (f'ROW { i + 3 } : "time_amount" of retention rule is not in valid format. It should be an "integer" or "indefinite".' )
1457
- buckets_invalid_check = True
1458
- continue
1442
+ if rule_values and str (dfbuckets .loc [i , 'Object Versioning' ]).strip ().lower () == 'enabled' :
1443
+ log (f'ROW { i + 3 } : Retention policy cannot be created when Object Versioning is enabled.' )
1444
+ buckets_invalid_check = True
1445
+
1446
+ elif rule_values and str (dfbuckets .loc [i , 'Object Versioning' ]).strip ().lower () == 'disabled' :
1447
+ retention_rules = []
1448
+ for rule in rule_values :
1449
+ rule_components = rule .split ("::" )
1450
+ if len (rule_components ) >= 1 :
1451
+ retention_rule_display_name = rule_components [0 ]
1452
+ time_unit = None
1453
+ time_amount = None
1454
+ time_rule_locked = None
1455
+
1456
+ if len (rule_components ) >= 2 :
1457
+ if rule_components [1 ].lower () == 'indefinite' :
1458
+ time_amount = None
1459
1459
else :
1460
- time_amount = int (time_amount )
1460
+ time_amount = rule_components [1 ]
1461
+ if not time_amount .isdigit ():
1462
+ log (f'ROW { i + 3 } : "time_amount" of retention rule is not in valid format. It should be an "integer" or "indefinite".' )
1463
+ buckets_invalid_check = True
1464
+ continue
1465
+ else :
1466
+ time_amount = int (time_amount )
1461
1467
1462
- if len (rule_components ) >= 3 :
1463
- time_unit = rule_components [2 ].upper ()
1464
- if time_unit not in ('DAYS' , 'YEARS' ):
1465
- log (f'ROW { i + 3 } : "time_unit" of retention rule is not in valid format. It should be either DAYS or YEARS.' )
1466
- buckets_invalid_check = True
1467
- else :
1468
- # If time_unit is valid, set the flag to True for processing time_rule_locked
1469
- process_time_rule_locked = True
1470
-
1471
- if len (rule_components ) == 4 and process_time_rule_locked :
1472
- time_rule_locked = rule_components [3 ]
1473
- if time_rule_locked .endswith (".000Z" ):
1474
- time_rule_locked = time_rule_locked [:- 5 ] + "Z"
1475
- elif not re .match (r"\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z|\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z" ,time_rule_locked ):
1476
- # Convert from "dd-mm-yyyy" to "YYYY-MM-DDThh:mm:ssZ" format
1477
- if re .match (r"\d{2}-\d{2}-\d{4}" , time_rule_locked ):
1478
- try :
1479
- datetime_obj = datetime .datetime .strptime (time_rule_locked , "%d-%m-%Y" )
1480
- time_rule_locked = datetime_obj .strftime ("%Y-%m-%dT%H:%M:%SZ" )
1481
- except ValueError :
1468
+ if len (rule_components ) >= 3 :
1469
+ time_unit = rule_components [2 ].upper ()
1470
+ if time_unit not in ('DAYS' , 'YEARS' ):
1471
+ log (f'ROW { i + 3 } : "time_unit" of retention rule is not in valid format. It should be either DAYS or YEARS.' )
1472
+ buckets_invalid_check = True
1473
+ else :
1474
+ # If time_unit is valid, set the flag to True for processing time_rule_locked
1475
+ process_time_rule_locked = True
1476
+
1477
+ if len (rule_components ) == 4 and process_time_rule_locked :
1478
+ time_rule_locked = rule_components [3 ]
1479
+ if time_rule_locked .endswith (".000Z" ):
1480
+ time_rule_locked = time_rule_locked [:- 5 ] + "Z"
1481
+ elif not re .match (r"\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z|\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z" ,time_rule_locked ):
1482
+ # Convert from "dd-mm-yyyy" to "YYYY-MM-DDThh:mm:ssZ" format
1483
+ if re .match (r"\d{2}-\d{2}-\d{4}" , time_rule_locked ):
1484
+ try :
1485
+ datetime_obj = datetime .datetime .strptime (time_rule_locked , "%d-%m-%Y" )
1486
+ time_rule_locked = datetime_obj .strftime ("%Y-%m-%dT%H:%M:%SZ" )
1487
+ except ValueError :
1488
+ log (f'ROW { i + 3 } : "time_rule_locked" of retention rule is not in valid format. It should be in the format "dd-mm-yyyy".' )
1489
+ buckets_invalid_check = True
1490
+ continue
1491
+ else :
1482
1492
log (f'ROW { i + 3 } : "time_rule_locked" of retention rule is not in valid format. It should be in the format "dd-mm-yyyy".' )
1483
1493
buckets_invalid_check = True
1484
1494
continue
1485
- else :
1486
- log (f'ROW { i + 3 } : "time_rule_locked" of retention rule is not in valid format. It should be in the format "dd-mm-yyyy".' )
1495
+ # Parse the time_rule_locked into a datetime object
1496
+ try :
1497
+ time_rule_locked_datetime = datetime .datetime .strptime (time_rule_locked , "%Y-%m-%dT%H:%M:%SZ" )
1498
+ except ValueError :
1499
+ log (f'ROW { i + 3 } : "time_rule_locked" of retention rule is not in valid format. It should be in the format "YYYY-MM-DDThh:mm:ssZ".' )
1487
1500
buckets_invalid_check = True
1488
1501
continue
1489
- # Parse the time_rule_locked into a datetime object
1490
- try :
1491
- time_rule_locked_datetime = datetime .datetime .strptime (time_rule_locked , "%Y-%m-%dT%H:%M:%SZ" )
1492
- except ValueError :
1493
- log (f'ROW { i + 3 } : "time_rule_locked" of retention rule is not in valid format. It should be in the format "YYYY-MM-DDThh:mm:ssZ".' )
1494
- buckets_invalid_check = True
1495
- continue
1496
1502
1497
- # Calculate the difference between current time and time_rule_locked
1498
- time_difference = time_rule_locked_datetime - current_time
1503
+ # Calculate the difference between current time and time_rule_locked
1504
+ time_difference = time_rule_locked_datetime - current_time
1499
1505
1500
- # Check if the difference is less than 14 days
1501
- if time_difference .days < 14 :
1502
- log (f'ROW { i + 3 } : "time_rule_locked" of retention rule must be more than 14 days from the current time.' )
1503
- buckets_invalid_check = True
1506
+ # Check if the difference is less than 14 days
1507
+ if time_difference .days < 14 :
1508
+ log (f'ROW { i + 3 } : "time_rule_locked" of retention rule must be more than 14 days from the current time.' )
1509
+ buckets_invalid_check = True
1504
1510
1505
1511
# Check for the Lifecycle Policy Details
1506
1512
if lifecycle_input == True :
@@ -1545,6 +1551,7 @@ def validate_buckets(filename, comp_ids):
1545
1551
if time_unit not in ['days' ,'years' ]:
1546
1552
log (f'ROW { i + 3 } : Invalid time amount. "Lifecycle Rule Period" must be "DAYS" or "YEARS".' )
1547
1553
buckets_invalid_check = True
1554
+
1548
1555
else :
1549
1556
log (f'ROW { i + 3 } : Invalid format for "Lifecycle Rule Period" ' )
1550
1557
buckets_invalid_check = True
0 commit comments