Ejemplo n.º 1
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)
Ejemplo n.º 2
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,
        )
Ejemplo n.º 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 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)
Ejemplo n.º 6
0
    def get_collection_size_per_resource(self, project):
        """
        List cllection size per resource

        Parameters
        project : str
            Project ID
        -------

        Returns
        -------

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

        return RuleInfo(name="get_collection_size_per_resource",
                        get_result=True,
                        session=self.session,
                        dto=CollectionSizes)
    def export_project_collection(self, project, collection, repository,
                                  message):
        """
        Starts the exporting process of a collection. Be sure to call this rule
        as 'rodsadmin' because it will open a collection using admin-mode.

        Parameters
        ----------
        project: str
            The project ID e.g. P000000010
        collection: str
            The collection ID e.g. C000000001
        repository: str
            The repository to copy to e.g. Dataverse
        message: dict
            The json input to execute the export

        Returns
        -------
        AttributeValue
            dto.AttributeValue object
        """
        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")

        # This rule can only be executed by 'rodsadmin', so validating on that here
        if self.session.username != "rods":
            raise RuleInputValidationError(
                "this function has to be run as 'rods'")

        self.prepare_export(project, collection, repository)
        publish_message("datahub.events_tx",
                        "projectCollection.exporter.requested",
                        json.dumps(message))
Ejemplo n.º 8
0
    def get_project_contributors(self, project_id, inherited,
                                 show_service_accounts):
        """
        Get the contributors of the projects

        Parameters
        ----------
        project_id : str
            The project's id path; eg. 000000010
        inherited : str
            Role inheritance
            * inherited='true' cumulates authorizations to designate the role. i.e. A contributor has OWN or WRITE access
            * inherited='false' only shows explicit contributors. i.e. A contributor only has WRITE access
        show_service_accounts: str
            'true'/'false' expected; If true, hide the service accounts in the result

        Returns
        -------
        ProjectContributors
            dto.ProjectContributors object
        """
        if not check_project_id_format(project_id):
            raise RuleInputValidationError(
                "invalid project's path format: eg. /nlmumc/projects/P000000010"
            )
        if inherited != "false" and inherited != "true":
            raise RuleInputValidationError(
                "invalid value for *inherited: expected 'true' or 'false'")
        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="list_project_contributors",
                        get_result=True,
                        session=self.session,
                        dto=ProjectContributors)