Skip to content

Commit

Permalink
feat: change spaces example
Browse files Browse the repository at this point in the history
  • Loading branch information
cowan-macady committed Jun 16, 2023
1 parent cb47dbf commit 058f251
Show file tree
Hide file tree
Showing 37 changed files with 2,950 additions and 136 deletions.
2 changes: 0 additions & 2 deletions examples/sdk-backend/README.md

This file was deleted.

43 changes: 0 additions & 43 deletions examples/sdk-backend/app/api/app_with_agent_credentials.py

This file was deleted.

2 changes: 1 addition & 1 deletion examples/sdk-backend/Pipfile → examples/spaces/Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ name = "pypi"
connexion = {version = ">=2.6.0", extras = ["swagger-ui"]}
swagger-ui-bundle = ">=0.0.4"
python-dateutil = ">=2.6.0"
indykite-sdk-python = {ref = "v1.20.0", git = "https://github.com/indykite/indykite-sdk-python"}
indykite-sdk-python = {ref = "v1.22.0", git = "https://github.com/indykite/indykite-sdk-python"}
python-jose = "3.3.0"
gql = "3.4.0"
requests = ">=2.31.0"
Expand Down
172 changes: 86 additions & 86 deletions examples/sdk-backend/Pipfile.lock → examples/spaces/Pipfile.lock

Large diffs are not rendered by default.

30 changes: 30 additions & 0 deletions examples/spaces/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# IndyKite Python SDK spaces example
Create an AppSpace, a tenant, an application, an application agent and get application agent credentials

## Requirements

* Python >= 3.10
* IndyKite account: Accounted created by logging in on https://console.indykite.id/
* Customer created on https://console.indykite.id/
* Service account created on https://console.indykite.id/ under the above customer

## Installation
* Copy example to local environment
* In the spaces directory, run:

pipenv install
pipenv shell

* Credentials: export the file as env variable in CLI (setex for Windows)

export INDYKITE_SERVICE_ACCOUNT_CREDENTIALS_FILE=path_to_service_account_file

* In spaces directory, run:

flask run

* You should get:

Running on http://127.0.0.1:5000


Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import traceback
from flask import redirect, url_for
from flask import redirect, url_for, render_template, session
from flask_openapi3 import HTTPBearer, HTTPBase
from flask_openapi3 import Info
from flask_openapi3 import OpenAPI
Expand Down Expand Up @@ -49,13 +49,21 @@ def create_app():


app = create_app()
app.config['SECRET_KEY'] = 'd5fb8c4fa8bd46638dadc4e751e0d68d'


@app.route("/")
def index():
return redirect(url_for("openapi.swagger"))
return render_template("index.html")


@app.route("/kill")
def kill():
session.clear()
return render_template("index.html")


if __name__ == "__main__":
app.run(debug=True)


File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from app.form.app_space import AppSpaceById, AppSpaceCreate
from app.utils.response import get_response, response_data
from app.utils.helper import change_display_to_name
from flask import Flask, render_template, request, url_for, flash, redirect, session

__version__ = "/v1"
__bp__ = "/app_space"
Expand Down Expand Up @@ -35,3 +36,40 @@ def get_app_space(path: AppSpaceById):
return response_data("AppSpaceById", get_response(app_space))
else:
return response_data("AppSpaceById", "Invalid app_space id")


@api.get("/new")
def new_app_space():
return render_template('new_app_space.html')


@api.post("/new")
def new_app_space_post():
session.clear()
customer_id = request.form['customer_id']
display_name = request.form['display_name']
description = request.form['description']

if not customer_id:
flash('Customer id is required!')
elif not display_name:
flash('Display name is required!')
elif not description:
flash('Description is required!')
else:
client_config = ConfigClient()
app_space = client_config.create_app_space(customer_id,
change_display_to_name(display_name),
display_name,
description,
[])
if app_space:
session['app_space'] = get_response(app_space)
app_space_by_id = client_config.get_app_space_by_id(app_space.id)
if app_space_by_id:
session['app_space_by_id'] = get_response(app_space_by_id)
return render_template('index.html')
else:
session['app_space'] = "Invalid app_space creation"
return render_template('index.html')
return render_template('new_app_space.html')
104 changes: 104 additions & 0 deletions examples/spaces/app/api/app_with_agent_credentials.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
from flask_openapi3 import APIBlueprint
from flask_openapi3 import Tag
from indykite_sdk.config import ConfigClient
from app.config import API_PREFIX
from app.form.app_with_agent_credentials import ApplicationWithAgentCredentialsCreate
from app.utils.response import get_response, get_credentials_response, response_data
from flask import Flask, render_template, request, url_for, flash, redirect, session
import json

__version__ = "/v1"
__bp__ = "/app_with_agent_credentials"
url_prefix = API_PREFIX + __version__ + __bp__
tag = Tag(name=" ApplicationWithAgentCredentials", description=" ApplicationWithAgentCredentials")
api = APIBlueprint(__bp__, __name__, url_prefix=url_prefix, abp_tags=[tag])


