Example #1
0
    def get_project_details(self, project_path, show_service_accounts):
        """
        Get the list of projects

        Parameters
        ----------
        project_path : str
            The project's absolute path; eg. /nlmumc/projects/P000000010
        show_service_accounts: str
            'true'/'false' expected; If true, hide the service accounts in the result

        Returns
        -------

        dict || Project
            JSON || dto.Project object
        """
        if not check_project_path_format(project_path):
            raise RuleInputValidationError(
                "invalid project's path format: eg. /nlmumc/projects/P000000010"
            )
        if show_service_accounts != "false" and show_service_accounts != "true":
            raise RuleInputValidationError(
                "invalid value for *show_service_accounts: expected 'true' or 'false'"
            )

        return RuleInfo(
            name="get_project_details",
            get_result=True,
            session=self.session,
            dto=Project,
            parse_to_dto=self.parse_to_dto,
        )
Example #2
0
    def edit_drop_zone(self, token, project, title):
        """
        Edits the dropzone's project and title AVUs

        Parameters
        ----------
        token : str
            the token of the DZ to modify
        project : str
            the new project number (ex. P000000001)
        title : str
            the new title (ex. bar)

        """

        input_params = {
            "*token": '"{}"'.format(token),
            "*project": '"{}"'.format(project),
            "*title": '"{}"'.format(title),
        }

        rule_body = """
               execute_rule{
                   editIngest;
               }
               """

        return RuleInfo(
            name="editIngest",
            get_result=False,
            session=self.session,
            dto=None,
            input_params=input_params,
            rule_body=rule_body,
        )
Example #3
0
    def change_project_permissions(self, project_id, users):
        """
        Change immediately the ACL on the project level.
        Then in the delay queue, change recursively all the collections under the project.

        Parameters
        ----------
        project_id : str
            The project's id; e.g P000000010
        users: str
            The input string to modify the ACL.
            It should follow the following format: 'username:access_level"
            e.g "[email protected]:read [email protected]:write"
        """
        if not check_project_id_format(project_id):
            raise RuleInputValidationError(
                "invalid project's path format: eg. /nlmumc/projects/P000000010"
            )

        if type(users) != str:
            raise RuleInputValidationError(
                "invalid type for *users: expected a string")

        return RuleInfo(name="changeProjectPermissions",
                        get_result=False,
                        session=self.session,
                        dto=None)
    def set_collection_avu(self, collection_path, attribute, value):
        """
        Set a collection AVU

        Parameters
        ----------
        collection_path : str
            The collection's absolute path; eg. /nlmumc/projects/P000000001
        attribute: str
            The attribute that is going to be set; e.g 'responsibleCostCenter'
        value: str
            The value that is going to bet set; e.g 'UM-12345678N'
        """
        if not check_project_path_format(
                collection_path) and not check_project_collection_path_format(
                    collection_path):
            raise RuleInputValidationError("invalid path format")

        if type(attribute) != str:
            raise RuleInputValidationError(
                "invalid type for *attribute: expected a string")

        if type(value) != str:
            raise RuleInputValidationError(
                "invalid type for *value: expected a string")

        return RuleInfo(name="setCollectionAVU",
                        get_result=False,
                        session=self.session,
                        dto=None)
Example #5
0
    def get_contributing_project(self, project_id, show_service_accounts):
        """
        Get project ACL if the user is a contributor. Otherwise, it returns None

        Parameters
        ----------
        project_id : str
            The project's id path; eg. 000000010
        show_service_accounts: str
            'true'/'false' expected; If true, hide the service accounts in the result

        Returns
        -------
        ContributingProject
            dto.ContributingProject object
        """

        if not check_project_id_format(project_id):
            raise RuleInputValidationError(
                "invalid project id; eg. P000000001")

        if show_service_accounts != "false" and show_service_accounts != "true":
            raise RuleInputValidationError(
                "invalid value for *show_service_accounts: expected 'true' or 'false'"
            )

        return RuleInfo(name="get_contributing_project",
                        get_result=True,
                        session=self.session,
                        dto=ContributingProject)
