From e54c2a50cd7ece159c9885f4ccd74cbc98fb917a Mon Sep 17 00:00:00 2001 From: skyflow-puneet Date: Tue, 18 Oct 2022 14:07:33 +0530 Subject: [PATCH 1/4] [SDK-750] Update sample readme --- README.md | 24 +++++++++++ samples/README.md | 100 +++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 114 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 72d8abd..63ba211 100644 --- a/README.md +++ b/README.md @@ -76,6 +76,30 @@ except SkyflowError as e: ``` +[Example](https://github.com/skyflowapi/skyflow-python/blob/main/samples/generate_bearer_token_from_creds_sample.py): + +```python +from skyflow.errors import SkyflowError +from skyflow.service_account import generate_bearer_token_from_creds, is_expired + +# cache token for reuse +bearerToken = '' +tokenType = '' +def token_provider(): + if is_expired(bearerToken): + bearerToken, tokenType = generate_bearer_token_from_creds('') + return bearerToken, tokenType + +try: + accessToken, tokenType = token_provider() + print("Access Token:", accessToken) + print("Type of token:", tokenType) +except SkyflowError as e: + print(e) + +``` + + ## Vault APIs The [Vault](https://github.com/skyflowapi/skyflow-python/tree/main/skyflow/vault) python module is used to perform operations on the vault such as inserting records, detokenizing tokens, retrieving tokens for a skyflow_id and to invoke a connection. diff --git a/samples/README.md b/samples/README.md index d7f8ca3..459f2e5 100644 --- a/samples/README.md +++ b/samples/README.md @@ -1,13 +1,93 @@ -## Description -These are the samples for skyflow-python. In order to use these samples, you must first: +# PYTHON-SDK sample templates +Use this folder to test the functionalities of PYTHON-SDK just by adding `VAULT-ID` `VAULT-URL` and `SERVICE-ACCOUNT` details at the required place. -1. Install skyflow module using pip -2. Replace placeholders like ``, `` etc. in the sample file with your Vault ID, Vault URL etc. +## Prerequisites +- A Skylow account. If you don't have one, you can register for one on the [Try Skyflow](https://skyflow.com/try-skyflow) page. +- Python 3.7.0 and above. -Below is a brief description of the samples: +## Configure +- Before you can run the sample app, create a vault +- The package can be installed using pip: -- [SATokenSample.py](https://github.com/skyflowapi/skyflow-python/blob/main/samples/SATokenSample.py): Contains a python program illustrating the usage of `service_account.generate_bearer_token()` -- [InsertSample.py](https://github.com/skyflowapi/skyflow-python/blob/main/samples/InsertSample.py) : Contains a python program illustrating the use of `vault.Client.insert()` -- [detokenizeSample.py](https://github.com/skyflowapi/skyflow-python/blob/main/samples/detokenizeSample.py): Contains a python program illustrating the use of `vault.detokenize()` -- [`getByIDSample.py`](https://github.com/skyflowapi/skyflow-python/blob/main/samples/getByIDSample.py): Contains a python program illustrating the use of `vault.Client.get_by_id()` -- [`invoke_connection.py`](https://github.com/skyflowapi/skyflow-python/blob/main/samples/invoke_connectionSample.py): Contains a python program illustrating the use of `vault.Client.invoke_connection()` \ No newline at end of file + pip install skyflow + +### Create the vault +1. In a browser, navigate to Skyflow Studio and log in. +2. Create a vault by clicking **Create Vault** > **Start With a Template** > **Quickstart vault**. +3. Once the vault is created, click the gear icon and select **Edit Vault** Details. +4. Note your Vault URL and Vault ID values, then click Cancel. You'll need these later. + +### Create a service account +1. In the side navigation click, **IAM** > **Service Accounts** > **New Service Account**. +2. For Name, enter **Test-Python-Sdk-Sample**. For Roles, choose the required roles for specific action. +3. Click **Create**. Your browser downloads a **credentials.json** file. Keep this file secure, as you'll need it in the next steps. + +### Different types of functionalities of Java-Sdk +- [**Detokenize**](detokenize_sample.py) + - Detokenize the data token from the vault. + - Make sure the token is of the data which exists in the Vault. If not so please make use of [insert_sample.py](insert_sample.py) to insert the data in the data and use this token for detokenization. + - Configure + - Replace **** with **VAULT ID** + - Replace **** with **VAULT URL**. + - Replace **** with **COLUMN NAME**. + - Replace **** with **Data Token**. + - Replace **** with relative path of **SERVICE ACCOUNT CREDENTIAL FILE**. + - Execution + + python3 detokenize_smaple.py +- [**GetById**](get_by_ids_sample.py) + - Get data using skyflow id. + - Configure + - Replace **** with **VAULT ID** + - Replace **** with **VAULT URL**. + - Replace **** with **Skyflow Id 1**. + - Replace **** with **Skyflow Id 2**. + - Replace **** with **Skyflow Id 3**. + - Replace **** with relative path of **SERVICE ACCOUNT CREDENTIAL FILE**. + - Replace **** with **credit_cards**. + - Execution + + python3 get_by_ids_sample.py +- [**Insert**](insert_sample.py) + - Insert data in the vault. + - Configure + - Replace **** with **VAULT ID**. + - Replace **** with **VAULT URL**. + - Replace **** with relative path of **SERVICE ACCOUNT CREDENTIAL FILE**. + - Replace **** with **credit_cards**. + - Replace **** with **column name**. + - Replace **** with **valid value corresponding to column name**. + - Execution + + python3 insert_sample.py +- [**InvokeConnection**](invoke_connection_sample.py) + - Invoke connection + - Configure + - Replace **** with **VAULT ID**. + - Replace **** with **VAULT URL**. + - Replace **** with relative path of **SERVICE ACCOUNT CREDENTIAL FILE**. + - Replace **** with **Connection url**. + - Replace **** with **access token**. + - Replace value of **requestBody** with your's request body content. + - Replace value of **pathParams** with your's path params content. + + - Execution + + python3 invoke_connection_sample.py +- [**Service account token generation**](sa_token_Sample.py) + - generates SA Token using path of credentials file. + - Configure + - Replace **** with relative path of **SERVICE ACCOUNT CREDENTIAL FILE**. + + - Execution + + python3 sa_token_sample.py + +- [**Generate Bearer Token From Credentails**](generate_bearer_token_from_creds_sample.py) + - generates SA Token using json content of credentials file. + - Configure + - Replace **credentials*** with json data of downloaded credentials file while creation Service account. + + - Execution + + python3 generate_bearer_token_from_creds_sample.py \ No newline at end of file From 48b7d9fbbac6c1e9ba17112721d09af281ca9f78 Mon Sep 17 00:00:00 2001 From: skyflow-puneet Date: Fri, 21 Oct 2022 14:41:55 +0530 Subject: [PATCH 2/4] [SDK-750] Update sample readme typo Signed-off-by: skyflow-puneet --- samples/README.md | 152 +++++++++++++++++++++++----------------------- 1 file changed, 76 insertions(+), 76 deletions(-) diff --git a/samples/README.md b/samples/README.md index 459f2e5..c9b0eb7 100644 --- a/samples/README.md +++ b/samples/README.md @@ -1,93 +1,93 @@ -# PYTHON-SDK sample templates -Use this folder to test the functionalities of PYTHON-SDK just by adding `VAULT-ID` `VAULT-URL` and `SERVICE-ACCOUNT` details at the required place. +# Python SDK samples +Test the SDK by adding `VAULT-ID`, `VAULT-URL`, and `SERVICE-ACCOUNT` details in the required places for each sample. ## Prerequisites -- A Skylow account. If you don't have one, you can register for one on the [Try Skyflow](https://skyflow.com/try-skyflow) page. -- Python 3.7.0 and above. +- A Skyflow account. If you don't have one, register for one on the [Try Skyflow](https://skyflow.com/try-skyflow) page. +- Python 3.7.0 or higher. -## Configure -- Before you can run the sample app, create a vault -- The package can be installed using pip: +## Prepare +- Install the Python SDK: pip install skyflow ### Create the vault -1. In a browser, navigate to Skyflow Studio and log in. +1. In a browser, sign in to Skyflow Studio. 2. Create a vault by clicking **Create Vault** > **Start With a Template** > **Quickstart vault**. -3. Once the vault is created, click the gear icon and select **Edit Vault** Details. -4. Note your Vault URL and Vault ID values, then click Cancel. You'll need these later. +3. Once the vault is ready, click the gear icon and select **Edit Vault Details**. +4. Note your **Vault URL** and **Vault ID** values, then click **Cancel**. You'll need these later. ### Create a service account 1. In the side navigation click, **IAM** > **Service Accounts** > **New Service Account**. -2. For Name, enter **Test-Python-Sdk-Sample**. For Roles, choose the required roles for specific action. -3. Click **Create**. Your browser downloads a **credentials.json** file. Keep this file secure, as you'll need it in the next steps. +2. For **Name**, enter "SDK Sample". For **Roles**, choose **Vault Editor**. +3. Click **Create**. Your browser downloads a **credentials.json** file. Keep this file secure, as You'll need it for each of the samples. -### Different types of functionalities of Java-Sdk -- [**Detokenize**](detokenize_sample.py) - - Detokenize the data token from the vault. - - Make sure the token is of the data which exists in the Vault. If not so please make use of [insert_sample.py](insert_sample.py) to insert the data in the data and use this token for detokenization. - - Configure - - Replace **** with **VAULT ID** - - Replace **** with **VAULT URL**. - - Replace **** with **COLUMN NAME**. - - Replace **** with **Data Token**. - - Replace **** with relative path of **SERVICE ACCOUNT CREDENTIAL FILE**. - - Execution - - python3 detokenize_smaple.py -- [**GetById**](get_by_ids_sample.py) - - Get data using skyflow id. - - Configure - - Replace **** with **VAULT ID** - - Replace **** with **VAULT URL**. - - Replace **** with **Skyflow Id 1**. - - Replace **** with **Skyflow Id 2**. - - Replace **** with **Skyflow Id 3**. - - Replace **** with relative path of **SERVICE ACCOUNT CREDENTIAL FILE**. - - Replace **** with **credit_cards**. - - Execution - - python3 get_by_ids_sample.py -- [**Insert**](insert_sample.py) - - Insert data in the vault. - - Configure - - Replace **** with **VAULT ID**. - - Replace **** with **VAULT URL**. - - Replace **** with relative path of **SERVICE ACCOUNT CREDENTIAL FILE**. - - Replace **** with **credit_cards**. - - Replace **** with **column name**. - - Replace **** with **valid value corresponding to column name**. - - Execution - - python3 insert_sample.py -- [**InvokeConnection**](invoke_connection_sample.py) - - Invoke connection - - Configure - - Replace **** with **VAULT ID**. - - Replace **** with **VAULT URL**. - - Replace **** with relative path of **SERVICE ACCOUNT CREDENTIAL FILE**. - - Replace **** with **Connection url**. - - Replace **** with **access token**. - - Replace value of **requestBody** with your's request body content. - - Replace value of **pathParams** with your's path params content. +## The samples +### Detokenize +Detokenize a data token from the vault. Make sure the specified token is for data that exists in the vault. If you need a valid token, use [insert_sample.py](insert_sample.py) to insert the data, then use this data's token for detokenization. +#### Configure +1. Replace **** with **VAULT ID** +2. Replace **** with **VAULT URL**. +3. Replace **** with **COLUMN NAME**. +4. Replace **** with **Data Token**. +5. Replace **** with relative path of **SERVICE ACCOUNT CREDENTIAL FILE**. +#### Run the sample - - Execution - - python3 invoke_connection_sample.py -- [**Service account token generation**](sa_token_Sample.py) - - generates SA Token using path of credentials file. - - Configure - - Replace **** with relative path of **SERVICE ACCOUNT CREDENTIAL FILE**. + python3 detokenize_sample.py - - Execution +### GetById +Get data using skyflow id. +#### Configure +1. Replace **** with **VAULT ID** +2. Replace **** with **VAULT URL**. +3. Replace **** with **Skyflow Id 1**. +4. Replace **** with **Skyflow Id 2**. +5. Replace **** with **Skyflow Id 3**. +6. Replace **** with relative path of **SERVICE ACCOUNT CREDENTIAL FILE**. +7. Replace **** with **credit_cards**. + #### Run the sample - python3 sa_token_sample.py + python3 get_by_ids_sample.py -- [**Generate Bearer Token From Credentails**](generate_bearer_token_from_creds_sample.py) - - generates SA Token using json content of credentials file. - - Configure - - Replace **credentials*** with json data of downloaded credentials file while creation Service account. +### Insert +Insert data in the vault. +#### Configure +1. Replace **** with **VAULT ID**. +2. Replace **** with **VAULT URL**. +3. Replace **** with relative path of **SERVICE ACCOUNT CREDENTIAL FILE**. +4. Replace **** with **credit_cards**. +5. Replace **** with **column name**. +6. Replace **** with **valid value corresponding to column name**. +#### Run the sample + + python3 insert_sample.py +### InvokeConnection +Skyflow Connections is a gateway service that uses Skyflow's underlying tokenization capabilities to securely connect to first-party and third-party services. This way, your infrastructure is never directly exposed to sensitive data, and you offload security and compliance requirements to Skyflow. +#### Configure +1. Replace **** with **VAULT ID**. +2. Replace **** with **VAULT URL**. +3. Replace **** with relative path of **SERVICE ACCOUNT CREDENTIAL FILE**. +4. Replace **** with **Connection url**. +5. Replace **** with **access token**. +6. Replace value of **requestBody** with your's request body content. +7. Replace value of **pathParams** with your's path params content. +#### Run the sample + + python3 invoke_connection_sample.py + +### Service account token generation +Generates SA Token using path of credentials file. +#### Configure +1. Replace **** with relative path of **SERVICE ACCOUNT CREDENTIAL FILE**. - - Execution - - python3 generate_bearer_token_from_creds_sample.py \ No newline at end of file +#### Run the sample + + python3 sa_token_sample.py + +### Generate Bearer Token From Credentails +Generates SA Token using json content of credentials file. +#### Configure +1. Replace **credentials** with json data of downloaded credentials file while creation Service account. + +#### Run the sample + + python3 generate_bearer_token_from_creds_sample.py \ No newline at end of file From 8e0ad13570242691866aba5ed4bbe801db9fd4aa Mon Sep 17 00:00:00 2001 From: skyflow-puneet Date: Fri, 21 Oct 2022 17:29:01 +0530 Subject: [PATCH 3/4] [SDK-750] Fix typo Signed-off-by: skyflow-puneet --- samples/README.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/samples/README.md b/samples/README.md index c9b0eb7..da601c2 100644 --- a/samples/README.md +++ b/samples/README.md @@ -32,7 +32,7 @@ Detokenize a data token from the vault. Make sure the specified token is for dat 5. Replace **** with relative path of **SERVICE ACCOUNT CREDENTIAL FILE**. #### Run the sample - python3 detokenize_sample.py + python3 detokenize_sample.py ### GetById Get data using skyflow id. @@ -46,7 +46,7 @@ Get data using skyflow id. 7. Replace **** with **credit_cards**. #### Run the sample - python3 get_by_ids_sample.py + python3 get_by_ids_sample.py ### Insert Insert data in the vault. @@ -59,7 +59,7 @@ Insert data in the vault. 6. Replace **** with **valid value corresponding to column name**. #### Run the sample - python3 insert_sample.py + python3 insert_sample.py ### InvokeConnection Skyflow Connections is a gateway service that uses Skyflow's underlying tokenization capabilities to securely connect to first-party and third-party services. This way, your infrastructure is never directly exposed to sensitive data, and you offload security and compliance requirements to Skyflow. #### Configure @@ -72,7 +72,7 @@ Skyflow Connections is a gateway service that uses Skyflow's underlying tokeniza 7. Replace value of **pathParams** with your's path params content. #### Run the sample - python3 invoke_connection_sample.py + python3 invoke_connection_sample.py ### Service account token generation Generates SA Token using path of credentials file. @@ -81,7 +81,7 @@ Generates SA Token using path of credentials file. #### Run the sample - python3 sa_token_sample.py + python3 sa_token_sample.py ### Generate Bearer Token From Credentails Generates SA Token using json content of credentials file. @@ -90,4 +90,4 @@ Generates SA Token using json content of credentials file. #### Run the sample - python3 generate_bearer_token_from_creds_sample.py \ No newline at end of file + python3 generate_bearer_token_from_creds_sample.py \ No newline at end of file From 2e304c7578b9364c4ec5f3cbc733732b8618defa Mon Sep 17 00:00:00 2001 From: Manny Silva Date: Thu, 27 Oct 2022 10:47:35 -0700 Subject: [PATCH 4/4] SDK-750 Reformatted/edited the sample app readme --- samples/README.md | 186 +++++++++++++++++++++++++++++++--------------- 1 file changed, 128 insertions(+), 58 deletions(-) diff --git a/samples/README.md b/samples/README.md index da601c2..086f467 100644 --- a/samples/README.md +++ b/samples/README.md @@ -1,93 +1,163 @@ # Python SDK samples -Test the SDK by adding `VAULT-ID`, `VAULT-URL`, and `SERVICE-ACCOUNT` details in the required places for each sample. + +Test the SDK by adding `VAULT-ID`, `VAULT-URL`, and `SERVICE-ACCOUNT` details in +the required places for each sample. ## Prerequisites -- A Skyflow account. If you don't have one, register for one on the [Try Skyflow](https://skyflow.com/try-skyflow) page. + +- A Skyflow account. If you don't have one, register for one on the + [Try Skyflow](https://skyflow.com/try-skyflow) page. - Python 3.7.0 or higher. ## Prepare -- Install the Python SDK: - pip install skyflow +### Install the Python SDK + +```bash +pip install skyflow +``` ### Create the vault + 1. In a browser, sign in to Skyflow Studio. -2. Create a vault by clicking **Create Vault** > **Start With a Template** > **Quickstart vault**. +2. Create a vault by clicking **Create Vault** > **Start With a Template** > + **Quickstart vault**. 3. Once the vault is ready, click the gear icon and select **Edit Vault Details**. -4. Note your **Vault URL** and **Vault ID** values, then click **Cancel**. You'll need these later. +4. Note your **Vault URL** and **Vault ID** values, then click **Cancel**. + You'll need these later. ### Create a service account + 1. In the side navigation click, **IAM** > **Service Accounts** > **New Service Account**. 2. For **Name**, enter "SDK Sample". For **Roles**, choose **Vault Editor**. -3. Click **Create**. Your browser downloads a **credentials.json** file. Keep this file secure, as You'll need it for each of the samples. +3. Click **Create**. Your browser downloads a **credentials.json** file. Keep + this file secure, as You'll need it for each of the samples. ## The samples -### Detokenize -Detokenize a data token from the vault. Make sure the specified token is for data that exists in the vault. If you need a valid token, use [insert_sample.py](insert_sample.py) to insert the data, then use this data's token for detokenization. + +### [Get data by ID](./getByIDSample.py) + +Get data using Skyflow IDs for the desired records. + #### Configure -1. Replace **** with **VAULT ID** -2. Replace **** with **VAULT URL**. -3. Replace **** with **COLUMN NAME**. -4. Replace **** with **Data Token**. -5. Replace **** with relative path of **SERVICE ACCOUNT CREDENTIAL FILE**. + +Replace the following values in the sample file: + +| Value | Description | +| ------------------------------ | ------------------------------------------------------- | +| `` | ID of your vault. | +| `` | URL of your vault. | +| `` | Skyflow ID of the first record. | +| `` | Skyflow ID of the second record. | +| `` | Skyflow ID of the third record. | +| `` | relative path to your service account credentials file. | +| `` | Name of the table to get data from. | + #### Run the sample - python3 detokenize_sample.py +```bash +python3 getByIDSample.py +``` + +### [Insert data](./InsertSample.py) -### GetById -Get data using skyflow id. -#### Configure -1. Replace **** with **VAULT ID** -2. Replace **** with **VAULT URL**. -3. Replace **** with **Skyflow Id 1**. -4. Replace **** with **Skyflow Id 2**. -5. Replace **** with **Skyflow Id 3**. -6. Replace **** with relative path of **SERVICE ACCOUNT CREDENTIAL FILE**. -7. Replace **** with **credit_cards**. - #### Run the sample - - python3 get_by_ids_sample.py - -### Insert Insert data in the vault. + #### Configure -1. Replace **** with **VAULT ID**. -2. Replace **** with **VAULT URL**. -3. Replace **** with relative path of **SERVICE ACCOUNT CREDENTIAL FILE**. -4. Replace **** with **credit_cards**. -5. Replace **** with **column name**. -6. Replace **** with **valid value corresponding to column name**. + +Replace the following values in the sample file: + +| Value | Description | +| ------------------------------ | ------------------------------------------------------- | +| `` | ID of your vault. | +| `` | URL of your vault. | +| `` | relative path to your service account credentials file. | +| `` | Name of the table to insert data into. | +| `` | Name of the column to insert data into. | +| `` | Valid value to insert into the corresponding column. | + #### Run the sample - - python3 insert_sample.py -### InvokeConnection -Skyflow Connections is a gateway service that uses Skyflow's underlying tokenization capabilities to securely connect to first-party and third-party services. This way, your infrastructure is never directly exposed to sensitive data, and you offload security and compliance requirements to Skyflow. + +```bash +python3 InsertSample.py +``` + +### [Detokenize data](./detokenizeSample.py) + +Detokenize a data token from the vault. Make sure the specified token is for +data that exists in the vault. If you need a valid token, use +[insert_sample.py](insert_sample.py) to insert the data, then use this data's +token for detokenization. + #### Configure -1. Replace **** with **VAULT ID**. -2. Replace **** with **VAULT URL**. -3. Replace **** with relative path of **SERVICE ACCOUNT CREDENTIAL FILE**. -4. Replace **** with **Connection url**. -5. Replace **** with **access token**. -6. Replace value of **requestBody** with your's request body content. -7. Replace value of **pathParams** with your's path params content. + +Replace the following values in the sample file: + +| Value | Description | +| ------------------------------ | ------------------------------------------------------- | +| `` | ID of your vault. | +| `` | URL of your vault. | +| `` | relative path to your service account credentials file. | +| `` | Name of the column to insert data into. | +| `` | Token for the data you want to detokenize. | + +#### Run the sample + +```bash +python3 detokenizeSample.py +``` + +### [Invoke a connection](./invokeConnectionSample.py) + +Skyflow Connections is a gateway service that uses Skyflow's underlying +tokenization capabilities to securely connect to first-party and third-party +services. This way, your infrastructure is never directly exposed to sensitive +data, and you offload security and compliance requirements to Skyflow. + +#### Configure + +Replace the following values in the sample file: + +| Value | Description | +| ------------------------------ | ------------------------------------------------------- | +| `` | ID of your vault. | +| `` | URL of your vault. | +| `` | relative path to your service account credentials file. | +| `` | URL of your connection. | +| `` | Access token for your connection. | +| `requestBody` | Your request body content. | +| `pathParams` | Your path parameters. | + #### Run the sample - - python3 invoke_connection_sample.py - -### Service account token generation + +```bash +python3 invokeConnectionSample.py +``` + +### [Service account token generation](./SATokenSample.py) + Generates SA Token using path of credentials file. + #### Configure -1. Replace **** with relative path of **SERVICE ACCOUNT CREDENTIAL FILE**. + +Replace `` with the relative path to your service account credentials file. #### Run the sample - - python3 sa_token_sample.py -### Generate Bearer Token From Credentails +```bash +python3 SATokenSample.py +``` + +### [Generate Bearer Token](./generateBearerTokenFromCredsSample.py) + Generates SA Token using json content of credentials file. + #### Configure -1. Replace **credentials** with json data of downloaded credentials file while creation Service account. + +Replace `credentials` with the content of service account credentials file. #### Run the sample - - python3 generate_bearer_token_from_creds_sample.py \ No newline at end of file + +```bash +python3 generateBearerTokenFromCredsSample.py +```