예제 #1
0
    def set(self,name, obj):
        '''
        Creates/Updates a SslInitiationPolicy the forum sentry.
        :param name: The name of the SslInitiationPolicy we want to create/update..
        :param obj: The SslInitiationPolicy  to created/updated.
        :raises requests.exceptions.HTTPError: When response code is not successful.
        :returns: The SslInitiationPolicy object that was created/updated.
        '''
        if not isinstance(obj, self.str2Class(self.policy_type)):
            raise InvalidTypeError(obj)
        
        #This doesnt follow the normal pattern. It doesnt take /name
        target_endpoint = "{0}".format(self.path)
        
        self._logger.debug("target_endpoint: {0}".format(target_endpoint))
        
        
        serialized_json = self._serializer.serialize(obj)
        
        self._logger.debug("serialized_json: {0}".format(serialized_json))
        
        try:
            # this method will be patched for unit test
            j = self._request("POST", target_endpoint, serialized_json)
            
            self._logger.debug(j)
            
            obj = self._serializer.deserialize(j, self.policy_type)

            return obj
           
        except HTTPError as e:
            wrapped_error = ForumHTTPError(e)
            self._logger.error(wrapped_error)
            raise wrapped_error
예제 #2
0
    def get(self, name):
        ''' gets a SslInitiationPolicy
        :param name: The name of the SslInitiationPolicy we want to get.
        :raises requests.exceptions.HTTPError: When response code is not successful.
        :returns: A SslInitiationPolicy object.
        '''
        target_endpoint = "{0}/{1}".format(self.path, name)
        
        self._logger.debug("target_endpoint: {0}".format(target_endpoint))

        try:
            # this method will be patched for unit test
            j = self._request("GET", target_endpoint)
            #print j
            self._logger.debug("json returned from {0} >>>>".format(target_endpoint))
            self._logger.debug(j)
            
            obj = self._serializer.deserialize(j, self.policy_type)
            #print obj
            self._logger.debug("object after deserialize >>>>")
            
            return obj
           
        except HTTPError as e:
            self._logger.debug(e)
            if e.response.status_code == 404:
                self._logger.warn("{0} not found".format(name))
                return None
            else:
                wrapped_error = ForumHTTPError(e)
                self._logger.error(wrapped_error)
                raise wrapped_error
예제 #3
0
    def delete(self,name):
        ''' delete a SslInitiationPolicy
        :param name: The name of the SslInitiationPolicy we want to delete.
        :raises requests.exceptions.HTTPError: When response code is not successful.
        :returns: True/False.
        '''
        target_endpoint = "{0}/{1}".format(self.path, name)
        
        self._logger.debug("target_endpoint: {0}".format(target_endpoint))

        try:
            # this method will be patched for unit test
            #We dont expect any data back in a delete. If it fails we'll either get a 404 which means it doesnt exist or some other error which will be thrown up the stack.
            self._request("DELETE", target_endpoint)
            return True
           
        except HTTPError as e:
            self._logger.debug(e)
            if e.response.status_code == 404:
                self._logger.warn("{0} not found".format(name))
                return True
            else:
                wrapped_error = ForumHTTPError(e)
                self._logger.error(wrapped_error)
                raise wrapped_error
예제 #4
0
    def set(self, name, obj):
        '''
        Creates/Updates a TaskList on the forum sentry. Unfortunately task lists updated using this method do not contain any tasks. It is recommended to use deploy for task lists
        :param name: The name of the TaskList we want to create/update..
        :param obj: The TaskList object to created/updated.
        :raises requests.exceptions.HTTPError: When response code is not successful.
        :returns: The TaskList object that was created/updated.
        '''

        if not isinstance(obj, self.str2Class(self.policy_type)):
            raise InvalidTypeError(obj)

        target_endpoint = "{0}/{1}".format(self.path, name)

        self._logger.debug("target_endpoint: {0}".format(target_endpoint))

        serialized_json = self._serializer.serialize(obj)

        self._logger.debug("serialized_json: {0}".format(serialized_json))

        try:
            # this method will be patched for unit test
            j = self._request("PUT", target_endpoint, serialized_json)

            self._logger.debug(j)

            obj = self._serializer.deserialize(j, self.policy_type)

            return obj

        except HTTPError as e:
            wrapped_error = ForumHTTPError(e)
            self._logger.error(wrapped_error)
            raise wrapped_error
