Skip to content

Commit

Permalink
Add stuff for local test
Browse files Browse the repository at this point in the history
  • Loading branch information
saschakiefer committed Dec 19, 2020
1 parent ef6afea commit b0c2b88
Show file tree
Hide file tree
Showing 9 changed files with 82 additions and 5 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ PaaS application ready to deploy to [SAP Cloud Platform](https://www.sap.com/ger
- Flask application container with `main` blueprint
- AppRouter module to protect the application from unauthorized users
- Example Role implemented
- Local test possible

## Prerequisite

Expand Down
2 changes: 1 addition & 1 deletion cookiecutter_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@
pass


cookiecutter(curdir, extra_context=extra_context, overwrite_if_exists=False)
cookiecutter(curdir, extra_context=extra_context, overwrite_if_exists=True)
6 changes: 6 additions & 0 deletions hooks/post_gen_project.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import os

# In the template we named it `gitignore` so it does not interfere with
# the templates `.gitignore`.
# Rename gitignore -> .gitignore
os.rename("gitignore", ".gitignore")
58 changes: 55 additions & 3 deletions {{cookiecutter.repo_name}}/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,67 @@

Simple SAP Cloud Platform PaaS App. Written in Python with Flask and protected by the AppRouter.

## Prerequisites
## Deployment
### Pre Deployment
You have to be logged in to your cloud platform service account.

Before you can deploy the application, you have to create a `xsuaa` service instance with
```bash
cf create-service xsuaa application {{ cookiecutter.uaa_service_instance_name }} -c xs-security.json
```

## Post Deployment
### Deployment
You can deploy the app with `cf push`.

After the deployment you have to create a Role Collection which contains the `User`-role (alternatively you cann add the role to an existing role collection).
### Post Deployment

After the deployment you have to create a Role Collection which contains the `User`-role (alternatively you can add the role to an existing role collection).
This role collection needs to be assigned to the user to logon.

## Local Testing
### Prerequisite
- `node` version: `^12.0.0`
- you have deployed the application once to CF
- you are logged on to your SCP space

### AppRouter
#### Configure Connection to XSUAA
Create a service key for accessing XSUAA and get the key values:
```bash
cf create-service-key {{ cookiecutter.uaa_service_instance_name }} {{ cookiecutter.uaa_service_instance_name }}-key
cf service-key {{ cookiecutter.uaa_service_instance_name }} {{ cookiecutter.uaa_service_instance_name }}-key
```

Copy the output ant place it into the `{{cookiecutter.approuter_module_name}}/default-service.json` file
(replace the empty object with the object you get from the key).

#### Run the AppRouter

```
cd {{ cookiecutter.approuter_module_name }}
npm install # only once
npm start
```

The AppRouter is no ready to serve requests on `http://localhost:5000`.

### Run/Debug the Flask Application

#### Install Dependent Packages
Create a virtual environment and install the dependent packages
```bash
python3 -m venv .venv
pip install -r {{ cookiecutter.python_module_name }}/requirements.txt
source .venv/bin/activate
```

#### Set Environment Variables
To function correctly, the `xssec` library needs the same environment variables as it finds in the Cloud Foundry container.

You can get these variables with `cf env {{ cookiecutter.scp_app_name }}-core`.

In the output you will find two environment variables: `VCAP_SERVICES` and `VCAP_APPLICATION`.
Both needs to be set in the environment you run Flask in. If you want to debug the app in your IDE of choice, make sure, that both variables are set in the run configuration (in both cases the complete JSON structure)
_HINT_: Watch out for the last `}` in the output and make sure, that you copy the correct `json` object.

**IMPORTANT**: Make sure, that your Flask app listens on port `4000`. If you want to use a different port, make sure, that you configure the correct one in the `{{cookiecutter.approuter_module_name}}/default-env.json` file.
Original file line number Diff line number Diff line change
Expand Up @@ -708,3 +708,4 @@ MigrationBackup/
# Fody - auto-generated XML schema
FodyWeavers.xsd

default-services.json
4 changes: 3 additions & 1 deletion {{cookiecutter.repo_name}}/xs-security.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"xsappname": "{{ cookiecutter.scp_app_name }}",
"description": "This is the description of the application",
"tenant-mode": "dedicated",
"scopes": [
{
Expand All @@ -23,7 +24,8 @@
],
"oauth2-configuration": {
"redirect-uris": [
"https://{{ cookiecutter.scp_app_host_prefix }}{{ cookiecutter.scp_app_name }}.{{ cookiecutter.scp_app_domain }}"
"https://{{ cookiecutter.scp_app_host_prefix }}{{ cookiecutter.scp_app_name }}.{{ cookiecutter.scp_app_domain }}",
"http://localhost:5000"
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
default-env.json
default-services.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"destinations": [
{
"name": "core",
"url": "http://localhost:4000",
"forwardAuthToken": true,
"strictSSL": false
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"uaa": {}
}

0 comments on commit b0c2b88

Please sign in to comment.