Skip to content

Commit

Permalink
SK-1749: Updated samples
Browse files Browse the repository at this point in the history
  • Loading branch information
saileshwar-skyflow committed Nov 19, 2024
1 parent 1a235bb commit e842282
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 36 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/internal-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:
- "*.yml"
- "*.md"
- "skyflow/utils/_version.py"
- "samples/*"
- "samples/**"
branches:
- release/*

Expand Down
5 changes: 3 additions & 2 deletions samples/service_account/scoped_token_generation_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@

# Generate bearer token from credentials file path
options = {
"ctx": "<CONTEXT_ID>"
"role_ids": ["ROLE_ID1", "ROLE_ID2"]
}

if is_expired(bearer_token):
bearer_token, token_type = generate_bearer_token(
"<YOUR_CREDENTIALS_FILE_PATH>", options
Expand All @@ -25,3 +24,5 @@

print(bearer_token, token_type)



Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@

# Generate bearer token from credentials file path
options = {
"role_ids": ["ROLE_ID1", "ROLE_ID2"]
"ctx": "<CONTEXT_ID>"
}

if is_expired(bearer_token):
bearer_token, token_type = generate_bearer_token(
"<YOUR_CREDENTIALS_FILE_PATH>", options
Expand All @@ -22,5 +23,4 @@
if is_expired(bearer_token):
bearer_token, token_type = generate_bearer_token_from_creds(skyflow_credentials_string, options)

print(bearer_token, token_type)

print(bearer_token, token_type)
5 changes: 2 additions & 3 deletions samples/vault_api/delete_records.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,11 @@
]

delete_request = DeleteRequest(
table='TABLE_NAME',
table='<TABLE_NAME>',
ids = primary_delete_ids
)

# will return first Vault ID
response = client.vault().delete(delete_request)
response = client.vault('<VAULT_ID>').delete(delete_request)

print(response)

Expand Down
6 changes: 3 additions & 3 deletions samples/vault_api/detokenize_records.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
# please pass one of api_key, token, credentials_string & path as credentials
credentials = {
"token": "BEARER_TOKEN", # bearer token
# api_key: "API_KEY", //API_KEY
# path: "PATH", //path to credentials file
# credentials_string: skyflow_credentials_string, // credentials as string
# api_key: "API_KEY", #API_KEY
# path: "PATH", #path to credentials file
# credentials_string: skyflow_credentials_string, #credentials as string
}

client = (
Expand Down
41 changes: 23 additions & 18 deletions samples/vault_api/insert_byot.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from skyflow import Env
from skyflow import Skyflow, LogLevel
from skyflow.error import SkyflowError
from skyflow.utils.enums import TokenStrict
from skyflow.vault.data import GetRequest, InsertRequest
from skyflow.vault.tokens import DetokenizeRequest
Expand Down Expand Up @@ -28,23 +29,27 @@
.build()
)

# sample data
insert_data = [
{ "card_number": 'CARD_NUMBER1', "card_cvv": 'CVV1' },
{ "card_number": 'CARD_NUMBER2', "card_cvv": 'CVV2' },
]

insert_request = InsertRequest(
table_name='TABLE_NAME',
values = insert_data,
continue_on_error=False, # if continue on error is set true we will return request_index for errors
token_strict=TokenStrict.ENABLE, # token strict / byot is enabled,
tokens = [
{ "card_number": 'CARD_NUMBER1', "card_cvv": 'CVV1' },
{ "card_number": 'CARD_NUMBER2', "card_cvv": 'CVV2' },
],
)
#Initialize Client

try:
insert_data = [
{"<FIELD_NAME1>": '<VALUE1>'},
{"<FIELD_NAME2>": '<VALUE2>'}
]

token_data = [
{"<FIELD_NAME1>": '<TOKEN1>'},
{"<FIELD_NAME2>": '<TOKEN2>'}
]

response = skyflow_client.vault('VAULT_ID').insert(insert_request)
insert_request = InsertRequest(
table_name='<TABLE_NAME>',
values=insert_data,
token_strict=TokenStrict.ENABLE, # token strict is enabled,
tokens=token_data,
)

print(response)
response = skyflow_client.vault('VAULT_ID').insert(insert_request)
print("Response:", response)
except SkyflowError as e:
print("Error Occurred:", e)
3 changes: 1 addition & 2 deletions samples/vault_api/insert_records.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@

# sample data
insert_data = [
{ "card_number": 'CARD_NUMBER1', "card_cvv": 'CVV1' },
{ "card_number": 'CARD_NUMBER2', "card_cvv": 'CVV2' },
{ "<FIELD>": '<VALUE>', "<FIELD>": '<VALUE>' },
]

insert_request = InsertRequest(
Expand Down
14 changes: 11 additions & 3 deletions samples/vault_api/invoke_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,27 @@
.build()
)


body = {
"KEY1": "VALUE1",
"KEY2": "VALUE2"
}

headers = {
'Content-Type': 'application/json'
"KEY1": "VALUE1"
}
path_params = {
"KEY1": "VALUE1"
}
query_params = {
"KEY1": "VALUE1"
}

invoke_connection_request = InvokeConnectionRequest(
method=Method.POST,
body=body,
request_headers = headers
request_headers = headers, # optional
path_params = path_params, # optional
query_params=query_params # optional
)
# will return the first connection
response = skyflow_client.connection().invoke(invoke_connection_request)
Expand Down
1 change: 1 addition & 0 deletions skyflow/generated/rest/api/tokens_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ def record_service_detokenize(

_response_types_map: Dict[str, Optional[str]] = {
'200': "V1DetokenizeResponse",
'207': "V1DetokenizeResponse",
'404': "object",
}
response_data = self.api_client.call_api(
Expand Down
2 changes: 1 addition & 1 deletion skyflow/vault/data/_get_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class GetRequest:
def __init__(self,
table,
ids = None,
redaction_type = "plain-text",
redaction_type = None,
return_tokens = False,
fields = None,
offset = None,
Expand Down

0 comments on commit e842282

Please sign in to comment.