Example #1
0
    def remove_object_tag(self, args):
        """Removes a security Tag from an object.

Required Arguments:

* `tag` - The name of the Tag.
* `object_id` - The ID of the object.
* `object_type` - The numeric type of the object.
    
Returns: Success message if successful, error message on failure.
"""
        # this is a admin function
        if not api._ADMIN:
            return R(err_code=R.Codes.Forbidden, err_msg="Only Administrators can perform this function.")
    
        # define the required parameters for this call
        required_params = ["tag", "object_id", "object_type"]
        has_required, resp = api.check_required_params(required_params, args)
        if not has_required:
            return resp

        tag.ObjectTags.Remove(args["tag"], args["object_id"])

        catocommon.write_delete_log(api._USER_ID, args["object_type"], args["object_id"], args["object_id"], "Tag [%s] removed from object via API." % args["tag"])

        return R(response="Tag successfully removed from object.")
Example #2
0
    def delete_credential(self, args):
        """Removes a Shared Credential.

Required Arguments:
 
* `credential` - Name or ID of the Credential to delete.
    
Returns: Success message if successful, error message on failure.
"""
        # this is a developer function
        if not api._DEVELOPER:
            return R(err_code=R.Codes.Forbidden, err_msg="Only Developers or Administrators can perform this function.")
        
        required_params = ["credential"]
        has_required, resp = api.check_required_params(required_params, args)
        if not has_required:
            return resp

        obj = asset.Credential()
        obj.FromName(args["credential"])
        obj.DBDelete()

        catocommon.write_delete_log(api._USER_ID, catocommon.CatoObjectTypes.Credential, obj.ID, obj.Name, "Credential [%s] deleted via API." % obj.Name)

        return R(response="Delete operation successful.")
Example #3
0
    def delete_tag(self, args):
        """Deletes a security Tag.

Required Arguments:

* `name` - The name of the Tag.
    
Returns: Success message if successful, error message on failure.
"""
        # this is a admin function, kick out 
        if not api._ADMIN:
            return R(err_code=R.Codes.Forbidden, err_msg="Only Administrators can perform this function.")
    
        # define the required parameters for this call
        required_params = ["name"]
        has_required, resp = api.check_required_params(required_params, args)
        if not has_required:
            return resp
    
        obj = tag.Tag(args["name"], None)
        obj.DBDelete()

        catocommon.write_delete_log(api._USER_ID, catocommon.CatoObjectTypes.Tag, obj.Name, obj.Name, "Tag [%s] deleted via API." % obj.Name)

        return R(response="Delete operation successful.")
Example #4
0
    def delete_asset(self, args):
        """Deletes an Asset.

Required Arguments:

* asset - Either the Asset ID or Name.

Returns: Nothing if successful, error messages on failure.
"""
        # this is a admin function
        if not api._ADMIN:
            return R(err_code=R.Codes.Forbidden, err_msg="Only Administrators can perform this function.")
        
        required_params = ["asset"]
        has_required, resp = api.check_required_params(required_params, args)
        if not has_required:
            return resp

        obj = asset.Asset()
        obj.FromName(args["asset"])

        if not api.is_object_allowed(obj.ID, catocommon.CatoObjectTypes.Asset):
            return R(err_code=R.Codes.Forbidden, err_msg="You do not have access to the details of this Asset.")
            
        asset.Assets.Delete(["'%s'" % obj.ID])
        
        catocommon.write_delete_log(api._USER_ID, catocommon.CatoObjectTypes.Asset, obj.ID, obj.Name, "Deleted via API.")
        return R(response="[%s] successfully deleted." % obj.Name)
Example #5
0
    def delete_task(self, args):
        """Deletes all versions of a Task.

Required Arguments: 

* `task` - Either the Task ID or Name.

Optional Arguments:

* `force_delete` - Delete the Task, even if there are historical rows and references.  (Valid values: 1, yes, true)

Returns: Nothing if successful, error messages on failure.
"""
        # this is a admin function
        if not api._ADMIN:
            return R(err_code=R.Codes.Forbidden, err_msg="Only Administrators can perform this function.")
        
        required_params = ["task"]
        has_required, resp = api.check_required_params(required_params, args)
        if not has_required:
            return resp

        force = catocommon.is_true(args.get("force_delete"))

        obj = task.Task()
        obj.FromNameVersion(name=args["task"], include_code=False)

        if not api.is_object_allowed(obj.ID, catocommon.CatoObjectTypes.Task):
            return R(err_code=R.Codes.Forbidden, err_msg="You do not have access to the details of this Task.")
            
        task.Tasks.Delete(["'%s'" % obj.ID], force)
        
        catocommon.write_delete_log(api._USER_ID, catocommon.CatoObjectTypes.Task, obj.ID, obj.Name, "Deleted via API.")
        return R(response="[%s] successfully deleted." % obj.Name)
Example #6
0
    def delete_cloud_keypair(self, args):
        """Removes a Key Pair from a Cloud.

Required Arguments: 

* `cloud` - Name or ID of the Cloud.
* `name` - Name of the Key Pair to delete.
    
Returns: A list of [Cloud KeyPair Objects](restapi/api-response-objects.html#CloudKeyPair){:target="_blank"}.
"""
        # this is a developer function
        if not api._DEVELOPER:
            return R(err_code=R.Codes.Forbidden, err_msg="Only Developers or Administrators can perform this function.")
        
        required_params = ["cloud", "name"]
        has_required, resp = api.check_required_params(required_params, args)
        if not has_required:
            return resp

        obj = cloud.Cloud()
        obj.FromName(args["cloud"])
        obj.DeleteKeyPair(args.get("name"))

        catocommon.write_delete_log(api._USER_ID, catocommon.CatoObjectTypes.CloudKeyPair, obj.ID, obj.Name, "KeyPair [%s] removed from Cloud via API." % args.get("name"))

        # so what do we return when we add a keypair?  How about a list of all the keypairs.
        if args.get("output_format") == "json":
            return R(response=obj.KeyPairsAsJSON())
        elif args.get("output_format") == "text":
            return R(response=obj.KeyPairsAsText(args.get("output_delimiter"), args.get("header")))
        else:
            return R(response=obj.KeyPairsAsXML())
Example #7
0
    def delete_plan(self, args):
        """Deletes a specific queued execution Plan.

Required Arguments: 

* `plan_id` - The integer ID of the Plan to delete.

Returns: Nothing if successful, error messages on failure.
"""
        # this is a admin function
        if not api._ADMIN:
            return R(err_code=R.Codes.Forbidden, err_msg="Only Administrators can perform this function.")
        
        required_params = ["plan_id"]
        has_required, resp = api.check_required_params(required_params, args)
        if not has_required:
            return resp

        task.Task.DeletePlan(args["plan_id"])

        catocommon.write_delete_log(api._USER_ID, catocommon.CatoObjectTypes.Task, "", "", "Plan [%s] deleted via API." % (args["plan_id"]))
        
        return R(response="Plan [%s] successfully deleted." % args["plan_id"])
Example #8
0
def WriteObjectDeleteLog(oType, sObjectID, sObjectName, sLog=""):
    catocommon.write_delete_log(GetSessionUserID(), oType, sObjectID, sObjectName, sLog)