Example #6
0
    def get_active_drop_zone(self, token, check_ingest_resource_status):
        """
        Get the list of active drop zones

        Parameters
        ----------
        token : str
            The dropzone token
        check_ingest_resource_status : str
            'true'/'false' excepted values; If true, show the project resource status

        Returns
        -------
        DropZone
            dto.DropZone object
        """
        if type(token) != str:
            raise RuleInputValidationError(
                "invalid type for *token: expected a string")

        if check_ingest_resource_status != "false" and check_ingest_resource_status != "true":
            raise RuleInputValidationError(
                "invalid value for *check_ingest_resource_status: expected 'true' or 'false'"
            )

        return RuleInfo(name="get_active_drop_zone",
                        get_result=True,
                        session=self.session,
                        dto=DropZone)
    def get_collection_attribute_value(self, path, attribute):
        """
        Get the attribute value of an iRODS collection

        Parameters
        ----------
        path: str
            The absolute path of the collection
            e.g: /nlmumc/projects/P000000010/C000000001 or /nlmumc/ingest/zones/grieving-giant
        attribute: str
            The attribute to query

        Returns
        -------
        AttributeValue
            dto.AttributeValue object
        """

        if type(path) != str:
            raise RuleInputValidationError(
                "invalid type for *path: expected a string")

        if type(attribute) != str:
            raise RuleInputValidationError(
                "invalid type for *attribute: expected a string")

        return RuleInfo(name="get_collection_attribute_value",
                        get_result=True,
                        session=self.session,
                        dto=AttributeValue)
Example #8
0
    def get_project_acl_for_manager(self, project_id, show_service_accounts):
        """
        Query the list of ACL for a project for the client user

        Parameters
        ----------
        project_id : str
            The project's id; e.g P000000010
        show_service_accounts: str
            'true'/'false' expected; If true, hide the service accounts in the result

        Returns
        -------
        ManagingProjects
            The list of usernames for managers, contributors and viewers.
            Returns an empty list if the user is not a manager.
        """
        if not check_project_id_format(project_id):
            raise RuleInputValidationError(
                "invalid project's path format: e.g P000000010")
        if show_service_accounts != "false" and show_service_accounts != "true":
            raise RuleInputValidationError(
                "invalid value for *showServiceAccounts: expected 'true' or 'false'"
            )

        return RuleInfo(
            name="get_project_acl_for_manager",
            get_result=True,
            session=self.session,
            dto=ManagingProjects,
            parse_to_dto=self.parse_to_dto,
        )
