-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #87 from skyflowapi/SK-865-development-delete-by-s…
…kyflow-id-in-python-sdk SK-865 development delete by skyflow id in python sdk
- Loading branch information
Showing
7 changed files
with
398 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
''' | ||
Copyright (c) 2022 Skyflow, Inc. | ||
''' | ||
from skyflow.errors import SkyflowError | ||
from skyflow.service_account import generate_bearer_token, is_expired | ||
from skyflow.vault import Client, Configuration,DeleteOptions | ||
|
||
|
||
# cache token for reuse | ||
bearerToken = '' | ||
|
||
|
||
def token_provider(): | ||
global bearerToken | ||
if is_expired(bearerToken): | ||
bearerToken, _ = generate_bearer_token('<YOUR_CREDENTIALS_FILE_PATH>') | ||
return bearerToken | ||
|
||
|
||
try: | ||
config = Configuration( | ||
'<YOUR_VAULT_ID>', '<YOUR_VAULT_URL>', token_provider) | ||
client = Client(config) | ||
options = DeleteOptions(False) | ||
|
||
data = {"records": [ | ||
{ | ||
"id": "<SKYFLOW_ID1>", | ||
"table": "<TABLE_NAME>", | ||
}, | ||
{ | ||
"id": "<SKYFLOW_ID2>", | ||
"table": "<TABLE_NAME>", | ||
} | ||
]} | ||
|
||
response = client.delete_by_id(data,options=options) | ||
print('Response:', response) | ||
except SkyflowError as e: | ||
print('Error Occurred:', e) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
''' | ||
Copyright (c) 2022 Skyflow, Inc. | ||
''' | ||
import json | ||
|
||
import requests | ||
from requests.models import HTTPError | ||
from skyflow.errors._skyflow_errors import SkyflowError, SkyflowErrorCodes, SkyflowErrorMessages | ||
from skyflow._utils import InterfaceName | ||
|
||
interface = InterfaceName.DELETE_BY_ID.value | ||
|
||
|
||
def deleteProcessResponse(response: requests.Response, interface=interface): | ||
statusCode = response.status_code | ||
content = response.content | ||
try: | ||
response.raise_for_status() | ||
if statusCode == 204: | ||
return None | ||
try: | ||
return json.loads(content) | ||
except: | ||
raise SkyflowError( | ||
statusCode, SkyflowErrorMessages.RESPONSE_NOT_JSON.value % content, interface=interface) | ||
except HTTPError: | ||
message = SkyflowErrorMessages.API_ERROR.value % statusCode | ||
if response is not None and response.content is not None: | ||
try: | ||
errorResponse = json.loads(content) | ||
if 'error' in errorResponse and type(errorResponse['error']) == dict and 'message' in errorResponse[ | ||
'error']: | ||
message = errorResponse['error']['message'] | ||
except: | ||
message = SkyflowErrorMessages.RESPONSE_NOT_JSON.value % content | ||
error = {} | ||
if 'x-request-id' in response.headers: | ||
message += ' - request id: ' + response.headers['x-request-id'] | ||
error.update({"code": statusCode, "description": message}) | ||
return error | ||
|
Oops, something went wrong.