def post()

in decisionai_plugin/common/tsanaclient.py [0:0]


    def post(self, api_endpoint, instance_id, api_key, user, path, data):
        if not api_endpoint.startswith('http'):
            api_endpoint = "https://" + api_endpoint

        url = api_endpoint.rstrip('/') + path

        headers = {
            "x-api-key": api_key,
            "x-user": user,
            "X-Base-Address": api_endpoint,
            "Instance-Id": instance_id,
            "X-Action-Source": "Plugin",
            "Content-Type": "application/json"
        }

        if self.username and self.password:
            auth = (self.username, self.password)
        else:
            auth = None

        if self.crt and self.key:
            cert = (self.crt, self.key)
        else:
            cert = None

        try:
            r = self.retryrequests.post(url=url, headers=headers, auth=auth, data=json.dumps(data),
                                        timeout=REQUEST_TIMEOUT_SECONDS, cert=cert, verify=False)
            if r.status_code != 204:
                try:
                    return r.json()
                except ValueError as e:
                    return "ValueError: " + str(e) + " Content: " + r.content.decode('UTF-8')
        except Exception as e:
            raise Exception('TSANA service api "{}" failed, request:{}, {}'.format(url, json.dumps(data), str(e)))