22import botocore
33import os
44
5- def color (text : str ,color : str = 'cyan' ) -> str :
5+
6+ def color (text : str , color : str = "cyan" ) -> str :
67 """
78 colors the output to terminal -- nicer aesthetic!
89 """
9-
10- if color == ' cyan' :
11- r ,g , b = 0 ,255 ,255
12- elif color == ' orange' :
13- r ,g , b = 255 ,179 ,71
14- elif color == ' green' :
15- r ,g , b = 57 ,255 ,20
16-
10+
11+ if color == " cyan" :
12+ r , g , b = 0 , 255 , 255
13+ elif color == " orange" :
14+ r , g , b = 255 , 179 , 71
15+ elif color == " green" :
16+ r , g , b = 57 , 255 , 20
17+
1718 return f"\033 [38;2;{ r } ;{ g } ;{ b } m{ text } \033 [38;2;255;255;255m"
1819
1920
20- bucket_name_parameter = ' MacieDevlabBucketName'
21- sensitive_data_folder = ' test-data'
21+ bucket_name_parameter = " MacieDevlabBucketName"
22+ sensitive_data_folder = " test-data"
2223
23- ssm_client = boto3 .client (' ssm' )
24- s3_client = boto3 .client ('s3' )
25- macie_client = boto3 .client (' macie2' )
24+ ssm_client = boto3 .client (" ssm" )
25+ s3_client = boto3 .client ("s3" )
26+ macie_client = boto3 .client (" macie2" )
2627
2728
28- bucket_name = ssm_client .get_parameter (
29- Name = bucket_name_parameter
30- )[ 'Parameter' ][ 'Value' ]
31- bucket_location = s3_client . get_bucket_location ( Bucket = bucket_name )[ 'LocationConstraint' ]
29+ bucket_name = ssm_client .get_parameter (Name = bucket_name_parameter )[ "Parameter" ][ "Value" ]
30+ bucket_location = s3_client . get_bucket_location ( Bucket = bucket_name )[
31+ "LocationConstraint"
32+ ]
3233if bucket_location is None :
33- bucket_location = 'us-east-1'
34- print (f"Bucket with test data is { color (bucket_name )} in the { color (bucket_location ,color = 'orange' )} region" )
34+ bucket_location = "us-east-1"
35+ print (
36+ f"Bucket with test data is { color (bucket_name )} in the { color (bucket_location ,color = 'orange' )} region"
37+ )
3538macie_console_link = f"https://{ bucket_location } .console.aws.amazon.com/macie/home?region={ bucket_location } "
3639
3740
3841list_files = os .listdir (sensitive_data_folder )
3942for file_name in list_files :
40- response = s3_client .upload_file (f"./{ sensitive_data_folder } /{ file_name } " , bucket_name , file_name )
43+ response = s3_client .upload_file (
44+ f"./{ sensitive_data_folder } /{ file_name } " , bucket_name , file_name
45+ )
4146print (f"Uploaded test data to { color (bucket_name )} bucket" )
4247
4348
4449try :
4550 macie_client .disable_macie ()
4651 print ("Disabled installation of Macie from previous Lab Participant" )
47- except macie_client .exceptions .from_code (' AccessDeniedException' ) as e :
48- print (e .response [' Error' ][ ' Message' ])
52+ except macie_client .exceptions .from_code (" AccessDeniedException" ) as e :
53+ print (e .response [" Error" ][ " Message" ])
4954macie_client .enable_macie ()
5055response = macie_client .get_macie_session ()
5156macie_client .create_custom_data_identifier (
52- description = ' Passport number of Gotham Citizens' ,
57+ description = " Passport number of Gotham Citizens" ,
5358 keywords = [
54- ' passport' ,
59+ " passport" ,
5560 ],
5661 maximumMatchDistance = 50 ,
57- name = ' Gotham Passport' ,
58- regex = ' [ABCDEF]\\ d{7}[A-Z]' ,
62+ name = " Gotham Passport" ,
63+ regex = " [ABCDEF]\\ d{7}[A-Z]" ,
5964 severityLevels = [
60- {
61- 'occurrencesThreshold' : 1 ,
62- 'severity' : 'HIGH'
63- },
64- ]
65+ {"occurrencesThreshold" : 1 , "severity" : "HIGH" },
66+ ],
6567)
6668
6769
68- if response [' status' ] == ' ENABLED' :
70+ if response [" status" ] == " ENABLED" :
6971 print ("Macie enabled!\n \n " )
7072 print (f"🚀 { color ('You are ready to go' ,color = 'green' )} 🚀" )
71- print (f"Click this link, and then click open to continue to Macie: { color (macie_console_link , color = 'cyan' )} " )
73+ print (
74+ f"Click this link, and then click open to continue to Macie: { color (macie_console_link , color = 'cyan' )} "
75+ )
7276 print ("\n \n " )
7377else :
74- print ("Error enabling Macie, please check with the lab organizer" )
78+ print ("Error enabling Macie, please check with the lab organizer" )
0 commit comments