Skip to content

Commit 6252521

Browse files
authored
Merge pull request #22900 from Joysie/master
Node and Python tutorials are updated
2 parents 39fbb71 + f117710 commit 6252521

File tree

2 files changed

+53
-45
lines changed

2 files changed

+53
-45
lines changed

tutorials/btp-cf-buildpacks-node-create/btp-cf-buildpacks-node-create.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ primary_tag: programming-tool>node-js
1919
- You have a trial or a productive account for SAP Business Technology Platform (SAP BTP). If you don't have such yet, you can create one so you can [try out services for free] (https://developers.sap.com/tutorials/btp-free-tier-account.html).
2020
- You have created a subaccount and a space on Cloud Foundry Environment.
2121
- [cf CLI] (https://help.sap.com/products/BTP/65de2977205c403bbc107264b8eccf4b/4ef907afb1254e8286882a2bdef0edf4.html) is installed locally.
22-
- [Node.js] (https://nodejs.org/en/about/releases/) and [npm] (https://docs.npmjs.com/downloading-and-installing-node-js-and-npm) are installed locally. Make sure you have the latest Node.js version. In this tutorial, we use v.18.
22+
- [Node.js] (https://nodejs.org/en/about/releases/) and [npm] (https://docs.npmjs.com/downloading-and-installing-node-js-and-npm) are installed locally. Make sure you have the latest Node.js version. In this tutorial, we use v.16.
2323
- You have installed an integrated development environment, for example [Visual Studio Code] (https://code.visualstudio.com/).
2424

2525
## Intro
26-
This tutorial will guide you through creating and setting up a simple Node.js application by using cf CLI. You will start by building and deploying a web application that returns simple data – a **Hello World!** message, and then invoking this app through another one - a web microservice (application router).
26+
This tutorial will guide you through creating and setting up a simple Node.js application in cf CLI. You will start by building and deploying a web application that returns simple data – a **Hello World!** message, and then invoking this app through a web microservice (application router). Finally, you will set authentication checks and authorization roles to properly access and manage your web application.
2727

2828
### Log on to SAP BTP
2929
First, you need to connect to the SAP BTP, Cloud Foundry environment with your productive subaccount. Your Cloud Foundry URL depends on the region where the API endpoint belongs to. To find out which one is yours, see: [Regions and API Endpoints Available for the CF Environment] (https://help.sap.com/products/BTP/65de2977205c403bbc107264b8eccf4b/f344a57233d34199b2123b9620d0bb41.html?version=Cloud)
@@ -49,6 +49,9 @@ In this tutorial, we use `eu20.hana.ondemand.com` as an example.
4949
5050
5151
5. Choose the org name and space where you want to create your application.
52+
53+
> This step is skipped if you're using a trial account.
54+
5255
5356
5457
#### RESULT
@@ -127,7 +130,7 @@ You're going to create a simple Node.js application.
127130
"description": "My simple Node.js app",
128131
"main": "index.js",
129132
"engines": {
130-
"node": "14.x.x"
133+
"node": "16.x.x"
131134
},
132135
"scripts": {
133136
"start": "node start.js"
@@ -140,7 +143,7 @@ You're going to create a simple Node.js application.
140143
}
141144
```
142145
143-
8. Inside the `myapp` folder, create another file called `start.js` with the following content:
146+
8. Inside the `myapp` folder, create a file `start.js` with the following content:
144147
145148
```JavaScript
146149
const express = require('express');
@@ -199,8 +202,7 @@ Authentication in the SAP BTP, Cloud Foundry environment is provided by the Auth
199202
"tenant-mode" : "dedicated",
200203
"oauth2-configuration": {
201204
"redirect-uris": [
202-
"https://node-1234-aaaa-5678.cfapps.eu20.hana.ondemand.com/",
203-
"https://web-1234-aaaa-5678.cfapps.eu20.hana.ondemand.com/"
205+
"https://*.cfapps.eu20.hana.ondemand.com/**"
204206
]
205207
}
206208
}
@@ -380,7 +382,6 @@ Authentication in the SAP BTP, Cloud Foundry environment is provided by the Auth
380382
381383
382384
383-
384385
### Run an Authorization Check
385386
Authorization in the SAP BTP, Cloud Foundry environment is also provided by the XSUAA service. In the previous example, the `@sap/approuter` package was added to provide a central entry point for the business application and to enable authentication. Now to extend the example, authorization will be added through the implementation of a `users` REST service. Different authorization checks will be introduced for the GET and CREATE operations to demonstrate how authorization works. The authorization concept includes elements such as roles, scopes, and attributes provided in the security descriptor file `xs-security.json`. For more information, see: [Application Security Descriptor Configuration Syntax] (https://help.sap.com/docs/BTP/65de2977205c403bbc107264b8eccf4b/517895a9612241259d6941dbf9ad81cb.html?version=Cloud)
386387
@@ -431,7 +432,7 @@ Authorization in the SAP BTP, Cloud Foundry environment is also provided by the
431432
cf update-service nodeuaa -c xs-security.json
432433
```
433434
434-
3. In the `myapp` folder, create a new file called `users.json` with the following content:
435+
3. In the `myapp` folder, create a file `users.json` with the following content:
435436
436437
```JSON
437438
[{

tutorials/btp-cf-buildpacks-python-create/btp-cf-buildpacks-python-create.md

Lines changed: 44 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,35 @@
22
parser: v2
33
author_name: Gergana Tsakova
44
author_profile: https://github.com/Joysie
5+
title: Create a Python Application with Cloud Foundry Python Buildpack
6+
description: Create a simple application and enable services for it, by using the Cloud Foundry Python Buildpack and Cloud Foundry Command Line Interface (cf CLI).
57
auto_validation: true
68
time: 40
79
tags: [ tutorial>beginner, software-product>sap-btp--cloud-foundry-environment, software-product>sap-hana, software-product-function>sap-btp-cockpit]
810
primary_tag: programming-tool>python
911
---
1012

11-
# Create a Python Application via Cloud Foundry Command Line Interface
12-
<!-- description --> Create a simple Python application in the Cloud Foundry Command Line Interface (cf CLI) and enable services for it.
13+
## You will learn
14+
- How to create a simple "Hello World" application in Python
15+
- How to consume an SAP BTP service from it
16+
- How to run authentication and authorization checks via the XSUAA service
1317

1418
## Prerequisites
15-
- You have a productive account for SAP Business Technology Platform (SAP BTP). If you don't have such yet, you can create one so you can [try out services for free] (https://developers.sap.com/tutorials/btp-free-tier-account.html).
19+
- You have a trial or productive account for SAP Business Technology Platform (SAP BTP). If you don't have such yet, you can create one so you can [try out services for free] (https://developers.sap.com/tutorials/btp-free-tier-account.html).
1620
- You have created a subaccount and a space on Cloud Foundry Environment.
17-
- You have created a service instance for [SAP HANA Cloud] (https://help.sap.com/docs/HANA_CLOUD/9ae9104a46f74a6583ce5182e7fb20cb/f7febb16072b41f7ac90abf5ea1d4b86.html) with `hana-free` plan.
18-
- [Python] (https://www.python.org/downloads/) version 3.6.x or higher is installed locally. In this tutorial, we use Python **3.10.1**.
21+
- You have created a service instance for [SAP HANA Cloud] (https://help.sap.com/docs/HANA_CLOUD/9ae9104a46f74a6583ce5182e7fb20cb/f7febb16072b41f7ac90abf5ea1d4b86.html). To learn how to set it up, watch the first half of this video: [SAP HANA Cloud Trial Setup](https://www.youtube.com/watch?v=GSNQpfxPuLU)
22+
- [Python] (https://www.python.org/downloads/) is installed locally. To check which Python versions are supported in the current buildpack, see: [Developing Python in the Cloud Foundry Environment](https://help.sap.com/docs/btp/sap-business-technology-platform/developing-python-in-cloud-foundry-environment#buildpack-versioning). In this tutorial, we use Python **3.11.1**.
1923
- [cf CLI] (https://help.sap.com/products/BTP/65de2977205c403bbc107264b8eccf4b/4ef907afb1254e8286882a2bdef0edf4.html) is installed locally.
2024
- [npm] (https://docs.npmjs.com/downloading-and-installing-node-js-and-npm) is installed locally.
2125
- You have installed an integrated development environment, for example [Visual Studio Code] (https://code.visualstudio.com/).
2226
- You have installed the `virtualenv` tool. It creates a folder, which contains all the necessary executables to use the packages that your Python project would need. To install it locally, execute the following command in the Python installation path:
2327
&nbsp;
24-
`<Python_installation_path>\Python39\Scripts>pip install virtualenv`
25-
28+
`<Python_installation_path>\Python311\Scripts>pip install virtualenv`
2629

2730

2831

29-
## You will learn
30-
- How to create a simple "Hello World" application in Python
31-
- How to consume SAP BTP services from it
32-
- How to run authentication checks for your app
33-
- How to run authorization checks for your app
34-
35-
3632
## Intro
37-
This tutorial will guide you through creating and setting up a simple Python application by using cf CLI. You will start by building and deploying a web application that returns simple data – a **Hello World!** message, and then invoking this app through another one - a web microservice (application router).
33+
This tutorial will guide you through creating and setting up a simple Python application by using cf CLI. You will start by building and deploying a web application that returns simple data – a **Hello World!** message. This simple app will consume an SAP BTP service, and then will be invoked through a web microservice (application router). Finally, you will set authentication checks and authorization roles to properly access and manage your web application.
3834

3935
---
4036

@@ -58,9 +54,15 @@ In this tutorial, we use `eu20.hana.ondemand.com` as an example.
5854
cf login
5955
```
6056
61-
4. When prompted, enter your user credentials – the email and password you have used to register your productive SAP BTP account.
57+
4. When prompted, enter your user credentials – the email and password you have used to register your trial or productive SAP BTP account.
58+
59+
> **IMPORTANT**: If the authentication fails, even though you've entered correct credentials, try [logging in via single sign-on] (https://help.sap.com/products/BTP/65de2977205c403bbc107264b8eccf4b/e1009b4aa486462a8951c4d499ce6d4c.html?version=Cloud).
60+
61+
62+
5. Choose the org name and space where you want to create your application.
63+
64+
> This step is skipped if you're using a trial account.
6265
63-
> **IMPORTANT**: If the authentication fails, even though you've entered correct credentials, try [logging in via single sign-on] (https://help.sap.com/products/BTP/65de2977205c403bbc107264b8eccf4b/e1009b4aa486462a8951c4d499ce6d4c.html?version=Cloud).
6466
6567
6668
#### RESULT
@@ -102,7 +104,7 @@ You're going to create a simple Python application.
102104
4. Specify the Python runtime version that your application will run on. To do that, create a `runtime.txt` file with the following content:
103105
104106
```TXT
105-
python-3.10.1
107+
python-3.11.1
106108
```
107109
108110
5. This application will be a web server utilizing the Flask web framework. To specify Flask as an application dependency, create a `requirements.txt` file with the following content:
@@ -133,7 +135,7 @@ You're going to create a simple Python application.
133135
cf push
134136
```
135137
136-
> Make sure you always execute `cf push` in the folder where the `manifest.yml` file is located! In this case, that's `python-tutorial`.
138+
> Make sure you always execute `cf push` in the directory where the `manifest.yml` file is located! In this case, that's `python-tutorial`.
137139
138140
8. When the staging and deployment steps are completed, the `myapp` application should be successfully started and its details displayed in the command console.
139141
@@ -153,13 +155,7 @@ Your Python application is successfully deployed and running on the SAP BTP, Clo
153155
154156
You have created a service instance for SAP HANA Cloud (see **Prerequisites** at the beginning). Now you're going to make a connection to your SAP HANA database from SAP HANA Schemas & HDI Containers - a service that runs on the SAP BTP, Cloud Foundry environment - and consume this service in your application.
155157
156-
1. Create a `hana` service instance named `pyhana`. As a service plan, you can use `securestore` or `hdi-shared`. They both work for this scenario, so - whichever you prefer (or whichever is available in your subaccount). Execute one of the following commands, respectively:
157-
158-
```Bash/Shell
159-
cf create-service hana securestore pyhana
160-
```
161-
162-
or
158+
1. Create a `hana` service instance named `pyhana` with service plan `hdi-shared`. Execute:
163159
164160
```Bash/Shell
165161
cf create-service hana hdi-shared pyhana
@@ -258,6 +254,21 @@ Authentication in the SAP BTP, Cloud Foundry environment is provided by the Auth
258254
}
259255
```
260256
257+
> **NOTE**: For trial accounts, enter the following additional `oauth2-configuration` lines in your `xs-security.json` file:
258+
259+
260+
```JSON
261+
{
262+
"xsappname" : "myapp",
263+
"tenant-mode" : "dedicated",
264+
"oauth2-configuration": {
265+
"redirect-uris": [
266+
"https://*.cfapps.eu20.hana.ondemand.com/**"
267+
]
268+
}
269+
}
270+
```
271+
261272
2. Create an `xsuaa` service instance named `pyuaa` with plan `application`, by executing the following command:
262273
263274
```Bash
@@ -299,7 +310,7 @@ Authentication in the SAP BTP, Cloud Foundry environment is provided by the Auth
299310
</head>
300311
<body>
301312
<h1>Python Tutorial</h1>
302-
<a href="/myapp/">My Application</a>
313+
<a href="/myapp/">My Python Application</a>
303314
</body>
304315
</html>
305316
```
@@ -312,7 +323,7 @@ Authentication in the SAP BTP, Cloud Foundry environment is provided by the Auth
312323
npm init
313324
```
314325
315-
This will walk you through creating a `package.json` file in the `web` folder. Press **Enter** on every step.
326+
Press **Enter** on every step. This process will walk you through creating a `package.json` file in the `web` folder.
316327
317328
8. Now you need to create a directory `web/node_modules/@sap` and install an `approuter` package in it. To do that, in the `web` directory execute:
318329
@@ -376,7 +387,7 @@ Authentication in the SAP BTP, Cloud Foundry environment is provided by the Auth
376387
377388
> ### What's going on?
378389
379-
>As of this point of the tutorial, the URL of the `web` application will be requested instead of the `myapp` URL. It will then forward the requests to the `myapp` application.
390+
>At this point of the tutorial, the URL of the `web` application will be requested instead of the `myapp` URL. It will then forward the requests to the `myapp` application.
380391
381392
382393
13. When the staging and deployment steps are completed, the `web` application should be successfully started and its details displayed in the command console.
@@ -389,13 +400,12 @@ Authentication in the SAP BTP, Cloud Foundry environment is provided by the Auth
389400
390401
#### RESULT
391402
392-
A simple application page with title **Python Tutorial** is displayed. When you click the `My Application` link, the current SAP HANA time is displayed, in UTC time zone.
393-
403+
- A simple application page with title **Python Tutorial** is displayed. When you click the `My Application` link, the current SAP HANA time is displayed, in UTC time zone.
404+
405+
- If you directly access the `myapp` URL, it displays the same result - the current SAP HANA time in UTC time zone.
394406
395407
396408
### Run an Authorization Check
397-
398-
399409
Authorization in the SAP BTP, Cloud Foundry environment is also provided by the XSUAA service. In the previous example, the `@sap/approuter` package was added to provide a central entry point for the business application and to enable authentication. Now to extend the example, authorization will be added.
400410
401411
1. Add the `sap-xssec` security library to the `requirements.txt` file, to place restrictions on the content you serve. The file should look like this:
@@ -472,9 +482,6 @@ Authorization in the SAP BTP, Cloud Foundry environment is also provided by the
472482
473483
Accessing the `myapp` application results in the following:
474484
475-
- If you try to access it directly, a `403 Forbidden` response is displayed due to lack or permissions (lack of authorization header).
485+
- If you try to access it directly, a `403 Forbidden` response is displayed due to lack of permissions (lack of authorization header). This is a correct and expected behavior.
476486
477487
- If you try to access it through the `web` application router, the current SAP HANA time is displayed (in UTC time zone) – provided that you have the `openid` scope assigned to your user. Since the OAuth 2.0 client is used, the `openid` scope is assigned to your user by default, the correct authorization header is declared, and thus you are allowed to access the `myapp` application.
478-
479-
480-

0 commit comments

Comments
 (0)