diff --git a/.github/workflows/deploy_push.yml b/.github/workflows/deploy_push.yml
index 45db91a3..b1f99ad9 100644
--- a/.github/workflows/deploy_push.yml
+++ b/.github/workflows/deploy_push.yml
@@ -139,7 +139,7 @@ jobs:
if: github.ref_name != 'master'
run: |
cd infra
- aws s3 sync ../html s3://mtchoun-mouh-$GITHUB_REF_NAME-mtchoun-mouh.mongulu.cm --exclude "index.html" --delete
+ aws s3 sync ../html s3://mtchoun-mouh-$GITHUB_REF_NAME-mtchoun-mouh.mongulu.cm --exclude "index.html" --exclude "demo.html" --delete
- name: "website: check readiness"
uses: APina03/wait_for_response@master
with:
diff --git a/coverage.svg b/coverage.svg
index b4a82e60..f9eb6b47 100644
--- a/coverage.svg
+++ b/coverage.svg
@@ -15,7 +15,7 @@
coverage
coverage
- 56%
- 56%
+ 55%
+ 55%
diff --git a/infra/api/extract.py b/infra/api/extract.py
index 57f9a2cc..70c96e93 100644
--- a/infra/api/extract.py
+++ b/infra/api/extract.py
@@ -4,6 +4,7 @@
import os
import zulip
from textractor import Textractor
+from PIL import UnidentifiedImageError
def Images_in_Bucket(Bucket_Name):
"""Gets a list of all image names in an S3 bucket.
@@ -98,23 +99,30 @@ def Extract_Users(s3BucketName, ImageName): # sourcery no-metrics
list: A list of extracted user information dicts.
"""
region = os.environ["REGION"]
- extractor = Textractor(region_name=os.environ["REGION"])
- document = extractor.detect_document_text(file_source=f"s3://{s3BucketName}/{ImageName}")
- filtered_lines = []
+ extractor = Textractor(region_name=region)
errors_tab = []
+ filtered_lines = []
+
+ try:
+ # Try to detect document text, catch UnidentifiedImageError if occurs
+ document = extractor.detect_document_text(file_source=f"s3://{s3BucketName}/{ImageName}")
+ except UnidentifiedImageError as e:
+ print(f"UnidentifiedImageError: {str(e)} - Image: {ImageName}")
+ errors_tab.append({"error": str(e), "image": ImageName})
+ return errors_tab
+
for line in document.lines:
# Vérifie si aucun mot de stop_words n'est présent dans la ligne
if not any(stop_word in str(line) for stop_word in stopWords):
filtered_lines.append(str(line))
+
for line in filtered_lines:
-
try:
UserName = line.split(". ")[1:] if "." in line else line
if isinstance(UserName, list):
UserName = ". ".join(UserName)
if UserName != "":
- # We choosed to save all the names in lower former instead of upper because of the DU stopWord
- # Indeed if upper names , all persons DU like DURAND in their names will not be detected.
+ # We choose to save all names in lower case to avoid issues with stop words like 'DU'
print(f"Username={UserName.lower()}")
insert_dynamodb(UserName.lower(), ImageName)
except Exception as e:
diff --git a/infra/api/lambda.py b/infra/api/lambda.py
index 52f94d78..59117afb 100644
--- a/infra/api/lambda.py
+++ b/infra/api/lambda.py
@@ -52,6 +52,26 @@ def register_handler(event, context):
}
),
}
+ else:
+
+ os.environ['LINKS_TABLE'] = "Links"
+ Scan_reponse = Scan_Users(name.lower(), "Users")
+ image_url = Scan_reponse[0]["URLImage"]
+ print(image_url)
+
+ return {
+ "statusCode": 200,
+ "headers": {
+ "Access-Control-Allow-Origin": "*",
+ "Access-Control-Allow-Headers": "Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token",
+ "Access-Control-Allow-Methods": "GET,OPTIONS,POST,PUT",
+ },
+ "body": json.dumps(
+ {
+ "message": f" {image_url}",
+ }
+ ),
+ }
except Exception as e:
capture_exception(e)
raise
diff --git a/infra/main.tf b/infra/main.tf
index a08c576d..c2f15ac6 100644
--- a/infra/main.tf
+++ b/infra/main.tf
@@ -1,5 +1,22 @@
locals {
requirements_path = "api/requirements.txt"
+ url = join("/", [aws_api_gateway_deployment.test.invoke_url, aws_api_gateway_resource.resource.path_part])
+
+ demo_page = templatefile("templates/demo.tmpl", {
+ url = local.url
+ contact = var.MAINTAINER_MAIL
+ })
+
+ index_page = templatefile("templates/index.tmpl", {
+ url = local.url
+ contact = var.MAINTAINER_MAIL
+ })
+
+ terratag_added_main = { "environment" = "mtchoun-mouh-master", "project" = "mtchoun-mouh" }
+
+ # If your backend is not Terraform Cloud, the value is ${terraform.workspace}
+ # otherwise the value retrieved is that of the TFC_WORKSPACE_NAME with trimprefix
+ workspace = var.TFC_WORKSPACE_NAME != "" ? trimprefix("${var.TFC_WORKSPACE_NAME}", "mtchoun-mouh-") : "${terraform.workspace}"
}
resource "aws_s3_bucket" "images" {
@@ -193,6 +210,8 @@ resource "aws_lambda_function" "scan" {
source_code_hash = data.archive_file.lambda_zip.output_base64sha256
runtime = "python3.8"
timeout = 900
+ layers = [aws_lambda_layer_version.test_lambda_layer.arn] //lambda_layer here is the name
+ depends_on = [aws_lambda_layer_version.test_lambda_layer]
environment {
variables = {
@@ -266,19 +285,9 @@ resource "aws_api_gateway_deployment" "test" {
stage_name = (terraform.workspace == "mtchoun-mouh-master") ? var.stage_name : "${terraform.workspace}-${var.stage_name}"
}
-locals {
-
- url = join("/", [aws_api_gateway_deployment.test.invoke_url, aws_api_gateway_resource.resource.path_part])
-
- index_page = templatefile("templates/index.tmpl", {
- url = local.url
- contact = var.MAINTAINER_MAIL
- })
-
- # If your backend is not Terraform Cloud, the value is ${terraform.workspace}
- # otherwise the value retrieved is that of the TFC_WORKSPACE_NAME with trimprefix
- workspace = var.TFC_WORKSPACE_NAME != "" ? trimprefix("${var.TFC_WORKSPACE_NAME}", "mtchoun-mouh-") : "${terraform.workspace}"
-
+resource "local_file" "demo_page" {
+ content = local.demo_page
+ filename = "../html/demo.html"
}
resource "local_file" "index_page" {
@@ -287,7 +296,7 @@ resource "local_file" "index_page" {
}
// Terraform cloud have the file but the CI no so we upload it from terraform cloud
-resource "aws_s3_bucket_object" "example_file" {
+resource "aws_s3_bucket_object" "index_page" {
bucket = aws_s3_bucket.website.id
key = "index.html"
source = "../html/index.html"
@@ -296,6 +305,15 @@ resource "aws_s3_bucket_object" "example_file" {
depends_on = [local_file.index_page]
}
+resource "aws_s3_bucket_object" "demo_page" {
+ bucket = aws_s3_bucket.website.id
+ key = "demo.html"
+ source = "../html/demo.html"
+ content_type = "text/html"
+
+ depends_on = [local_file.demo_page]
+}
+
# Inspired from https://frama.link/GFCHrjEL
module "cors" {
source = "squidfunk/api-gateway-enable-cors/aws"
@@ -324,7 +342,3 @@ resource "aws_lambda_permission" "allow_cloudwatch_to_call_check_foo" {
principal = "events.amazonaws.com"
source_arn = aws_cloudwatch_event_rule.scheduler.arn
}
-
-locals {
- terratag_added_main = { "environment" = "mtchoun-mouh-master", "project" = "mtchoun-mouh" }
-}
diff --git a/infra/templates/demo.tmpl b/infra/templates/demo.tmpl
new file mode 100644
index 00000000..ff49913a
--- /dev/null
+++ b/infra/templates/demo.tmpl
@@ -0,0 +1,175 @@
+
+
+
+
+
+
+
+
+
+
+
+ Mtchoun' mouh
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file