def get_keys(remoteci_id): context = build_signature_context() remoteci = dci_remoteci.get(context, remoteci_id).json()["remoteci"] res = dci_remoteci.refresh_keys(context, id=remoteci_id, etag=remoteci["etag"]) if res.status_code == 201: return res.json()["keys"]
def get_topic_by_id(topic_id): context = build_signature_context() c = dci_topic.get(context, topic_id) topic = c.json()["topic"] if len(topic) == 0: print("Ensure that topic %s exists or that you have access" % topic_id) print("Contact your EPM for more information.") return return topic
def get_topic(topic_name): context = build_signature_context() t = dci_topic.list(context, where="name:%s" % topic_name) t.raise_for_status() topics = t.json()["topics"] if len(topics) == 0: print("Ensure you have access to topic %s" % topic_name) print("Contact your EPM for more information.") return return topics[0]
def get_component_by_id(component_id): context = build_signature_context() c = dci_component.get(context, component_id) component = c.json()["component"] if len(component) == 0: print("Ensure that component %s exists or that you have access" % component_id) print("Contact your EPM for more information.") return return component
def cert_is_valid(cert_file): try: context = build_signature_context() with open(cert_file, "r") as f: cert = f.read() uri = "%s/certs/check" % context.dci_cs_api r = context.session.post(uri, json={"cert": cert}) return r.status_code == 204 except Exception: return False
def get_components(topic): context = build_signature_context() components = [] for component_type in topic["component_types"]: res = dci_topic.list_components( context, topic["id"], limit=1, sort="-created_at", offset=0, where="type:%s,state:active" % component_type, ).json() components.extend(res["components"]) return components
def main(): args = parse_arguments(sys.argv[1:], os.environ) dci_cs_url = args.dci_cs_url dci_login = args.dci_login dci_password = args.dci_password context = None if dci_login is not None and dci_password is not None: context = dci_context.build_dci_context(dci_login=dci_login, dci_password=dci_password, dci_cs_url=dci_cs_url) sso_url = args.sso_url sso_username = args.sso_username sso_password = args.sso_password sso_token = args.sso_token refresh_sso_token = args.refresh_sso_token if (sso_url is not None and sso_username is not None and sso_password is not None) or sso_token is not None: context = dci_context.build_sso_context( dci_cs_url, sso_url, sso_username, sso_password, sso_token, refresh=refresh_sso_token, ) dci_client_id = args.dci_client_id dci_api_secret = args.dci_api_secret if dci_client_id is not None and dci_api_secret is not None: context = dci_context.build_signature_context( dci_cs_url=dci_cs_url, dci_client_id=dci_client_id, dci_api_secret=dci_api_secret, ) if not context: print("No credentials provided.") sys.exit(1) response = run(context, args) print_response(response, args.format, args.verbose)
def create_tag(job_id, name): context = build_signature_context() dci_tag.create(context, name) res = dci_job.add_tag(context, job_id, name) if res.status_code == 201: return res.json()
def create_jobstate(job_id, status): context = build_signature_context() res = dci_jobstate.create(context, status, "download from dci-downloader", job_id) if res.status_code == 201: return res.json()["jobstate"]
def create_job(topic_id): context = build_signature_context() res = dci_job.schedule(context, topic_id) if res.status_code == 201: return res.json()["job"]
def build_context(dci_credentials): return dci_context.build_signature_context( dci_client_id=dci_credentials['DCI_CLIENT_ID'], dci_api_secret=dci_credentials['DCI_API_SECRET'], dci_cs_url=dci_credentials['DCI_CS_URL'])