Skip to content

Instantly share code, notes, and snippets.

@ramnes
Created March 29, 2022 14:01
Show Gist options
  • Save ramnes/895104ee5f03853e145369056d44a3f9 to your computer and use it in GitHub Desktop.
Save ramnes/895104ee5f03853e145369056d44a3f9 to your computer and use it in GitHub Desktop.
Restrict the deployment of Qovery applications to changes in their root path
import json
import os.path
import httpx
context_path = os.path.expanduser("~/.qovery/context.json")
with open(context_path) as context_file:
context = json.load(context_file)
client = httpx.Client(
base_url="https://api.qovery.com",
headers={"Authorization": f"Bearer {context['access_token']}"},
)
def get_applications():
environments = client.get(f"/project/{context['project_id']}/environment").json()["results"]
for environment in environments:
applications = client.get(f"/environment/{environment['id']}/application").json()["results"]
for application in applications:
yield application
def ensure_restriction(application):
root_path = application["git_repository"]["root_path"]
if root_path == "/":
return
restrictions = client.get(f"/application/{application['id']}/deploymentRestriction").json()["results"]
if restrictions:
return
payload = {
"mode": "MATCH",
"type": "PATH",
"value": root_path[1:]
}
client.post(f"/application/{application['id']}/deploymentRestriction", json=payload)
for application in get_applications():
ensure_restriction(application)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment