Skip to content

Commit 6628974

Browse files
committed
updated readme
1 parent ed7dd81 commit 6628974

File tree

1 file changed

+53
-14
lines changed

1 file changed

+53
-14
lines changed

README.MD

Lines changed: 53 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22
[![PyPI version](https://badge.fury.io/py/cloudshell-sandboxapi-wrapper.svg)](https://badge.fury.io/py/cloudshell-sandboxapi-wrapper)
33

44
# Cloudshell Sandbox Rest Api Client
5-
A python client wrapper around the [cloudshell sandbox api](https://help.quali.com/Online%20Help/0.0/Portal/Content/API/CS-Snbx-API-Topic.htm?Highlight=sandbox%20api).
6-
This client provides an object-oriented interface to instantiating an api session and interacting with the endpoints.
75

8-
No additional library object wrapping implemented. All methods return the json.loads python object in the shape of the documented json response. See the [documentation](https://help.quali.com/Online%20Help/0.0/Portal/Content/API/RefGuides/Sndbx-REST-API/REST-API-V2-Ref-Guide.htm?tocpath=CloudShell%20API%20Guide%7CCloudShell%20Sandbox%20API%7C_____3)
9-
for details.
6+
A python client wrapper around
7+
the [cloudshell sandbox api](https://help.quali.com/Online%20Help/0.0/Portal/Content/API/CS-Snbx-API-Topic.htm?Highlight=sandbox%20api)
8+
. No additional library object wrapping implemented. All methods return the json.loads python object in the shape of the
9+
documented json response. See
10+
the [documentation](https://help.quali.com/Online%20Help/0.0/Portal/Content/API/RefGuides/Sndbx-REST-API/REST-API-V2-Ref-Guide.htm?tocpath=CloudShell%20API%20Guide%7CCloudShell%20Sandbox%20API%7C_____3)
11+
for details.
1012

1113
### Installation
1214

@@ -15,55 +17,92 @@ pip install cloudshell-sandbox-rest
1517
```
1618

1719
### Basic Usage
20+
1821
```python
1922
from cloudshell.sandbox_rest.sandbox_api import SandboxRestApiSession
2023

24+
# pull in api user credentials
25+
CS_SERVER = "localhost"
26+
CS_USER = "admin"
27+
CS_PASSWORD = "admin"
28+
CS_DOMAIN = "Global"
29+
30+
TARGET_BLUEPRINT = "<MY_BLUEPRINT_NAME>"
31+
DEPLOYED_SANDBOX_NAME = "My Rest Api Blueprint"
2132

22-
api = SandboxRestApiSession(host="localhost", username="admin", password="admin", domain="Global")
23-
start_response = api.start_sandbox(blueprint_id="<MY_BLUEPRINT_NAME>", sandbox_name="My Rest Api Blueprint")
33+
api = SandboxRestApiSession(host=CS_SERVER, username=CS_USER, password=CS_PASSWORD, domain=CS_DOMAIN)
34+
start_response = api.start_sandbox(blueprint_id=TARGET_BLUEPRINT, sandbox_name=DEPLOYED_SANDBOX_NAME)
2435
sandbox_id = start_response["id"]
2536
components_response = api.get_sandbox_components(sandbox_id)
2637

2738
print(f"total components in sandbox: {len(components_response)}")
2839
```
2940

3041
### Context Manager Usage
42+
3143
Using the api session with a context manager "with" statement will log out and invalidate the token for you.
3244

3345
```python
3446
from cloudshell.sandbox_rest.sandbox_api import SandboxRestApiSession
3547

36-
api = SandboxRestApiSession(host="localhost", username="admin", password="admin", domain="Global")
48+
CS_SERVER = "localhost"
49+
CS_USER = "admin"
50+
CS_PASSWORD = "admin"
51+
CS_DOMAIN = "Global"
52+
53+
TARGET_BLUEPRINT = "<MY_BLUEPRINT_NAME>"
54+
DEPLOYED_SANDBOX_NAME = "My Rest Api Blueprint"
55+
56+
api = SandboxRestApiSession(host=CS_SERVER, username=CS_USER, password=CS_PASSWORD, domain=CS_DOMAIN)
3757

3858
with api:
39-
start_response = api.start_sandbox(blueprint_id="<MY_BLUEPRINT_NAME>", sandbox_name="My Rest Api Blueprint")
59+
start_response = api.start_sandbox(blueprint_id=TARGET_BLUEPRINT, sandbox_name=DEPLOYED_SANDBOX_NAME)
4060
sandbox_id = start_response["id"]
4161
components_response = api.get_sandbox_components(sandbox_id)
4262
print(f"total components in sandbox: {len(components_response)}")
4363
print(f"session token is: {api.token}")
4464

4565
print(f"session token outside context manager: {api.token}")
4666
```
67+
4768
- NOTE: api login happens during init, not on entering context
4869
- context exit invalidates token
4970

5071
### Instantiate Session with Token
51-
Common use case is for admin to pull user token and start a session on their behalf. This can be done as seen in example below.
72+
73+
Common use case is for admin to pull user token and start a session on their behalf. This can be done as seen in example
74+
below.
75+
5276
```python
5377
from cloudshell.sandbox_rest.sandbox_api import SandboxRestApiSession
5478

55-
admin_api = SandboxRestApiSession(host="localhost", username="admin", password="admin", domain="Global")
79+
# admin credentials
80+
CS_SERVER = "localhost"
81+
CS_USER = "admin"
82+
CS_PASSWORD = "admin"
83+
ADMIN_DOMAIN = "Global"
84+
85+
# end user details
86+
TARGET_END_USER = "end user"
87+
TARGET_USER_DOMAIN = "<END_USERS_DOMAIN>"
88+
89+
TARGET_BLUEPRINT = "<MY_BLUEPRINT_NAME>"
90+
DEPLOYED_SANDBOX_NAME = "My Rest Api Blueprint"
91+
92+
admin_api = SandboxRestApiSession(host=CS_SERVER, username=CS_USER, password=CS_PASSWORD, domain=ADMIN_DOMAIN)
5693

5794
with admin_api:
58-
user_token = admin_api.get_token_for_target_user("end_user")
59-
user_api = SandboxRestApiSession(host="localhost", token=user_token, domain="<END_USERS_DOMAIN>")
95+
user_token = admin_api.get_token_for_target_user(TARGET_END_USER)
96+
user_api = SandboxRestApiSession(host=CS_SERVER, token=user_token, domain=TARGET_USER_DOMAIN)
6097
with user_api:
61-
start_response = user_api.start_sandbox(blueprint_id="<MY_BLUEPRINT_NAME>", sandbox_name="My Rest Api Blueprint")
98+
start_response = user_api.start_sandbox(blueprint_id=TARGET_BLUEPRINT, sandbox_name=DEPLOYED_SANDBOX_NAME)
6299
sandbox_id = start_response["id"]
63100
components_response = user_api.get_sandbox_components(sandbox_id)
64101
print(f"total components in sandbox: {len(components_response)}")
65102
```
103+
66104
- Note the use of nested context managers to manage the different session tokens
67105

68-
### License
106+
### License
107+
69108
Free Software: MIT License

0 commit comments

Comments
 (0)