Skip to content

Commit 4b66dee

Browse files
Merge pull request #25 from sightmachine/DATA-868
Data 868
2 parents 655f8f2 + a0f443a commit 4b66dee

7 files changed

Lines changed: 47 additions & 9 deletions

File tree

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,15 @@ Similarly, if you need to use your own CA Certificates, set the CURL_CA_BUNDLE e
8181
CURL_CA_BUNDLE="/path/to/my/certificates"
8282
```
8383

84+
### Selecting database schema
85+
By default, the production pipeline schema will be considered to retrive data from the tenant.
86+
To select a particular development pipeline schema you can use following function call:
87+
88+
```
89+
db_schema = pipeline_id
90+
cli.select_db_schema(schema_name=db_schema)
91+
```
92+
8493
### Retrieving Data
8594

8695
The typical workflow for getting data from Sight Machine is:

examples/Query Examples.ipynb

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,28 @@
5050
"columns = cli.get_machine_schema(machines[0])['display'].to_list()"
5151
]
5252
},
53+
{
54+
"attachments": {},
55+
"cell_type": "markdown",
56+
"metadata": {},
57+
"source": [
58+
"### Selecting a Particular Development Pipeline schema\n",
59+
"\n",
60+
"You can select development pipeline schema using following code example:\n",
61+
"\n",
62+
"Note:- By default, the production pipeline schema will be considered to retrive data from the tenant"
63+
]
64+
},
65+
{
66+
"cell_type": "code",
67+
"execution_count": null,
68+
"metadata": {},
69+
"outputs": [],
70+
"source": [
71+
"db_schema = 'pipeline_id' \n",
72+
"cli.select_db_schema(schema_name=db_schema)"
73+
]
74+
},
5375
{
5476
"cell_type": "markdown",
5577
"metadata": {},
@@ -2069,11 +2091,9 @@
20692091
}
20702092
],
20712093
"metadata": {
2072-
"interpreter": {
2073-
"hash": "767d51c1340bd893661ea55ea3124f6de3c7a262a8b4abca0554b478b1e2ff90"
2074-
},
20752094
"kernelspec": {
2076-
"display_name": "Python 3.7.5 64-bit ('usr')",
2095+
"display_name": "Python 3",
2096+
"language": "python",
20772097
"name": "python3"
20782098
},
20792099
"language_info": {
@@ -2086,9 +2106,14 @@
20862106
"name": "python",
20872107
"nbconvert_exporter": "python",
20882108
"pygments_lexer": "ipython3",
2089-
"version": "3.7.5"
2109+
"version": "3.10.9"
20902110
},
2091-
"orig_nbformat": 2
2111+
"orig_nbformat": 2,
2112+
"vscode": {
2113+
"interpreter": {
2114+
"hash": "b0fa6594d8f4cbf19f97940f81e996739fb7646882a419484c72d19e05852a7e"
2115+
}
2116+
}
20922117
},
20932118
"nbformat": 4,
20942119
"nbformat_minor": 2

smsdk/Auth/auth.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
SM_AUTH_HEADER_SECRET_ID = RESOURCE_CONFIG["auth_header-api-secret"]
2323
SM_AUTH_HEADER_SECRET_ID_OLD = RESOURCE_CONFIG["auth_header-api-secret_old"]
2424
SM_AUTH_HEADER_KEY_ID = RESOURCE_CONFIG["auth_header-api-key"]
25-
25+
X_SM_DB_SCHEMA = RESOURCE_CONFIG["x_sm_db_schema"]
2626

2727
class Authenticator(MaSession):
2828
"""

smsdk/client.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from pandas.io.json import json_normalize
1313

1414
from smsdk.utils import get_url
15-
from smsdk.Auth.auth import Authenticator
15+
from smsdk.Auth.auth import Authenticator, X_SM_DB_SCHEMA
1616
from smsdk.tool_register import smsdkentities
1717
from smsdk.client_v0 import ClientV0
1818

@@ -115,6 +115,9 @@ def __init__(self, tenant, site_domain="sightmachine.io", protocol = "https"):
115115
# Setup Authenticator
116116
self.auth = Authenticator(self)
117117
self.session = self.auth.session
118+
119+
def select_db_schema(self, schema_name):
120+
self.session.headers.update({X_SM_DB_SCHEMA:schema_name})
118121

119122
def get_data_v1(self, ename, util_name, normalize=True, *args, **kwargs):
120123
"""

smsdk/client_v0.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -699,7 +699,6 @@ def get_machine_type_names(self, clean_strings_out=True):
699699
query_params = {'_only': ['source_type', 'source_type_clean'],
700700
'_order_by': 'source_type_clean'}
701701
machine_types = self.get_data('machine_type', 'get_machine_types', normalize=True, **query_params)
702-
703702
if clean_strings_out:
704703
return machine_types['source_type_clean'].to_list()
705704
else:

smsdk/config/message_config.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"auth_header-api-secret": "X-SM-API-Secret",
33
"auth_header-api-secret_old": "X-SM-API-Key",
44
"auth_header-api-key": "X-SM-API-Key-Id",
5+
"x_sm_db_schema":"x-sm-db-schema",
56
"keywords": {
67
"KEYWORD_MISSING_ACCOUNT": "No such account",
78
"KEYWORD_INCORRECT_PASSWORD": "password does not match",

smsdk/ma_session.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
SM_AUTH_HEADER_SECRET_ID = RESOURCE_CONFIG["auth_header-api-secret"]
2222
SM_AUTH_HEADER_SECRET_ID_OLD = RESOURCE_CONFIG["auth_header-api-secret_old"]
2323
SM_AUTH_HEADER_KEY_ID = RESOURCE_CONFIG["auth_header-api-key"]
24+
X_SM_DB_SCHEMA = RESOURCE_CONFIG['x_sm_db_schema']
2425

2526
import logging
2627
log = logging.getLogger(__name__)

0 commit comments

Comments
 (0)