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

Private Offer Improvements #69

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions api/Account.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,21 @@ def handle_account(account_msg: dict, procurement_api: ProcurementApi):

account = procurement_api.get_account(account_id)
logger.debug("got account", account=account)
if account and settings.private_offers_only:
approval = None
for account_approval in account["approvals"]:
if account_approval["name"] == "signup":
approval = account_approval
break
logger.debug("found approval", approval=approval)

if approval:
if approval["state"] == "PENDING":
logger.debug("approving account in procurementApi")
procurement_api.approve_account(account_id)

elif approval["state"] == "APPROVED":
logger.info("account is already approved, no action performed")
else:
logger.debug("no approval found")
# The account has been deleted
7 changes: 7 additions & 0 deletions api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ From the api directory you can build and publish the app using the following com

gcloud builds submit --tag <registry path>/doit-easily:1.0 .

# Running the application locally

cd api
docker build . -t doit-easily:local
gcloud auth login --cred-file='path/to/SA_key.json'
gcloud auth application-default login --impersonate-service-account=doit-easily@<GCP-PROJECT-ID>.iam.gserviceaccount.com
docker run -e PORT=8080 -v ./default_settings.toml:/config/custom-settings.toml -e GOOGLE_APPLICATION_CREDENTIALS=/creds.json -v $GOOGLE_APPLICATION_CREDENTIALS:/creds.json -p 8080:8080 -e LOG_LEVEL=debug docker.io/library/doit-easily:local

# Configuration

Expand Down
10 changes: 10 additions & 0 deletions api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ def entitlements():

return render_template("index.html", **page_context)
except Exception as e:
logger.debug("an exception occurred loading index", exception=traceback.format_exc())
logger.error(e)
return {"error": "Loading failed"}, 500

Expand All @@ -76,10 +77,19 @@ def show_account(account_id):
logger.error(e)
return {"error": "Loading failed"}, 500


@app.route("/login", methods=["POST"])
@app.route("/activate", methods=["POST"])
@app.route("/login", methods=["GET"])
@app.route("/activate", methods=["GET"])
def login():
add_request_context_to_log(str(uuid.uuid4()))
if settings.private_offers_only:
return "This listing is only sold through custom pricing. Please contact the vendor.", 200

if request.method == "GET":
return "This integration is running.", 200

encoded = request.form.get("x-gcp-marketplace-token")
logger.debug('encoded token', token=encoded)
if not encoded:
Expand Down
3 changes: 3 additions & 0 deletions api/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,14 @@
Validator("marketplace_project", must_exist=True, is_type_of=str),
# the domain that hosts your product, such as `example-pro.com`
Validator("audience", must_exist=True, is_type_of=str),
Validator("private_offers_only", must_exist=True, is_type_of=bool),
# optional. If set, slack notifications will be sent.
Validator("auto_approve_entitlements", must_exist=True, is_type_of=bool),
# optional. If set, slack notifications will be sent.
Validator("slack_webhook", eq=None) | Validator("slack_webhook", is_type_of=str),
# optional. If set, google pubsub will be used.
Validator("event_topic", eq=None) | Validator("event_topic", 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
@@ -1,6 +1,7 @@
[default]
marketplace_project = '@none None' # This should be set to the name of the project you want to use, otherwise an error will be thrown.
auto_approve_entitlements = false # This should be set to true if you want to auto-approve entitlements.
private_offers_only = false # This should be set to true if you want to auto-approve accounts and are only offering private offers.
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.dns_zone_name'
Expand Down
6 changes: 3 additions & 3 deletions api/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
Flask==2.0.2
Flask==2.3.2
gunicorn==20.1.0
google-cloud-pubsub==2.18.0
pg8000==1.24.0
structlog==21.5.0
requests==2.31.0
requests==2.32.0
google-api-python-client==2.94.0
ratelimit==2.2.1
backoff==2.1.2
dynaconf==3.1.9
pyjwt[crypto]==2.3.0
Werkzeug==2.0.3
Werkzeug==3.0.3
2 changes: 1 addition & 1 deletion api/test/requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
werkzeug==2.0.3
werkzeug==3.0.3