From e51971b46f579d185fc7c512e580c057cabf5114 Mon Sep 17 00:00:00 2001 From: skyflow-puneet Date: Thu, 27 Oct 2022 10:10:50 +0530 Subject: [PATCH] [SDK-713] Update missing feature --- README.md | 44 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 41 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 98f9505..534d8a9 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ -# Description +# Skyflow-python --- - +## Description This Python SDK is designed to help developers easily implement Skyflow into their python backend. @@ -50,7 +50,7 @@ The [Service Account](https://github.com/skyflowapi/skyflow-python/tree/main/sky The `generate_bearer_token(filepath)` function takes the credentials file path for token generation, alternatively, you can also send the entire credentials as string, by using `generate_bearer_token_from_creds(credentials)` -[Example](https://github.com/skyflowapi/skyflow-python/blob/main/samples/sa_token_sample.py): +[Example using filepath](https://github.com/skyflowapi/skyflow-python/blob/main/samples/sa_token_sample.py): ```python from skyflow.errors import SkyflowError @@ -76,6 +76,42 @@ except SkyflowError as e: ``` +[Example using credentials string](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(): + global bearerToken + global tokenType + # As an example + credentials = { + "clientID": "", + "clientName": "", + "keyID": "", + "tokenURI": '', + "privateKey": "" + } + jsonString = json.dumps(credentials) + if is_expired(bearerToken): + bearerToken, tokenType = generate_bearer_token_from_creds( + credentials=jsonString) + + return bearerToken + +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. @@ -91,6 +127,7 @@ bearerToken = '' # User defined function to provide access token to the vault apis def token_provider(): + global bearerToken if is_expired(bearerToken): return bearerToken bearerToken, _ = generate_bearer_token('') @@ -342,6 +379,7 @@ from skyflow.vault import ConnectionConfig, Configuration, RequestMethod bearerToken = '' def token_provider(): + global bearerToken if is_expired(bearerToken): return bearerToken bearerToken, _ = generate_bearer_token('')