Cloudshell Sandbox Rest Api Client
A python client wrapper around the cloudshell sandbox api . 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 for details.
Installation
pip install cloudshell-sandbox-rest
Basic Usage
from cloudshell.sandbox_rest.sandbox_api import SandboxRestApiSession
# pull in api user credentials
CS_SERVER = "localhost"
CS_USER = "admin"
CS_PASSWORD = "admin"
CS_DOMAIN = "Global"
TARGET_BLUEPRINT = "<MY_BLUEPRINT_NAME>"
DEPLOYED_SANDBOX_NAME = "My Rest Api Blueprint"
api = SandboxRestApiSession(host=CS_SERVER, username=CS_USER, password=CS_PASSWORD, domain=CS_DOMAIN)
start_response = api.start_sandbox(blueprint_id=TARGET_BLUEPRINT, sandbox_name=DEPLOYED_SANDBOX_NAME)
sandbox_id = start_response["id"]
components_response = api.get_sandbox_components(sandbox_id)
print(f"total components in sandbox: {len(components_response)}")
Context Manager Usage
Using the api session with a context manager "with" statement will log out and invalidate the token for you.
from cloudshell.sandbox_rest.sandbox_api import SandboxRestApiSession
CS_SERVER = "localhost"
CS_USER = "admin"
CS_PASSWORD = "admin"
CS_DOMAIN = "Global"
TARGET_BLUEPRINT = "<MY_BLUEPRINT_NAME>"
DEPLOYED_SANDBOX_NAME = "My Rest Api Blueprint"
api = SandboxRestApiSession(host=CS_SERVER, username=CS_USER, password=CS_PASSWORD, domain=CS_DOMAIN)
with api:
start_response = api.start_sandbox(blueprint_id=TARGET_BLUEPRINT, sandbox_name=DEPLOYED_SANDBOX_NAME)
sandbox_id = start_response["id"]
components_response = api.get_sandbox_components(sandbox_id)
print(f"total components in sandbox: {len(components_response)}")
print(f"session token is: {api.token}")
print(f"session token outside context manager: {api.token}")
- NOTE: api login happens during init, not on entering context
- context exit invalidates token
Instantiate Session with Token
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.
from cloudshell.sandbox_rest.sandbox_api import SandboxRestApiSession
# admin credentials
CS_SERVER = "localhost"
CS_USER = "admin"
CS_PASSWORD = "admin"
ADMIN_DOMAIN = "Global"
# end user details
TARGET_END_USER = "end user"
TARGET_USER_DOMAIN = "<END_USERS_DOMAIN>"
TARGET_BLUEPRINT = "<MY_BLUEPRINT_NAME>"
DEPLOYED_SANDBOX_NAME = "My Rest Api Blueprint"
admin_api = SandboxRestApiSession(host=CS_SERVER, username=CS_USER, password=CS_PASSWORD, domain=ADMIN_DOMAIN)
with admin_api:
user_token = admin_api.get_token_for_target_user(TARGET_END_USER)
user_api = SandboxRestApiSession(host=CS_SERVER, token=user_token, domain=TARGET_USER_DOMAIN)
with user_api:
start_response = user_api.start_sandbox(blueprint_id=TARGET_BLUEPRINT, sandbox_name=DEPLOYED_SANDBOX_NAME)
sandbox_id = start_response["id"]
components_response = user_api.get_sandbox_components(sandbox_id)
print(f"total components in sandbox: {len(components_response)}")
- Note the use of nested context managers to manage the different session tokens
License
Free Software: MIT License
Metadata
Release files for cloudshell-sandbox-rest 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| cloudshell-sandbox-rest-0.1.1.tar.gz | 6.0 kB | Without provenance | Details for cloudshell-sandbox-rest-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| cloudshell_sandbox_rest-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for cloudshell_sandbox_rest-0.1.1-py3-none-any.whl |
Total release size: 13.1 kB
Release files / cloudshell-sandbox-rest-0.1.1.tar.gz
| Download URL | cloudshell-sandbox-rest-0.1.1.tar.gz |
|---|---|
| Size | 6.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0196bd56c4585a35ed4fc657d19e01fb0063b32dc5ea79ca235e3a3a4398a3de
|
|
BLAKE2b-256 checksum How to use checksums |
890b8529dc934fc1b2bc46417142dced707e4840de5104424239b4e87fa7adbb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9
|
Release files / cloudshell_sandbox_rest-0.1.1-py3-none-any.whl
| Download URL | cloudshell_sandbox_rest-0.1.1-py3-none-any.whl |
|---|---|
| Size | 7.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3d09c05703f462cfbe4afd2e70287bd500911fbc772c25f67d4977d6136be9d6
|
|
BLAKE2b-256 checksum How to use checksums |
e12909fd16671e055aa51e07b77994844d01a62053caeb6c5861b79c9c914320
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9
|
Security for cloudshell-sandbox-rest 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.