예제 #5
0
    def export(self, name, fsg, password, agent=None):
        ''' export a task list to an fsg file
        :param name: The name of the task list we want to export.
        :param fsg: The file to save the export to.
        :param password: The password to encrypt the export with.
        :param agent: The agent to use if required
        :raises requests.exceptions.HTTPError: When response code is not successful.
        :returns: True/False.
        '''
        target_endpoint = "{0}/{1}/fsg".format(self.path, name)

        self._logger.debug("target_endpoint: {0}".format(target_endpoint))

        try:
            # this method will be patched for unit test
            #We dont expect any data back in a delete. If it fails we'll either get a 404 which means it doesnt exist or some other error which will be thrown up the stack.
            return self._export_fsg(target_endpoint, fsg, password, agent)

        except HTTPError as e:
            self._logger.debug(e)
            if e.response.status_code == 404:
                self._logger.warn("{0} not found".format(name))
                return False
            else:
                wrapped_error = ForumHTTPError(e)
                self._logger.error(wrapped_error)
                raise wrapped_error
예제 #6
0
    def get(self, name):
        ''' gets a KeyPairs
        :param name: The name of the KeyPairs we want to get.
        :raises requests.exceptions.HTTPError: When response code is not successful.
        :returns: A string containing the keypair name if found or None if not
        '''
        #the api for key pairs doesnt return a model just a list.
        target_endpoint = "{0}".format(self.path)

        self._logger.debug("target_endpoint: {0}".format(target_endpoint))

        #Json being returned looks like the following
        #
        #See http://jmespath.org/tutorial.html
        #
        # {
        #   "policy": [
        #     {
        #       "name": "test1"
        #     }
        #   ]
        # }

        lookup_expr = 'policy[?name==\'{0}\'].name | [0]'.format(name)

        self._logger.debug("lookup_expr: {0}".format(lookup_expr))

        try:
            # this method will be patched for unit test
            j = self._request("GET", target_endpoint)
            #print j
            self._logger.debug(
                "json returned from {0} >>>>".format(target_endpoint))
            self._logger.debug(j)

            try:
                data = json.loads(j)
                return jmespath.search(lookup_expr, data)
            except Exception as e:
                self._logger.error(e)
                raise e

        except HTTPError as e:
            self._logger.debug(e)
            if e.response.status_code == 404:
                self._logger.warn("{0} not found".format(name))
                return None
            else:
                wrapped_error = ForumHTTPError(e)
                self._logger.error(wrapped_error)
                raise wrapped_error
    def set(self, name, obj):
        '''
        Creates/Updates a TaskListGroup on the forum sentry. 
        :param name: The name of the TaskListGroup we want to create/update..
        :param obj: The TaskListGroup object to created/updated.
        :raises requests.exceptions.HTTPError: When response code is not successful.
        :returns: The TaskListGroup object that was created/updated.
        '''

        if not isinstance(obj, self.str2Class(self.policy_type)):
            raise InvalidTypeError(obj)

        if obj.task_lists is not None:
            if not obj.task_lists:
                self._logger.warn(
                    "task_lists cannot be set to an empty string. It must be a valid comma separated list of task lists that exist in the forum"
                )
                obj.task_lists = None

        target_endpoint = "{0}/{1}".format(self.path, name)

        self._logger.debug("target_endpoint: {0}".format(target_endpoint))

        serialized_json = self._serializer.serialize(obj)

        self._logger.debug("serialized_json: {0}".format(serialized_json))

        try:
            # this method will be patched for unit test
            j = self._request("PUT", target_endpoint, serialized_json)

            self._logger.debug(j)

            obj = self._serializer.deserialize(j, self.policy_type)

            #Forum throws a 400 error if you set the taskLists to '' but forum return taskLists: '' if taskList is None :-(
            if not obj.task_lists:
                obj.task_lists = None

            return obj

        except HTTPError as e:
            wrapped_error = ForumHTTPError(e)
            self._logger.error(wrapped_error)
            raise wrapped_error
예제 #8
0
 def _import_fsg(self,fsg,password):
     
     target_endpoint = "configuration/import?format=fsg"
     
     self._logger.debug("target_endpoint: {0}".format(target_endpoint))
     
     form_data = {}
     form_data['password'] = password
     
     try:
         # this method will be patched for unit test
         return self._request_file(target_endpoint, fsg, form_data,download=False)
         
        
     except HTTPError as e:
         wrapped_error = ForumHTTPError(e)
         self._logger.error(wrapped_error)
         raise wrapped_error
