Example #1
0
    def create_rule(self,
                    file_name=None,
                    rule_name=None,
                    category=None,
                    content=None):
        response = Response()
        try:
            data = DataObject()
            data.add_value_string("fileName",
                                  ("%s_%s.js" % (category, rule_name)))
            data.add_value_string("category", category)
            data.add_value_string("name", rule_name)
            if content == None:
                with open(file_name, 'rb') as content:
                    data.add_value_string("content",
                                          content.read().decode('utf-8'))
            else:
                data.add_value_string("content", content)
            endpoint = MAPPING_RULES

            response = self.client.post_json(endpoint, data.data)
            response.success = response.status_code == 201

        except IOError as e:
            logger.error(e)
            response.success = False

        return response
Example #2
0
    def create_policy(self,
                      policy_name=None,
                      category=None,
                      policy_type="JavaScript",
                      file_name=None):
        data = DataObject()

        response = None
        try:
            with open(file_name, 'rb') as content:
                data.add_value_string('category', category)
                data.add_value_string('type', policy_type)
                data.add_value_string('name', policy_name)
                data.add_value_string("content",
                                      content.read().decode('utf-8'))
        except IOError as e:
            logger.error(e)
            response = Response()
            response.success = False

        if response == None:
            endpoint = ACCESS_POLICY
            response = self.client.post_json(endpoint, data.data)
            response.success = response.status_code == 201

        return response
Example #3
0
    def create(self, server_config_file=None):
        response = Response()
        endpoint = RSA_CONFIG + "/server_config"
        try:
            with open(server_config_file, "r") as server_config:
                files = {"server_config": server_config}
                response = self.client.post_file(endpoint, files=files)
                response.success = response.status_code == 200
        except IOError as e:
            logger.error(e)
            response.success = False

        return response
Example #4
0
    def import_keytab(self, keytab_file=None):
        response = Response()

        try:
            with open(file_path, 'rb') as contents:
                files = {"keytab_file": contents}

                response = self.client.post_file(KERBEROS_KEYTAB, files=files)
                response.success = response.status_code == 200
        except IOError as e:
            logger.error(e)
            response.success = False

        return response
Example #5
0
    def import_management_root_files(self, webseal_id, file_path):
        response = Response()

        endpoint = ("%s/%s/management_root" % (REVERSEPROXY, webseal_id))

        try:
            with open(file_path, 'rb') as pages:
                files = {"file": pages}

                response = self.client.post_file(endpoint, files=files)
                response.success = response.status_code == 200
        except IOError as e:
            logger.error(e)
            response.success = False

        return response
Example #6
0
    def update_metadata(self, id, filename=None):
        response = Response()
        try:
            with open(filename, 'rb') as content:
                files = {"file": content}

                endpoint = ("%s/%s/file" % (FIDO2_METADATA, id))

                response = self.client.post_file(endpoint, accept_type="application/json,text/html,application/*", files=files)
                response.success = response.status_code == 200

        except IOError as e:
            logger.error(e)
            response.success = False

        return response
Example #7
0
    def import_junction_mapping_file(self, file_path):

        response = Response()

        try:
            with open(file_path, 'rb') as contents:
                jmt_config_file = {"jmt_config_file": contents}

                response = self.client.post_file(JMT_CONFIG,
                                                 files=jmt_config_file)
                response.success = response.status_code == 200
        except IOError as e:
            logger.error(e)
            response.success = False

        return response
Example #8
0
    def import_file(self, path, file_name, file_path):
        response = Response()

        try:
            with open(file_path, 'rb') as template:
                files = {"file": template}

                endpoint = ("%s/%s/%s" % (TEMPLATE_FILES, path, file_name))

                response = self.client.post_file(endpoint, files=files)
                response.success = response.status_code == 200
        except IOError as e:
            logger.error(e)
            response.success = False

        return response
Example #9
0
    def _update_mediator(self, id, filename=None):
        response = Response()
        try:
            with open(filename, 'rb') as content:
                data = DataObject()
                data.add_value_string("content", content.read().decode('utf-8'))

                endpoint = ("%s/%s" % (FIDO2_MEDIATOR, id))

                response = self.client.put_json(endpoint, data.data)
                response.success = response.status_code == 204

        except IOError as e:
            logger.error(e)
            response.success = False

        return response
Example #10
0
    def create_mediator(self, name=None, filename=None):
        response = Response()
        try:
            with open(filename, 'rb') as content:
                data = DataObject()
                data.add_value_string("filename", ntpath.basename(filename))
                data.add_value_string("content", content.read().decode('utf-8'))
                data.add_value_string("type", "FIDO2")
                data.add_value_string("name", name)

                response = self.client.post_json(FIDO2_MEDIATOR, data.data)
                response.success = response.status_code == 201

        except IOError as e:
            logger.error(e)
            response.success = False

        return response
