@@ -1277,17 +1277,36 @@ def validate_tags(filename,comp_ids):
12771277 return False
12781278
12791279def validate_buckets (filename , comp_ids ):
1280+ # Initialize the flag to False for each bucket
12801281 buckets_empty_check = False
12811282 buckets_invalid_check = False
12821283 buckets_comp_check = False
1283- # Initialize the flag to False for each bucket
1284- lifecycle_policy_name_specified = False
1284+ bucket_reg_check = False
1285+ bucket_name_check = False
12851286
12861287 # Read the Compartments tab from excel
12871288 dfbuckets = data_frame (filename , 'Buckets' )
12881289
12891290 for i in dfbuckets .index :
12901291 region = str (dfbuckets .loc [i , 'Region' ]).strip ().lower ()
1292+ lifecycle_all_columns = ['Lifecycle Policy Name' , 'Lifecycle Target and Action' ,
1293+ 'Lifecycle Policy Enabled' , 'Lifecycle Rule Period' ,'Lifecyle Exclusion Patterns' ,'Lifecyle Inclusion Patterns' ,'Lifecyle Inclusion Prefixes' ]
1294+
1295+ lifecycle_mandatory_columns = ['Lifecycle Policy Name' ,'Lifecycle Target and Action' ,'Lifecycle Policy Enabled' ,'Lifecycle Rule Period' ]
1296+ lifecycle_input = False
1297+ for columns in lifecycle_all_columns :
1298+ column_value = str (dfbuckets .loc [i , columns ]).strip ().lower ()
1299+ if column_value != 'nan' :
1300+ lifecycle_input = True
1301+ data_column = columns
1302+ if lifecycle_input == True :
1303+ for columns in lifecycle_mandatory_columns :
1304+ column_value = str (dfbuckets .loc [i , columns ]).strip ().lower ()
1305+ if column_value == 'nan' :
1306+ log (f'ROW { i + 3 } : { columns } cannot be empty as column { data_column } has data.' )
1307+ buckets_invalid_check = True
1308+
1309+
12911310 # Encountered <End>
12921311 if (region in commonTools .endNames ):
12931312 break
@@ -1296,7 +1315,7 @@ def validate_buckets(filename, comp_ids):
12961315 buckets_empty_check = True
12971316 elif region not in ct .all_regions :
12981317 log (f'ROW { i + 3 } : "Region" { region } is not subscribed for tenancy.' )
1299- buckets_comp_check = True
1318+ bucket_reg_check = True
13001319
13011320 # Check for invalid Compartment Name
13021321 comp_name = str (dfbuckets .loc [i , 'Compartment Name' ]).strip ()
@@ -1307,14 +1326,21 @@ def validate_buckets(filename, comp_ids):
13071326 try :
13081327 comp_id = comp_ids [comp_name ]
13091328 except KeyError :
1310- log (f'ROW { i + 3 } : Compartment { comp_name } doesnot exist in OCI.' )
1329+ log (f'ROW { i + 3 } : Compartment { comp_name } does not exist in OCI.' )
13111330 buckets_comp_check = True
13121331
13131332 # Check for invalid Bucket Name
13141333 bucket_name = str (dfbuckets .loc [i , 'Bucket Name' ]).strip ()
13151334 if bucket_name .lower () == 'nan' or bucket_name == '' :
13161335 log (f'ROW { i + 3 } : Empty value at column "Bucket Name".' )
13171336 buckets_empty_check = True
1337+ else :
1338+ if re .match ("^[A-Za-z0-9_.-]*$" , bucket_name .lower ()):
1339+ bucket_name_check = False
1340+ else :
1341+ bucket_name_check = True
1342+ log (f'ROW { i + 3 } : "Bucket Name" can only contain letters (upper or lower case), numbers, hyphens, underscores, and periods.' )
1343+
13181344
13191345 # List of the column headers
13201346 dfcolumns = dfbuckets .columns .values .tolist ()
@@ -1324,58 +1350,35 @@ def validate_buckets(filename, comp_ids):
13241350 columnvalue = str (dfbuckets .loc [i , columnname ]).strip ()
13251351
13261352 if columnname == 'Storage Tier' :
1327- columnvalue = str (columnvalue ).strip ()
1328- if columnvalue != 'Standard' and columnvalue != 'Archive' :
1353+ if columnvalue .lower () not in ['standard' ,'archive' ]:
13291354 log (f'ROW { i + 3 } : Value of "Storage Tier" can be only either "Standard" or "Archive".' )
13301355 buckets_invalid_check = True
13311356
1332- if ' ' in columnvalue or '.' in columnvalue :
1333- log (f'ROW { i + 3 } : Spaces and Periods are not allowed in Storage Tier.' )
1334- buckets_invalid_check = True
13351357
13361358 if columnname == 'Auto Tiering' :
1337- columnvalue = str (columnvalue ).strip ()
1338- if columnvalue != 'Enabled' and columnvalue != 'Disabled' :
1359+ if columnvalue .lower () not in ['enabled' ,'disabled' ]:
13391360 log (f'ROW { i + 3 } : Value of "Auto Tiering" can be only either "Enabled" or "Disabled".' )
13401361 buckets_invalid_check = True
13411362
1342- if ' ' in columnvalue or '.' in columnvalue :
1343- log (f'ROW { i + 3 } : Spaces and Periods are not allowed in Auto Tiering.' )
1344- buckets_invalid_check = True
13451363
13461364 if columnname == 'Object Versioning' :
1347- columnvalue = str (columnvalue ).strip ()
1348- if columnvalue != 'Enabled' and columnvalue != 'Disabled' :
1365+ if columnvalue .lower () not in ['enabled' ,'disabled' ]:
13491366 log (f'ROW { i + 3 } : Value of "Object Versioning" can be only either "Enabled" or "Disabled".' )
13501367 buckets_invalid_check = True
13511368
1352- if ' ' in columnvalue or '.' in columnvalue :
1353- log (f'ROW { i + 3 } : Spaces and Periods are not allowed in Object Versioning.' )
1354- buckets_invalid_check = True
1355-
13561369 if columnname == 'Emit Object Events' :
1357- columnvalue = str (columnvalue ).strip ()
1358- if columnvalue != 'Enabled' and columnvalue != 'Disabled' :
1370+ if columnvalue .lower () not in ['enabled' ,'disabled' ]:
13591371 log (f'ROW { i + 3 } : Value of "Emit Object Events" can be only either "Enabled" or "Disabled".' )
13601372 buckets_invalid_check = True
13611373
1362- if ' ' in columnvalue or '.' in columnvalue :
1363- log (f'ROW { i + 3 } : Spaces and Periods are not allowed in Emit Object Events.' )
1364- buckets_invalid_check = True
13651374
13661375 if columnname == 'Visibility' :
1367- columnvalue = str (columnvalue ).strip ()
1368- if columnvalue != 'Private' and columnvalue != 'Public' :
1376+ if columnvalue .lower () not in ['private' ,'public' ]:
13691377 log (f'ROW { i + 3 } : Value of "Visibility" can be only either "Private" or "Public".' )
13701378 buckets_invalid_check = True
13711379
1372- if ' ' in columnvalue or '.' in columnvalue :
1373- log (f'ROW { i + 3 } : Spaces and Periods are not allowed in Visibility.' )
1374- buckets_invalid_check = True
1375-
13761380 #Check for valid destination region for enabling the replication policy
13771381 if columnname == 'Replication Policy' :
1378- columnvalue = str (columnvalue ).strip ()
13791382 columnvalue = columnvalue .split ("::" )
13801383 if len (columnvalue ) == 3 and all (columnvalue ):
13811384 replication_policy_name = columnvalue [0 ]
@@ -1388,7 +1391,6 @@ def validate_buckets(filename, comp_ids):
13881391
13891392 #Check for the retention policy details
13901393 if columnname == 'Retention Rules' :
1391- columnvalue = str (dfbuckets [columnname ][i ])
13921394 rule_values = columnvalue .split ("\n " )
13931395 retention_rules = []
13941396 for rule in rule_values :
@@ -1440,52 +1442,35 @@ def validate_buckets(filename, comp_ids):
14401442 continue
14411443
14421444 # Check for the Lifecycle Policy Details
1443- if columnname == 'Lifecycle Policy Name' :
1444- columnvalue = str (dfbuckets [columnname ][i ])
1445- if columnvalue != "" :
1446- lifecycle_policy_name = columnvalue
1447- lifecycle_policy_name_specified = True
1448-
1449- # Check if Lifecycle Policy Name is empty
1450- # Define the valid options for the "Lifecycle Target and Action" column
1451- valid_options = [
1452- 'objects::ARCHIVE' ,
1453- 'objects::INFREQUENT_ACCESS' ,
1454- 'objects::Delete' ,
1455- 'previous-object-versions::Archive' ,
1456- 'previous-object-versions::Delete' ,
1457- 'multipart-uploads::Abort'
1458- ]
1459-
1460- if lifecycle_policy_name_specified :
1445+ if lifecycle_input == True :
1446+ # Define the valid options for the "Lifecycle Target and Action" column
1447+ valid_options = [
1448+ 'objects::ARCHIVE' ,
1449+ 'objects::INFREQUENT_ACCESS' ,
1450+ 'objects::Delete' ,
1451+ 'previous-object-versions::Archive' ,
1452+ 'previous-object-versions::Delete' ,
1453+ 'multipart-uploads::Abort'
1454+ ]
1455+
1456+
14611457 # Check if "Lifecycle Target and Action" is empty
14621458 if columnname == 'Lifecycle Target and Action' :
1463- columnvalue = str (dfbuckets [columnname ][i ])
1464- if columnvalue == 'nan' :
1465- log (f'ROW { i + 3 } : "Lifecycle Target and Action" cannot be empty.' )
1466- buckets_invalid_check = True
1467- elif columnvalue not in valid_options :
1459+ if columnvalue != 'nan' and columnvalue not in valid_options :
14681460 log (f'ROW { i + 3 } : Invalid value in "Lifecycle Target and Action" column. '
14691461 f'Allowed options are: { ", " .join (valid_options )} .' )
14701462 buckets_invalid_check = True
14711463
14721464 # Check if "Lifecycle Policy Enabled" is empty
14731465 if columnname == 'Lifecycle Policy Enabled' :
1474- columnvalue = str (dfbuckets [columnname ][i ])
1475- if columnvalue == 'nan' :
1476- log (f'ROW { i + 3 } : "Lifecycle Policy Enabled" cannot be empty.' )
1477- buckets_invalid_check = True
1478- elif columnvalue not in ['True' , 'False' ]:
1479- log (f'ROW { i + 3 } : "Lifecycle Policy Enabled" must be either "True" or "False".' )
1466+ if columnvalue != 'nan' and columnvalue .lower () not in ['true' , 'false' ]:
1467+ log (f'ROW { i + 3 } : "Lifecycle Policy Enabled" must be either "TRUE" or "FALSE".' )
14801468 buckets_invalid_check = True
14811469
14821470 # Check if "Lifecycle Rule Period" is empty
14831471 if columnname == 'Lifecycle Rule Period' :
14841472 # Merge the checks for "Lifecycle Rule Period"
1485- if columnvalue == 'nan' :
1486- log (f'ROW { i + 3 } : "Lifecycle Rule Period" cannot be empty.' )
1487- buckets_invalid_check = True
1488- else :
1473+ if columnvalue != 'nan' :
14891474 columnvalue = columnvalue .upper ()
14901475 columnvalue = columnvalue .split ("::" )
14911476 if len (columnvalue ) == 2 :
@@ -1497,11 +1482,14 @@ def validate_buckets(filename, comp_ids):
14971482 buckets_invalid_check = True
14981483
14991484 # Check that time_unit is either "DAYS" or "YEARS"
1500- if time_unit not in ["DAYS" , "YEARS" ]:
1485+ if time_unit not in ['days' , 'years' ]:
15011486 log (f'ROW { i + 3 } : Invalid time amount. "Lifecycle Rule Period" must be "DAYS" or "YEARS".' )
15021487 buckets_invalid_check = True
1488+ else :
1489+ log (f'ROW { i + 3 } : Invalid format for "Lifecycle Rule Period" ' )
1490+ buckets_invalid_check = True
15031491
1504- if (buckets_empty_check == True or buckets_invalid_check == True or buckets_comp_check == True ):
1492+ if (buckets_empty_check == True or buckets_invalid_check == True or buckets_comp_check == True or bucket_reg_check == True or bucket_name_check == True ):
15051493 print ("Null or Wrong value Check failed!!" )
15061494 return True
15071495 else :
0 commit comments