예제 #9
0
    def pkcs12(self,
               name,
               p12,
               p12_password,
               private_key_password,
               create_signer_group=True):
        '''
        Creates/Updates a KeyPairs on the forum sentry.
        :param name: The name of the KeyPairs we want to create/update..
        :param p12: The p12 file to upload.
        :param p12_password: The password for the p12 file
        :param private_key_password: The password for the private key
        :param create_signer_group: If we should create a signer group from the p12. Default == True
        :raises requests.exceptions.HTTPError: When response code is not successful.
        :returns: The KeyPairs object that was created/updated.
        '''

        target_endpoint = "{0}/import/pkcs12".format(self.path)

        self._logger.debug("target_endpoint: {0}".format(target_endpoint))
        body_param = "keyAndCertificateFile"
        form_data = {}
        form_data['createSignerGroup'] = create_signer_group
        form_data['fileIntegrityPassword'] = p12_password
        form_data['password'] = private_key_password
        form_data['name'] = name
        try:
            # this method will be patched for unit test
            return self._request_file(target_endpoint,
                                      p12,
                                      form_data=form_data,
                                      download=False,
                                      body_param=body_param)

        except HTTPError as e:
            wrapped_error = ForumHTTPError(e)
            self._logger.error(wrapped_error)
            raise wrapped_error
    def get(self, name):
        ''' gets a TaskListGroup
        :param name: The name of the TaskListGroup we want to get.
        :raises requests.exceptions.HTTPError: When response code is not successful.
        :returns: A TaskListGroup object.
        '''

        target_endpoint = "{0}/{1}".format(self.path, name)

        self._logger.debug("target_endpoint: {0}".format(target_endpoint))

        try:
            # this method will be patched for unit test
            j = self._request("GET", target_endpoint)
            #print j
            self._logger.debug(
                "json returned from {0} >>>>".format(target_endpoint))
            self._logger.debug(j)

            obj = self._serializer.deserialize(j, self.policy_type)
            #print obj
            self._logger.debug("object after deserialize >>>>")

            #Forum throws a 400 error if you set the taskLists to '' but forum return taskLists: '' if taskList is None :-(
            if not obj.task_lists:
                obj.task_lists = None

            return obj

        except HTTPError as e:
            self._logger.debug(e)
            if e.response.status_code == 404:
                self._logger.warn("{0} not found".format(name))
                return None
            else:
                wrapped_error = ForumHTTPError(e)
                self._logger.error(wrapped_error)
                raise wrapped_error
예제 #11
0
    def set_virtual_directory(self, name, virtual_directory, obj):
        '''
        Creates/Updates a virtual directory attached to a JsonPolicies on the forum sentry.
        :param name: The name of the JsonPolicies we want to create/update..
        :param virtual_directory: The name of the VirtualDirectory we want to create/update.  
        :param obj: The VirtualDirectory object to created/updated.
        :raises requests.exceptions.HTTPError: When response code is not successful.
        :returns: The VirtualDirectory object that was created/updated.
        '''
        if not isinstance(obj, self.str2Class(self.virtual_directory_type)):
            raise InvalidTypeError(obj)

        target_endpoint = "{0}/{1}/{2}/{3}".format(self.path, name,
                                                   self.virtual_directory_path,
                                                   virtual_directory)

        self._logger.debug("target_endpoint: {0}".format(target_endpoint))

        serialized_json = self._serializer.serialize(obj)

        self._logger.debug("serialized_json: {0}".format(serialized_json))

        try:
            # this method will be patched for unit test
            j = self._request("PUT", target_endpoint, serialized_json)

            self._logger.debug(j)

            obj = self._serializer.deserialize(j, self.virtual_directory_type)

            return obj

        except HTTPError as e:
            wrapped_error = ForumHTTPError(e)
            self._logger.error(wrapped_error)
            raise wrapped_error
예제 #12
0
    def get_virtual_directory(self, name, virtual_directory):
        ''' gets a virtual directory attached to a JsonPolicies
        :param name: The name of the JsonPolicies we want to get the virtual directory from.
        :param virtual_directory: The name of the VirtualDirectory we want to get.
        :raises requests.exceptions.HTTPError: When response code is not successful.
        :returns: A VirtualDirectory object.
        '''
        target_endpoint = "{0}/{1}/{2}/{3}".format(self.path, name,
                                                   self.virtual_directory_path,
                                                   virtual_directory)

        self._logger.debug("target_endpoint: {0}".format(target_endpoint))

        try:
            # this method will be patched for unit test
            j = self._request("GET", target_endpoint)
            #print j
            self._logger.debug(
                "json returned from {0} >>>>".format(target_endpoint))
            self._logger.debug(j)

            obj = self._serializer.deserialize(j, self.virtual_directory_type)
            #print obj
            self._logger.debug("object after deserialize >>>>")

            return obj

        except HTTPError as e:
            self._logger.debug(e)
            if e.response.status_code == 404:
                self._logger.warn("{0} not found".format(name))
                return None
            else:
                wrapped_error = ForumHTTPError(e)
                self._logger.error(wrapped_error)
                raise wrapped_error