Skip to content
This repository has been archived by the owner on Oct 22, 2024. It is now read-only.

Commit

Permalink
Merge branch 'main' into github-actions
Browse files Browse the repository at this point in the history
  • Loading branch information
sinaj authored Oct 2, 2023
2 parents 03f1cb3 + ee9f75a commit c9cc9ba
Show file tree
Hide file tree
Showing 4 changed files with 125 additions and 2 deletions.
36 changes: 34 additions & 2 deletions api/api.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import base64
import os
import json
import os
import uuid
from urllib.parse import urlparse

from flask import request, Flask, render_template

from middleware import logger, add_request_context_to_log
import traceback

Expand Down Expand Up @@ -135,12 +138,41 @@ def login():
entitlement_id = procurement_api.get_entitlement_id(pcr["name"])
logger.info("approving entitlement", entitlement_id=entitlement_id)
procurement_api.approve_entitlement(entitlement_id)
return "Your account has been approved. You can close this window.", 200
page_context = {
"data": decoded
}
return render_template("register.html", **page_context)
except Exception as e:
logger.error("an exception occurred approving accounts", exception=traceback.format_exc())
return {"error": "failed to approve account"}, 500


@app.route("/register", methods=["POST"])
def register():
if settings.dlp_store_base is None:
return "Could not find the DLP Store API, please contact support.", 200
try:
form = request.form
name = form["name"]
url = urlparse(form["domain"])
domain = f"https://{url.hostname}"
path = url.path if url.path else "/"
data = json.loads(request.form["data"])
resp = requests.post(f"{settings.dlp_store_base}/api/v1/page/customer/", json=dict(
name=name,
domain=domain,
path=path,
platform="non_shopify",
gcp_marketplace_account_id=data["sub"],
platform_data=data,
))
if 200 <= resp.status_code < 300:
return "Your account has been approved. You can close this tab now.", 200
except:
pass
return "Could not complete registration successfully. Please contact support.", 200


# curl localhost:5000/v1/entitlement?state=CREATION_REQUESTED|ACTIVE|PLAN_CHANGE_REQUESTED|PLAN_CHANGED|PLAN_CHANGE_CANCELLED|CANCELLED|PENDING_CANCELLATION|CANCELLATION_REVERTED|DELETED
@app.route("/v1/entitlements", methods=["GET"])
def index():
Expand Down
1 change: 1 addition & 0 deletions api/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
Validator("event_topic", eq=None) | Validator("event_topic", is_type_of=str),
# not optional. If set, codelab mode is enabled.
Validator("is_codelab", must_exist=True, is_type_of=bool),
Validator("dlp_store_base", must_exist=True, is_type_of=str),
)

settings.validators.validate_all()
1 change: 1 addition & 0 deletions api/default_settings.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ auto_approve_entitlements = false # This should be set to true if you want to a
event_topic = '@none None' # Optional. The name of the topic to publish events to.
slack_webhook = '@none None' # Optional. The webhook URL to send Slack messages to.
audience = 'api.prod.marketplace.adeptmind.net'
dlp_store_base = '@none None'

[global] # global will override everything
is_codelab = false
89 changes: 89 additions & 0 deletions api/templates/register.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<!DOCTYPE html>
<html lang=en xmlns:th="http://www.thymeleaf.org">

<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>Entitlement Requests</title>

<link rel="icon" href="{{ url_for('static', filename='img/marketplace.svg') }}" type="image/x-icon">
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Open+Sans|DM+Sans">

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css">

<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js"></script>
<script src="{{ url_for('static', filename = 'approve.js') }}"></script>

<style>
:root {
--border-color: #d0d0d0;
--icon_size: 36px;
--sticky-bg-color: #fff;
}

body {
font-family: "Open Sans";
padding: 0;
position: relative;
width: 100%;
}

.container {
max-width: 1080px;
}

#layout {
padding-top: 30px;
}

.pt-3 {
padding-top: 15px;
}
</style>
</head>

<body>
<div id="layout" class="container">

<div class="row">
<form id="form" action="/register" method="post">
<div class="card">
<div class="card-content">
<span class="card-title">Register your account with Adeptmind</span>
<div class="row pt-3">
<div class="input-field col s6">
<input id="name" name="name" type="text" class="validate"
value="Adeptmind"
required>
<label for="name">Company name</label>
</div>
</div>
<div class="row">
<div class="input-field col s6">
<input placeholder="https://adeptmind.ai" id="domain" name="domain" type="url"
value="https://adeptmind.ai"
class="validate" required>
<label for="domain">Domain</label>
</div>
</div>
<input id="data" name="data" type="hidden">
</div>
<div class="card-action">
<button class="btn waves-effect waves-light" type="submit" name="action">Register</button>
</div>
</div>
</form>
</div>

</div>

<script>
const data = {{ data|tojson }};
document.getElementById('form').onsubmit = () => {
document.getElementById('data').value = JSON.stringify(data);
};
</script>
</body>

0 comments on commit c9cc9ba

Please sign in to comment.