Skip to content

Commit

Permalink
feat: add demo again
Browse files Browse the repository at this point in the history
  • Loading branch information
billmetangmo committed Sep 11, 2024
1 parent 7900254 commit ebf4a86
Show file tree
Hide file tree
Showing 4 changed files with 227 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/deploy_push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
21 changes: 21 additions & 0 deletions infra/api/lambda.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,27 @@ 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
Expand Down
48 changes: 30 additions & 18 deletions infra/main.tf
Original file line number Diff line number Diff line change
@@ -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" {
Expand Down Expand Up @@ -266,19 +283,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" {
Expand All @@ -287,7 +294,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"
Expand All @@ -296,6 +303,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"
Expand Down Expand Up @@ -324,7 +340,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" }
}
175 changes: 175 additions & 0 deletions infra/templates/demo.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width,initial-scale=1.0" />
<meta name="description" content="Recevez une notification dès la sortie de votre passeport sans prise de tête :)"/>
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<script
src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js"
integrity="sha384-9/reFTGAW83EW2RDu2S0VKaIzap3H66lZH81PoYlFhbGU+6BZp6G7niu735Sk7lN"
crossorigin="anonymous"
></script>
<script
src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js"
integrity="sha384-w1Q4orYjBQndcko6MimVbzY0tgp4pWB4lZ7lr30WKz0vr/aWKhXdBNmNb5D92v7s"
crossorigin="anonymous"
></script>
<link
rel="stylesheet"
href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css"
integrity="sha384-JcKb8q3iqJ61gNV9KGb8thSsNjpSL0n8PARn9HuZOnIxN0hoP+VmmDGMN5t9UJ0Z"
crossorigin="anonymous"
/>
<link rel="stylesheet" href="style.css" />
<title>Mtchoun' mouh</title>
<!-- jQuery Modal -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-modal/0.9.1/jquery.modal.min.js"></script>
<link
rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/jquery-modal/0.9.1/jquery.modal.min.css"
/>
<script type="text/javascript">
$(function () {
$("#help").popover({
trigger: "focus",
});
});

// disable onPaste
function disablePaste(e) {
return false;
}
// validate data
function controlFormData(e) {
e.preventDefault();
var Namere = /[A-Za-z]{1}[A-Za-z]/;
if (!Namere.test($("#name-input").val())) {
//alert("Name can not less than 2 char");
$("#errorMessage>p").html("Le nom ne peut avoir moins de 2 caractères!");
$("#errorMessage").modal("show");
return;
}

$("#confirmationModal").modal("show");
}

function submitToAPI(e) {
e.preventDefault();
var URL = "${url}";

var name = $("#name-input").val();
var data = {
name: name,
};

$.ajax({
type: "POST",
url: URL,
dataType: "json",
crossDomain: "true",
contentType: "application/json; charset=utf-8",
data: JSON.stringify(data),

success: function (response) {
// clear form and show a success message
$("#errorMessage>p").html(
"Nous avons trouvé l <a href="+response["message"]+">image</a> d'où provient votre choix &#128578;"

);
$("#errorMessage").css("background", "#0f7555");
console.log("ok")
$("#errorMessage").modal("show");
document.getElementById("contact-form").reset();
//location.reload();
},
error: function () {
// show an error message
$("#errorMessage>p").html(
"Le nom rentré n'existe pas. \n Veuillez vérifier l'orthographe. "
);
$("#errorMessage").modal("show");
//location.reload();
},
});
}
</script>
</head>
<body class="text-center">
<!--https://aws.amazon.com/fr/blogs/architecture/create-dynamic-contact-forms-for-s3-static-websites-using-aws-lambda-amazon-api-gateway-and-amazon-ses/-->
<form id="contact-form" method="post" class="form-signin">
<div class="mb-2">
<img alt="Logo cameroun" width="150" src="Armoiries_cameroun.svg" />
</div>
<h1 class="h5 font-weight-normal highlight">Si vous êtes là c'est que vous voulez une démonstration. Pas de soucis &#128578; </h1>
<h2 class="h6 font-weight-normal highlight">Nous vous proposons donc de choisir un nom au hasard dans le <b>communiqué du 22/09/2020</b>.
Pour cela rien de plus simple: rendez vous juste sur la page du <a href="https://www.consulacam-marseille.fr/index.php?p=consulat-cameroun-passeports">consulat</a>
et entrez ci-dessous celui-ci choisi.
</h2>
<b>NOTEZ BIEN </b>
<svg
data-html="true"
tabindex="0"
id="help"
data-toggle="popover"
data-trigger="focus"
title="Important !"
data-content="<p>Le nom doit être écrit pareil et dans le même ordre que celui choisi dans la page du consulat</p>
<p>Liste des contraintes actuelles (vérifiez que vous n'entrez pas dans ces cas) qui ne sont pas supportés: </p>
<ol>
<li>Les noms comprenant le mot <b>vve</b></li>
<li>Les noms comprenant les accents circonflexes comme Benoît</li>
<li>Les noms comprenant les trémas comme Raïssa</li>
<li>Les noms comprenant qu'un seul mot </li>
<li>Les noms comprenant un mot se terminant par i comme Etoundi </li>
<li>Les noms comprenant des chiffres romains</li>
</ol>"
aria-hidden="true"
focusable="false"
data-prefix="fas"
data-icon="info-circle"
class="svg-inline--fa fa-info-circle fa-w-16"
role="img"
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 512 512"
>
<path
fill="currentColor"
d="M256 8C119.043 8 8 119.083 8 256c0 136.997 111.043 248 248 248s248-111.003 248-248C504 119.083 392.957 8 256 8zm0 110c23.196 0 42 18.804 42 42s-18.804 42-42 42-42-18.804-42-42 18.804-42 42-42zm56 254c0 6.627-5.373 12-12 12h-88c-6.627 0-12-5.373-12-12v-24c0-6.627 5.373-12 12-12h12v-64h-12c-6.627 0-12-5.373-12-12v-24c0-6.627 5.373-12 12-12h64c6.627 0 12 5.373 12 12v100h12c6.627 0 12 5.373 12 12v24z"
></path>
</svg>
<label for="input-name" class="sr-only">Name:</label>
<input
type="text"
id="name-input"
placeholder="Veuillez le nom choisi …"
style="text-transform: uppercase"
class="form-control"
/>
<div
class="g-recaptcha"
data-sitekey="6Lc7cVMUAAAAAM1yxf64wrmO8gvi8A1oQ_ead1ys"
></div>

<button
class="btn btn-lg btn-primary btn-block"
type="button"
onClick="submitToAPI(event)"
>
Submit
</button>

<h3 class="h6 mt-2 font-weight-normal">Retournez en <a href="index.html">page d'accueil </a> </h3>

<div class="mt-5">
<img alt="Logo cameroun" width="150" src="Armoiries_de_Marseille.svg" />
</div>
<p class="mt-3 mb-3 text-muted">&copy; 2020 - <a href="mailto: ${contact}">Contact</a></p>
</form>

<!-- Alert-error -->
<div id="errorMessage" class="modal">
<p>Content error</p>
</div>
</body>
</html>

0 comments on commit ebf4a86

Please sign in to comment.