Example #9
0
    def set_acl(self, mode, access_level, user, path):
        """
        Set the ACL of a given collection

        Parameters
        ----------
        mode : str
            'default', 'recursive' excepted values
        access_level : str
            access level: 'own', 'write', 'read'
        user : str
            The username
        path : str
            The absolute path of the collection
        """
        if mode != "default" and mode != "recursive":
            raise RuleInputValidationError(
                "invalid value for *mode: expected 'default' or 'recursive'")
        if access_level != "own" and access_level != "write" and access_level != "read":
            raise RuleInputValidationError(
                "invalid value for *access_level: expected 'default' or 'recursive'"
            )
        if type(user) != str:
            raise RuleInputValidationError(
                "invalid type for *user: expected a string")
        if type(path) != str:
            raise RuleInputValidationError(
                "invalid type for *path: expected a string")

        return RuleInfo(name="set_acl",
                        get_result=False,
                        session=self.session,
                        dto=None)
    def get_project_collection_tape_estimate(self, project, collection):
        """
        The project collection tape status & the number and total bytes size of files eligible for tape

        Parameters
        ----------
        project: str
            The project's id; e.g P000000010
        collection: str
            The collection's id; e.g C000000001

        Returns
        -------
        dict
            The project collection tape status, above_threshold and archivable
        """
        if not check_project_id_format(project):
            raise RuleInputValidationError(
                "invalid project id; eg. P000000001")

        if not check_collection_id_format(collection):
            raise RuleInputValidationError(
                "invalid collection id; eg. C000000001")

        return RuleInfo(name="get_project_collection_tape_estimate",
                        get_result=True,
                        session=self.session,
                        dto=TapeEstimate)
    def get_project_collection_details(self, project, collection, inherited):
        """
        Lists the destination resources and their statuses

        Parameters
        ----------
        project : str
            The collection's absolute path; eg. P000000001
        collection : str
            The collection's id; eg. C000000001
        inherited: str
            The attribute that is going to be set; e.g 'responsibleCostCenter'

        Returns
        -------
        Collection
            The collection avu & acl

        """
        if not check_project_id_format(project):
            raise RuleInputValidationError(
                "invalid project id; eg. P000000001")

        if not check_collection_id_format(collection):
            raise RuleInputValidationError(
                "invalid collection id; eg. C000000001")

        if inherited != "false" and inherited != "true":
            raise RuleInputValidationError(
                "invalid value for *inherited: expected 'true' or 'false'")

        return RuleInfo(name="detailsProjectCollection",
                        get_result=True,
                        session=self.session,
                        dto=CollectionDetails)
Example #12
0
    def get_data_stewards(self):
        """
        Get the list of data stewards

        Returns
        -------
        DataStewards
            dto.DataStewards object
        """
        return RuleInfo(name="getDataStewards", get_result=True, session=self.session, dto=DataStewards)
 def prepare_export(self, project, collection, repository):
     """
     Calls the rule to prepare the project collection for the export:
     * Open the project collection for modification
     * Add the 'in-queue-for-export' AVU
     """
     return RuleInfo(name="prepareExportProjectCollection",
                     get_result=False,
                     session=self.session,
                     dto=None)
 def __export(self, message, project, collection, repository, amqp_host,
              amqp_port, amqp_user, amqp_pass):
     """
     Calls the rule to start an export.
     This method is private since it requires a lot of parameters and should not be called directly but
     always via 'export_project_collection'
     """
     return RuleInfo(name="requestExportProjectCollection",
                     get_result=False,
                     session=self.session,
                     dto=None)
 def get_users_in_group(self, group_id):
     """
     Get the list of users in a specific group
     Parameters
     ----------
     group_id : str
         Group id
     Returns
     -------
     Users
         dto.Users object
     """
     return RuleInfo(name="getUsersInGroup", get_result=True, session=self.session, dto=Users)
Example #16
0
    def get_ingest_resources(self):
        """
        Get the list of ingest resources

        Returns
        -------
        Resources
            dto.Resources object
        """

        return RuleInfo(name="getIngestResources",
                        get_result=True,
                        session=self.session,
                        dto=Resources)
Example #17
0
    def get_projects_overview(self):
        """
        Get the list of projects

        Returns
        -------
        Projects
            dto.ProjectsOverview object
        """

        return RuleInfo(name="optimized_list_projects",
                        get_result=True,
                        session=self.session,
                        dto=ProjectsOverview)
Example #18
0
    def get_destination_resources(self):
        """
        Get the list of destination resources

        Returns
        -------
        Resources
            dto.Resources object
        """

        return RuleInfo(name="getDestinationResources",
                        get_result=True,
                        session=self.session,
                        dto=Resources)
Example #19
0
    def get_projects_finance(self):
        """
        Get the list of projects financial information

        Returns
        -------
        ProjectsCost
            The list of projects financial information

        """

        return RuleInfo(name="get_projects_finance",
                        get_result=True,
                        session=self.session,
                        dto=ProjectsCost)
