Skip to content

Instantly share code, notes, and snippets.

View ricardochaves's full-sized avatar

Ricardo Baltazar Chaves ricardochaves

View GitHub Profile
- uses: ricardochaves/python-lint@test
with:
python-root-list: 'python_alelo tests'
use-pylint: false
use-pycodestyle: false
use-flake8: false
use-black: false
use-mypy: false
use-isort: false
name: Python Lint
on: [pull_request]
jobs:
lint:
runs-on: ubuntu-latest
steps:
name: Python application
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
@ricardochaves
ricardochaves / setup.yml
Created November 6, 2019 22:31
Script for Google Deployment Manager
imports:
- path: setup-k8s.py
- path: setup-ip.py
- path: setup-sql.py
resources:
- name: cluster
type: setup-k8s.py
properties:
CLUSTER_NAME: cluster-1
@ricardochaves
ricardochaves / setup-ip.py
Created November 6, 2019 21:51
Recipe for Google Deployment Manager
def GenerateConfig(context):
"""Generate YAML resource configuration."""
ip_name = context.properties["IP_NAME"]
region = context.properties["REGION"]
resources = []
resources.append(
{
"name": ip_name,
@ricardochaves
ricardochaves / setup-sql.py
Created November 6, 2019 21:31
Recipe for Google Deployment Manager
import uuid
def GenerateConfig(context):
"""Generate YAML resource configuration."""
sql_zone = context.properties["SQL_ZONE"]
sql_name = str(uuid.uuid4().hex)
db_name = context.properties["DB_NAME"]
user_name = context.properties["USER_NAME"]
@ricardochaves
ricardochaves / setup-k8s.py
Created November 6, 2019 21:22
Recipe for Google Deployment Manager
def GenerateConfig(context):
"""Generate YAML resource configuration."""
cluster_name = context.properties["CLUSTER_NAME"]
cluster_zone = context.properties["CLUSTER_ZONE"]
number_of_nodes = context.properties["NUM_NODES"]
resources = []
resources.append(
{
@app.route("/privateurl")
def privateurl():
if "access_token" not in flask.session:
return flask.redirect(flask.url_for("login"))
token = flask.session.get("access_token")
logging.info(f"Token: {token}")
return jsonify({"token": token})
@app.route("/getAToken")
def main_logic():
code = flask.request.args["code"]
state = flask.request.args["state"]
if state != flask.session["state"]:
raise ValueError("State does not match")
auth_context = adal.AuthenticationContext(AUTHORITY_URL)
token_response = auth_context.acquire_token_with_authorization_code(
code, REDIRECT_URI, config.RESOURCE, config.CLIENT_ID, config.CLIENT_SECRET
)
@app.route("/login")
def login():
auth_state = str(uuid.uuid4())
flask.session["state"] = auth_state
authorization_url = TEMPLATE_AUTHZ_URL.format(
config.TENANT, config.CLIENT_ID, REDIRECT_URI, auth_state, config.RESOURCE
)
resp = flask.Response(status=307)
resp.headers["location"] = authorization_url
return resp