@@ -512,6 +512,39 @@ def handler(event, context) -> str: # type: ignore[no-untyped-def]
512512 features = get_dict_value (config , "features" )
513513 archive_rules = get_dict_value (config , "archive_configuration" )
514514
515+ # Create a Boto3 session
516+
517+ session = boto3 .session .Session ()
518+
519+ # Create Boto3 S3 client
520+
521+ s3 = session .client (service_name = "s3" )
522+
523+ # Check whether to use local config or cloud config
524+
525+ if not get_dict_value (features , "use_local_config" ):
526+
527+ bucket_name = os .getenv ("S3_BUCKET_NAME" )
528+
529+ if not bucket_name :
530+ error_message = "S3_BUCKET_NAME environment variable not set. Please check your environment variables."
531+ raise Exception (error_message )
532+
533+ try :
534+ response = s3 .get_object (
535+ Bucket = bucket_name ,
536+ Key = "config.json" ,
537+ )
538+ except s3 .exceptions .NoSuchKey as e :
539+ error_message = (
540+ f"Configuration file not found in S3 bucket { bucket_name } . Please check the bucket contents."
541+ )
542+ raise Exception (error_message ) from e
543+
544+ config = json .loads (response ["Body" ].read ().decode ("utf-8" ))
545+ features = get_dict_value (config , "features" )
546+ archive_rules = get_dict_value (config , "archive_configuration" )
547+
515548 # Initialise logging
516549
517550 debug = get_dict_value (features , "show_log_locally" )
@@ -528,9 +561,7 @@ def handler(event, context) -> str: # type: ignore[no-untyped-def]
528561
529562 # Create Boto3 Secret Manager client
530563
531- session = boto3 .session .Session ()
532564 secret_manager = session .client (service_name = "secretsmanager" , region_name = aws_default_region )
533-
534565 logger .log_info ("Boto3 Secret Manager client created." )
535566
536567 # Create GitHub API interfaces (GraphQL and REST)
@@ -567,8 +598,8 @@ def handler(event, context) -> str: # type: ignore[no-untyped-def]
567598 "## Important Notice \n \n " ,
568599 f"This repository has not been updated in over { archive_threshold } days and will be archived in { notification_period } days if no action is taken. \n " ,
569600 "## Actions Required to Prevent Archive \n \n " ,
570- f "1. Update the repository by creating/updating an exemption file. \n " ,
571- f " - The exemption file should be named one of the following: \n " ,
601+ "1. Update the repository by creating/updating an exemption file. \n " ,
602+ " - The exemption file should be named one of the following: \n " ,
572603 f"{ '' .join (formatted_filenames )} \n " ,
573604 " - This file should contain the reason why the repository should not be archived. \n " ,
574605 " - If the file already exists, please update it with the latest information. \n " ,
0 commit comments