-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add quarantine bucket feature #5
base: main
Are you sure you want to change the base?
Conversation
cloud_function/main.py
Outdated
logger = logging.Client().logger() | ||
|
||
|
||
def move_object_to_quarantine(data, context): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Les commentaires sont un peu superflus ici, je pense que le code est auto-porteur
cloud_function/main.py
Outdated
def move_object_to_quarantine(data, context): | ||
data_json = json.loads(base64.b64decode(data["data"]).decode("utf-8")) | ||
|
||
# Extract the bucket and object name from the event data |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# Extract the bucket and object name from the event data |
cloud_function/main.py
Outdated
bucket_name = data_json["bucket"] | ||
object_name = data_json["name"] | ||
|
||
# Define the regex pattern for object name validation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# Define the regex pattern for object name validation |
cloud_function/main.py
Outdated
# Define the regex pattern for object name validation | ||
regex_validation = os.environ["REGEX_VALIDATION"] | ||
|
||
# # Initialize the Cloud Storage client |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# # Initialize the Cloud Storage client |
cloud_function/main.py
Outdated
# # Initialize the Cloud Storage client | ||
storage_client = storage.Client() | ||
|
||
# # Get the object metadata |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# # Get the object metadata |
cloud_function/main.py
Outdated
source_bucket = storage_client.get_bucket(bucket_name) | ||
source_blob = source_bucket.blob(object_name) | ||
|
||
# # Check if the object name matches the regex pattern |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# # Check if the object name matches the regex pattern |
cloud_function/main.py
Outdated
# Move the object to the quarantine bucket | ||
quarantine_bucket_name = f"{bucket_name}-quarantine" | ||
quarantine_bucket = storage_client.bucket(quarantine_bucket_name) | ||
source_bucket.copy_blob(source_blob, quarantine_bucket, object_name) | ||
source_blob.delete() | ||
|
||
logger.warn(f"Object {object_name} moved to the quarantine bucket.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Je pense que ce morceau là devrait être une fonction dédiée.
No description provided.