Example #20
0
    def generate_token(self):
        """
        Gets a unused (dropzone) token generated by iRODS

        Returns
        -------
        Token
            The token generated by iRODS

        """

        return RuleInfo(name="generate_token",
                        get_result=True,
                        session=self.session,
                        dto=Token)
    def unarchive_project_collection(self, path):
        """
        Un-archive a single file or entire collection from tape

        Parameters
        ----------
        path: str
            The absolute path of the collection or the single file to un-archive
            e.g: /nlmumc/projects/P000000010/C000000001 or /nlmumc/projects/P000000010/C000000001/test.txt
        """

        return RuleInfo(name="prepareTapeUnArchive",
                        get_result=False,
                        session=self.session,
                        dto=None)
    def list_groups_users(self):
        """
        Get the list of users for each group

        Returns
        -------
        dict
            JSON rule output
        """

        # TODO Create the DTO

        return RuleInfo(
            name="listGroupsByUser", get_result=True, session=self.session, dto=None, parse_to_dto=self.parse_to_dto
        )
Example #23
0
    def list_destination_resources_status(self):
        """
        Lists the destination resources and their statuses

        Returns
        -------
        Resources
            The resources

        """

        return RuleInfo(name="list_destination_resources_status",
                        get_result=True,
                        session=self.session,
                        dto=Resources)
Example #24
0
    def details_project(self, project, inherited):
        """
        Native iRODS language rule detailsProject.
        Get the project AVUs and its collections details in one rule.

        Returns
        -------
        dict
            JSON rule output
        """

        return RuleInfo(name="detailsProject",
                        get_result=True,
                        session=self.session,
                        dto=None,
                        parse_to_dto=self.parse_to_dto)
Example #25
0
    def list_projects_by_user(self):
        """
        Get the list of projects that each user has access into.


        Returns
        -------
        dict
            JSON rule output
        """

        return RuleInfo(name="listProjectsByUser",
                        get_result=True,
                        session=self.session,
                        dto=None,
                        parse_to_dto=self.parse_to_dto)
    def close_project_collection(self, project, project_collection):
        """
        Set the ACL of a given collection

        Parameters
        ----------
        project : str
            Project id
        project_collection : str
            Collection id
        """
        # Do input validation here
        return RuleInfo(name="closeProjectCollection",
                        get_result=False,
                        session=self.session,
                        dto=None)
    def get_groups(self, show_service_accounts):
        """
        Get the list of groups

        Parameters
        ----------
        show_service_accounts : str
            'true'/'false' excepted values; If true, hide the special groups in the result

        Returns
        -------
        Groups
            dto.Groups object
        """
        if show_service_accounts != "false" and show_service_accounts != "true":
            raise RuleInputValidationError("invalid value for *showServiceAccounts: expected 'true' or 'false'")
        return RuleInfo(name="get_groups", get_result=True, session=self.session, dto=Groups)
    def archive_project_collection(self, collection):
        """
        Archive all the eligible files from the collection to tape

        Parameters
        collection: str
            The absolute collection path: e.g /nlmumc/projects/P000000010/C000000001

        """
        if not check_project_collection_path_format(collection):
            raise RuleInputValidationError(
                "invalid collection id; eg. C000000001")

        return RuleInfo(name="prepareTapeArchive",
                        get_result=False,
                        session=self.session,
                        dto=None)
Example #29
0
    def set_total_size_dropzone(self, token):
        """
        Set an attribute value to the input user

        Parameters
        ----------
        token : str
            The dropzone token to be ingested

        """
        if type(token) != str:
            raise RuleInputValidationError(
                "invalid type for *token: expected a string")

        return RuleInfo(name="set_dropzone_total_size_avu",
                        get_result=False,
                        session=self.session,
                        dto=None)
Example #30
0
    def start_ingest(self, user, token):
        input_params = {
            "*user": '******'.format(user),
            "*token": '"{}"'.format(token)
        }

        rule_body = """
            execute_rule{
                ingest;
            }
            """

        return RuleInfo(
            name="ingest",
            get_result=False,
            session=self.session,
            dto=None,
            input_params=input_params,
            rule_body=rule_body,
        )