mirror of
https://staging.allspice.dev/AllSpice-Demos/Actions-demo.git
synced 2024-11-21 21:08:41 +00:00
57 lines
1.6 KiB
Python
57 lines
1.6 KiB
Python
# HelloWorld.py
|
|
|
|
# If you're new to scripting, this is a great place to start.
|
|
|
|
# Hello World starts you out easy with some simple server requests.
|
|
# This will help you troubleshoot your connection and show you the basics of making an api request
|
|
#
|
|
# For more information read our README.md
|
|
from allspice import AllSpice
|
|
import argparse, sys
|
|
|
|
|
|
|
|
|
|
print("Starting Test")
|
|
|
|
parser = argparse.ArgumentParser(
|
|
prog="Allspice_API_BIST", description="Test connection and execution of API actions"
|
|
)
|
|
|
|
parser.add_argument(
|
|
"--allspice_hub_url",
|
|
help="The URL of your AllSpice Hub instance. Defaults to https://hub.allspice.io.",
|
|
)
|
|
parser.add_argument(
|
|
"--allspice_token",
|
|
help="Your AllSpice application token. Generate a token: https://hub.allspice.io/user/settings/applications",
|
|
)
|
|
|
|
print("Parsing args")
|
|
args = parser.parse_args()
|
|
|
|
auth_token = args.allspice_token
|
|
if auth_token is None:
|
|
print("Please supply a token with --allspice_token <your_token> Generate a token: https://hub.allspice.io/user/settings/applications")
|
|
sys.exit(1)
|
|
print(f"Auth token {auth_token}")
|
|
|
|
if args.allspice_hub_url is None:
|
|
allspice = AllSpice(token_text="https://hub.allspice.io")
|
|
else:
|
|
try:
|
|
allspice = AllSpice(
|
|
token_text=auth_token, allspice_hub_url=args.allspice_hub_url
|
|
)
|
|
except Exception as e:
|
|
print("Error")
|
|
sys.exit(1)
|
|
|
|
print("Finish making connection")
|
|
# Test connection and key
|
|
print("AllSpice Version: " + allspice.get_version())
|
|
|
|
# Test private API call
|
|
print("API-Token belongs to user: " + allspice.get_user().username)
|
|
|
|
print("End test") |