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, )
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_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)
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)
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)
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)
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 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_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, )
def set_username_attribute_value(self, username, attribute, value): """ Set an attribute value to the input user Parameters ---------- username : str The username attribute : str The user attribute to set value : str The user attribute's value to set """ if type(username) != str: raise RuleInputValidationError("invalid type for *username: expected a string") 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="set_username_attribute_value", get_result=False, session=self.session, dto=None)
def get_username_attribute_value(self, username, attribute): """ Query an attribute value from the user list of AVU Parameters ---------- username : str The username attribute : str The user attribute to query Returns ------- AttributeValue dto.AttributeValue object """ if type(username) != str: raise RuleInputValidationError("invalid type for *username: expected a string") if type(attribute) != str: raise RuleInputValidationError("invalid type for *attribute: expected a string") return RuleInfo(name="get_username_attribute_value", get_result=True, session=self.session, dto=AttributeValue)
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))
def get_user_group_memberships(self, show_special_groups, username): """ Get the group membership of a given user Parameters ---------- show_special_groups : str 'true'/'false' excepted values; If true, hide the special groups in the result username : str The username to use for the query Returns ------- Groups dto.Groups object """ if show_special_groups != "false" and show_special_groups != "true": raise RuleInputValidationError("invalid value for *showServiceAccounts: expected 'true' or 'false'") if type(username) != str: raise RuleInputValidationError("invalid type for *username: expected a string") return RuleInfo(name="get_user_group_memberships", get_result=True, session=self.session, dto=Groups)
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)
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)
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 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)
def get_active_drop_zones(self, report): """ Get the list of active drop zones Parameters ---------- report : str 'true'/'false' excepted values; If true, show extra values: startDate, endDate & userName Returns ------- DropZones dto.DropZones object """ if report != "false" and report != "true": raise RuleInputValidationError( "invalid value for *report: expected 'true' or 'false'") return RuleInfo(name="listActiveDropZones", get_result=True, session=self.session, dto=DropZones)
def get_project_migration_status(self, project_path): """ Get the list of project's collections Parameters ---------- project_path : str The project's absolute path; eg. /nlmumc/projects/P000000010 Returns ------- MigrationCards dto.MigrationCards object """ if not check_project_path_format(project_path): raise RuleInputValidationError( "invalid project's path format: eg. /nlmumc/projects/P000000010" ) return RuleInfo(name="get_project_migration_status", get_result=True, session=self.session, dto=MigrationCards)
def get_projects(self, show_service_accounts): """ Get the list of projects Parameters ---------- show_service_accounts: str 'true'/'false' expected; If true, hide the service accounts in the result Returns ------- Projects dto.Projects object """ 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_projects", get_result=True, session=self.session, dto=Projects)
def get_contributing_projects(self, show_service_accounts): """ Query the list of ACL for a project for the client user. Returns an empty list if the user is not a contributor. Parameters ---------- show_service_accounts: str 'true'/'false' expected; If true, hide the service accounts in the result Returns ------- ContributingProjects dto.ContributingProjects object """ 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_contributing_projects", get_result=True, session=self.session, dto=ContributingProjects)
def get_user_or_group_by_id(self, uid): if type(uid) != str: raise RuleInputValidationError("invalid type for *username: expected a string") return RuleInfo(name="get_user_or_group_by_id", get_result=True, session=self.session, dto=UserOrGroup)
def create_new_project( self, authorizationPeriodEndDate, dataRetentionPeriodEndDate, ingestResource, resource, storageQuotaGb, title, principalInvestigator, dataSteward, respCostCenter, openAccess, tapeArchive, tapeUnarchive, ): """ Create a new iRODS project Parameters ---------- authorizationPeriodEndDate : str The username dataRetentionPeriodEndDate : str The username ingestResource : str The ingest resource to use during the ingestion resource : str The destination resource to store future collection storageQuotaGb : str The storage quota in Gb title : str The project title principalInvestigator : str The principal investigator(OBI:0000103) for the project dataSteward : str The data steward for the project respCostCenter : str The budget number openAccess : str 'true'/'false' excepted values tapeArchive : str 'true'/'false' excepted values tapeUnarchive : str 'true'/'false' excepted values Returns ------- CreateProject dto.CreateProject object """ # TODO check data format if type(authorizationPeriodEndDate) != str: raise RuleInputValidationError( "invalid type for *authorizationPeriodEndDate: expected a string" ) # TODO check data format if type(dataRetentionPeriodEndDate) != str: raise RuleInputValidationError( "invalid type for *dataRetentionPeriodEndDate: expected a string" ) if type(ingestResource) != str: raise RuleInputValidationError( "invalid type for *ingestResource: expected a string") if type(resource) != str: raise RuleInputValidationError( "invalid type for *resource: expected a string") if type(storageQuotaGb) != int: raise RuleInputValidationError( "invalid type for *storageQuotaGb: expected an integer") if type(title) != str: raise RuleInputValidationError( "invalid type for *title: expected a string") if type(principalInvestigator) != str: raise RuleInputValidationError( "invalid type for *principalInvestigator: expected a string") if type(dataSteward) != str: raise RuleInputValidationError( "invalid type for *dataSteward: expected a string") if type(respCostCenter) != str: raise RuleInputValidationError( "invalid type for *respCostCenter: expected a string") if openAccess != "false" and openAccess != "true": raise RuleInputValidationError( "invalid value for *openAccess: expected 'true' or 'false'") if tapeArchive != "false" and tapeArchive != "true": raise RuleInputValidationError( "invalid value for *tapeArchive: expected 'true' or 'false'") if tapeUnarchive != "false" and tapeUnarchive != "true": raise RuleInputValidationError( "invalid value for *tapeUnarchive: expected 'true' or 'false'") return RuleInfo(name="create_new_project", get_result=True, session=self.session, dto=CreateProject)