@api.post("")
def create_app_with_agent_credentials(body: ApplicationWithAgentCredentialsCreate):
client_config = ConfigClient()
app_with_agent_credentials = client_config.create_application_with_agent_credentials(
body.app_space_id,
body.tenant_id,
body.application_name,
body.application_agent_name,
body.application_agent_credentials_name,
"jwk",
None,
None)
if app_with_agent_credentials:
cred = {'ApplicationWithAgentCredentials': []}
for k, v in app_with_agent_credentials.items():
app = {k: []}
if k == "response_application_agent_credentials":
app_dict = get_credentials_response(v)
else:
app_dict = json.loads(get_response(v))
app[k].append(app_dict)
cred['ApplicationWithAgentCredentials'].append(app)
return response_data("ApplicationWithAgentCredentialsCreate",cred)
else:
return response_data("ApplicationWithAgentCredentialsCreate", "Invalid app_with_agent_credentials creation")


@api.get("/new")
def new_app_with_agent_credentials():
return render_template('new_app_with_agent_credentials.html')


@api.post("/new")
def new_app_with_agent_credentials_post():
app_space_id = request.form['app_space_id']
tenant_id = request.form['tenant_id']
application_name = request.form['application_name']
application_agent_name = request.form['application_agent_name']
application_agent_credentials_name = request.form['application_agent_credentials_name']

if not app_space_id:
flash('AppSpace id is required!')
elif not tenant_id:
flash('Tenant id is required!')
elif not application_name:
flash('Application name is required!')
elif not application_agent_name:
flash('Application agent name is required!')
elif not application_agent_credentials_name:
flash('Application agent credentials name is required!')
else:
client_config = ConfigClient()
app_with_agent_credentials = client_config.create_application_with_agent_credentials(
app_space_id,
tenant_id,
application_name,
application_agent_name,
application_agent_credentials_name,
"jwk",
None,
None)
if app_with_agent_credentials:
cred = {'ApplicationWithAgentCredentials': []}
for k, v in app_with_agent_credentials.items():
app = {k: []}
if k == "response_application_agent_credentials":
app_dict = get_credentials_response(v)
if v.agent_config:
ac = v.agent_config
session['id'] = v.id
session['kid'] = v.kid
session['agent_config'] = ac.decode("utf-8")
elif k == "response_application":
session['response_application'] = json.loads(get_response(v))
elif k == "response_application_agent":
session['response_application_agent'] = json.loads(get_response(v))
else:
app_dict = json.loads(get_response(v))
#app[k].append(app_dict)
#cred['ApplicationWithAgentCredentials'].append(app)

#session['app_with_agent_credentials'] = get_response(cred)
return render_template('index.html')
else:
session['app_with_agent_credentials'] = "Invalid app_with_agent_credentials creation"
return render_template('index.html')
return render_template('new_app_space.html')

Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from app.form.tenant import TenantById, TenantCreate
from app.utils.response import get_response, response_data
from app.utils.helper import change_display_to_name
from flask import Flask, render_template, request, url_for, flash, redirect, session

__version__ = "/v1"
__bp__ = "/tenant"
Expand Down Expand Up @@ -36,3 +37,39 @@ def get_tenant(path: TenantById):
return response_data("TenantById", get_response(tenant))
else:
return response_data("TenantById", "Invalid tenant id")


@api.get("/new")
def new_tenant():
return render_template('new_tenant.html')


@api.post("/new")
def new_tenant_post():
issuer_id = request.form['issuer_id']
display_name = request.form['display_name']
description = request.form['description']

if not issuer_id:
flash('Issuer id is required!')
elif not display_name:
flash('Display name is required!')
elif not description:
flash('Description is required!')
else:
client_config = ConfigClient()
tenant = client_config.create_tenant(issuer_id,
change_display_to_name(display_name),
display_name,
description,
[])
if tenant:
session['tenant'] = get_response(tenant)
tenant_by_id = client_config.get_tenant_by_id(tenant.id)
if tenant_by_id:
session['tenant_by_id'] = get_response(tenant_by_id)
return render_template('index.html')
else:
session['tenant'] = "Invalid tenant creation"
return render_template('index.html')
return render_template('new_tenant.html')
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
11 changes: 11 additions & 0 deletions examples/spaces/app/static/css/animate.min.css

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions examples/spaces/app/static/css/bootstrap.min.css

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions examples/spaces/app/static/css/font-awesome.min.css

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions examples/spaces/app/static/css/fontawesome.min.css

Large diffs are not rendered by default.

48 changes: 48 additions & 0 deletions examples/spaces/app/static/css/reset.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/* http://meyerweb.com/eric/tools/css/reset/
v2.0 | 20110126
License: none (public domain)
*/

html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed,
figure, figcaption, footer, header, hgroup,
menu, nav, output, ruby, section, summary,
time, mark, audio, video {
margin: 0;
padding: 0;
border: 0;
font-size: 100%;
font: inherit;
vertical-align: baseline;
}
/* HTML5 display-role reset for older browsers */
article, aside, details, figcaption, figure,
footer, header, hgroup, menu, nav, section {
display: block;
}
body {
line-height: 1;
}
ol, ul {
list-style: none;
}
blockquote, q {
quotes: none;
}
blockquote:before, blockquote:after,
q:before, q:after {
content: '';
content: none;
}
table {
border-collapse: collapse;
border-spacing: 0;
}

0 comments on commit 058f251

Please sign in to comment.