Example #11
0
    def create_metadata(self, filename=None):
        response = Response()
        try:
            with open(filename, 'rb') as content:
                data = DataObject()
                data.add_value_string("filename", ntpath.basename(filename))
                data.add_value_string("contents", content.read().decode('utf-8'))

                endpoint = FIDO2_METADATA

                response = self.client.post_json(endpoint, data.data)
                response.success = response.status_code == 201

        except IOError as e:
            logger.error(e)
            response.success = False

        return response
Example #12
0
    def import_mapping_rule(self, id, file_path):
        response = Response()

        try:
            with open(file_path, 'rb') as mapping_rule:
                files = {"file": mapping_rule}
                endpoint = "%s/%s/file" % (MAPPING_RULES, id)
                accept_type = "%s,%s" % ("application/json", "text/html")

                response = self.client.post_file(
                    endpoint, accept_type=accept_type, files=files)

                response.success = response.status_code == 200
        except IOError as e:
            logger.error(e)
            response.success = False

        return response
Example #13
0
    def import_files(self, file_path, force=True):
        response = Response()

        try:
            with open(file_path, 'rb') as templates:
                files = {"file": templates}

                data = DataObject()
                data.add_value("force", force)

                response = self.client.post_file(TEMPLATE_FILES,
                                                 data=data.data,
                                                 files=files)
                response.success = response.status_code == 200
        except IOError as e:
            logger.error(e)
            response.success = False

        return response
Example #14
0
    def import_signer(self, kdb_id, file_path, label=None):
        response = Response()

        try:
            with open(file_path, 'rb') as certificate:
                data = DataObject()
                data.add_value_string("label", label)

                files = {"cert": certificate}

                endpoint = ("%s/%s/signer_cert" % (SSL_CERTIFICATES, kdb_id))

                response = self.client.post_file(
                    endpoint, data=data.data, files=files)
                response.success = response.status_code == 200
        except IOError as e:
            logger.error(e)
            response.success = False

        return response
Example #15
0
    def import_activation_code(self, file_path):
        response = Response()

        try:
            with open(file_path, 'rb') as code:
                data = DataObject()
                data.add_value_string("name", "activation")

                files = {"filename": code}

                endpoint = CAPABILITIES + "/v1"

                response = self.client.post_file(endpoint,
                                                 data=data.data,
                                                 files=files)
                response.success = response.status_code == 200
        except IOError as e:
            logger.error(e)
            response.success = False

        return response
Example #16
0
    def install_fixpack(self, file_path):
        response = Response()

        try:
            with open(file_path, 'rb') as fixpack:
                data = DataObject()
                data.add_value_string("type", "application/octect-stream")

                files = {"file": fixpack}

                endpoint = FIXPACKS

                response = self.client.post_file(endpoint,
                                                 data=data.data,
                                                 files=files)
                response.success = response.status_code == 200
        except IOError as e:
            logger.error(e)
            response.success = False

        return response
Example #17
0
    def import_personal(self, kdb_id, file_path, password=None):
        response = Response()

        try:
            with open(file_path, 'rb') as certificate:
                data = DataObject()
                data.add_value_string("operation", "import")
                data.add_value_string("password", password)

                files = {"cert": certificate}

                endpoint = ("%s/%s/personal_cert" % (SSL_CERTIFICATES, kdb_id))

                response = self.client.post_file(
                    endpoint, data=data.data, files=files)
                response.success = response.status_code == 200
        except IOError as e:
            logger.error(e)
            response.success = False

        return response
Example #18
0
    def get(self, file_path, type=None):
        parameters = DataObject()
        parameters.add_value_string("type", type)

        endpoint = ("%s/%s" % (FILE_DOWNLOADS, file_path))

        response = Response()
        if type == "file":
            response = self.client.get(endpoint, parameters=parameters.data)
        else:
            response = self.client.get_json(endpoint, parameters.data)
        response.success = response.status_code == 200

        return response
Example #19
0
    def update_rule(self, rule_id, file_name=None):
        response = Response()
        try:
            with open(file_name, 'rb') as content:
                data = DataObject()

                data.add_value_string("content",
                                      content.read().decode('utf-8'))

                endpoint = ("%s/%s" % (MAPPING_RULES, rule_id))

                json.dumps(data.data,
                           sort_keys=True,
                           indent=4,
                           separators=(',', ': '))

                response = self.client.put_json(endpoint, data.data)
                response.success = response.status_code == 204

        except IOError as e:
            logger.error(e)
            response.success = False

        return response