Skip to content
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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

pe-artefact
Copy link
Contributor

No description provided.

logger = logging.Client().logger()


def move_object_to_quarantine(data, context):
Copy link
Collaborator

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

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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Extract the bucket and object name from the event data

bucket_name = data_json["bucket"]
object_name = data_json["name"]

# Define the regex pattern for object name validation
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Define the regex pattern for object name validation

# Define the regex pattern for object name validation
regex_validation = os.environ["REGEX_VALIDATION"]

# # Initialize the Cloud Storage client
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# # Initialize the Cloud Storage client

# # Initialize the Cloud Storage client
storage_client = storage.Client()

# # Get the object metadata
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# # Get the object metadata

source_bucket = storage_client.get_bucket(bucket_name)
source_blob = source_bucket.blob(object_name)

# # Check if the object name matches the regex pattern
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# # Check if the object name matches the regex pattern

Comment on lines 30 to 36
# 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.")
Copy link
Collaborator

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.

@pe-artefact pe-artefact requested a review from AlexisVLRT June 6, 2023 12:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants