Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagepy
# - STEP 1.  Import libs -------------------------
from __future__ import print_function
import time
import getpass
import uuid
import syndeia_cloud_33x_client_sdk
from syndeia_cloud_33x_client_sdk.rest import ApiException
from pprint import pprint

# - STEP 2.  Instantiate Configuration object (this is used to set server & credential details) -------------------------
configuration = syndeia_cloud_33x_client_sdk.Configuration()

# - STEP 3.  Set configuration object instance properties --------------------
# Note, if you are unsure of any of the below, contact your CAE Syndeia Cloud server admin 

# configuration.host = "http(s)://host.domain.tld:9000(HTTP)|9443(HTTPS)", ex:  
configuration.host = "<https://mySyndeiaCloudServer.domain.tld:9443"> # -or- "<http://mySyndeiaCloudServer.domain.tld:9000"> if using HTTP

# configuration.username = "username", for LDAP = LDAP "username", for Basic auth = your email address (usually)
configuration.username = "myUsername"

# configuration.password = getpass.getpass()|"myP4$$wD" (prompt for password) | (specify) 
configuration.password = getpass.getpass()

# TLS:  uncomment the below if server is using a self-signed cert, or it isn't in the trust store, or you want to skip SSL validation
# configuration.verify_ssl = False 

# - STEP 4.  Instantiate Syndeia REST ApiClient object with the configuration -----------------------------
api_client_instance = syndeia_cloud_33x_client_sdk.ApiClient(configuration)
# Now, given the api_client_instance, you can instiate any part of the API - AuthAPI, UserAPI, RepositoryAPI, etc.

# - STEP 5.  Authenticate ---------------------------------------------
# Instantiate AuthAPI object
auth_api_instance = syndeia_cloud_33x_client_sdk.AuthApi(api_client_instance)

# IF using LDAP, use the below:  
sign_in_provider_instance = syndeia_cloud_33x_client_sdk.models.SignInProvider(username = configuration.username, password = configuration.password)
authed_instance = auth_api_instance.authenticate_by_provider('LDAP', sign_in_provider_instance)

# ELSE, uncomment and use the below for Basic auth:   
# signin_instance = syndeia_cloud_33x_client_sdk.models.SignIn(username = configuration.username, password = configuration.password, remember_me = False)
# authed_instance = auth_api_instance.sign_in_user(signin_instance)

# grab returned (bearer) token and save in in the configuration object for subsequent requests
configuration.api_key['X-Auth-Token'] = authed_instance.resources.token

# - STEP 6A (optional).  Get all repositories ----------------------------
repository_api_instance = syndeia_cloud_33x_client_sdk.RepositoryApi(api_client_instance)

try:
    # Get all repositories
    repositories_response = repository_api_instance.get_repositories()
    pprint(repositories_response)
except ApiException as e:
    print("Exception when calling RepositoryApi->get_repositories: %s\n" % e)

# print number of repositories
num_repositories = len(repositories_response.resources)
print(num_repositories)

# for all repositories, print repository name (repository host)
for r in repositories_response.resources:
    print(r.name + " ( " + r.host + " ) ")

# - STEP 6B (optional).  Create a test repository ----------------------------
repository_api_instance = syndeia_cloud_33x_client_sdk.RepositoryApi(api_client_instance)
repository_create_instance = syndeia_cloud_33x_client_sdk.RepositoryCreate(gid = str(uuid.uuid4())[:11], 
                                                                       name = 'myRepo of Type Foo by ' + configuration.username, 
                                                                       host = '<https://myRepo.domain.com',> 
                                                                       type = {'name': 'Foo Type'}
                                                                      )

try:
    # Create a new repository
    repository_create_response = repository_api_instance.create_repository(repository_create_instance)
    pprint(repository_create_response)
except ApiException as e:
    print("Exception when calling RepositoryApi->create_repository: %s\n" % e)

# - STEP 7 (optional).  Get containers --------------------------------------
# Instantiate the ContainerAPI
container_api_instance = syndeia_cloud_33x_client_sdk.ContainerApi(api_client_instance)

try:
    container_response = container_api_instance.get_containers()
    print(container_response)
except ApiException as e:
    print("Exception when calling ContainerApi->get_containers: %s\n" % e)

# print number of containers   
num_containers = len(container_response.resources)
print(num_containers)

# print out container name (key)
for c in syndeia_containers:
    print(c.name + " (" + c.key + ")")

# - STEP 8 (optional).  Get artifacts --------------------------------------
# Instantiate the ArtifactAPI
artifact_api_instance = syndeia_cloud_33x_client_sdk.ArtifactApi(api_client_instance)

try:
    artifact_response = artifact_api_instance.get_artifacts()
    print(artifact_response)
except ApiException as e:
    print("Exception when calling ArtifactApi->get_artifacts: %s\n" % e)

# print number of artifacts
num_artifacts = len(artifact_response.resources)
print(num_artifacts)

# - STEP 9 (optional).  Get relations --------------------------------------
# Instantiate the RelationAPI
relation_api_instance = syndeia_cloud_33x_client_sdk.RelationApi(api_client_instance)

try:
    relation_response = relation_api_instance.get_relations()
    print(relation_response)
except ApiException as e:
    print("Exception when calling RelationApi->get_relations: %s\n" % e)

# Number of relations
num_relations = len(relation_response.resources)
print(num_relations)

# Get relations by specific Syndeia projects
# Get the Syndeia container with key UAV_MBEE
uav_relations = relation_api_instance.get_relations_by_container_key("UAV_MBEE")

num_uav_relations = len(uav_relations.resources)
print(num_uav_relations)

for r in uav_relations.resources:
    print(r.key + " - " + r.name)

...