def Apply(data, taxonomy_id, annotation_id): """Applies an annotation to a data asset. Args: data: Name of the data to be annotated. taxonomy_id: Id of the policy taxonomy. annotation_id: Id of the annotation. This annotation must belong to the policy taxonomy specified in taxonomy_name. Returns: An AnnotationTag message. """ client = utils.GetClientInstance().data_taxonomyStores_dataTaxonomies messages = utils.GetMessagesModule() name = resources.REGISTRY.Create( 'datapol.data.taxonomy', data=data, taxonomyStoresId=utils.GetTaxonomyStoresId(), dataTaxonomiesId=taxonomy_id).RelativeName() try: return client.ApplyAnnotationTag( messages. DatapolDataTaxonomyStoresDataTaxonomiesApplyAnnotationTagRequest( name=name, applyAnnotationTagRequest=messages.ApplyAnnotationTagRequest( annotationId=annotation_id))) except apitools_exceptions.HttpError as e: raise utils.ErrorWrapper(e, name)
def Create(taxonomy_id, annotation_name, description, parent_annotation=None, child_annotations=None): """Makes an API call to create an annotation in the given taxonomy. Args: taxonomy_id: Id of a taxonomy. annotation_name: Name of the annotation. description: a short description to the annotation. parent_annotation: Id of the parent annotation to this annotation. child_annotations: Ids of child annotations of this annotaiton. Returns: An Annotation message. """ messages = utils.GetMessagesModule() return _GetService().Create( messages.DatapolTaxonomyStoresDataTaxonomiesAnnotationsCreateRequest( parent=utils.GetTaxonomyRelativeName(taxonomy_id), annotation=messages.Annotation( displayName=annotation_name, description=description, parentAnnotation=parent_annotation, childAnnotations=child_annotations if child_annotations else [])))
def ListDataAssets(annotations=None, include_annotated_by_group=False, annotatable_only=True, filter_exp='', limit=None): """Lists resource names of all data assets with the given annotations. Args: annotations: A list of annotations. Each returned data asset will be tagged with at one of those annotations. include_annotated_by_group: If true, and a given annotation has child annotations, also returns data assets that are annotated with those child annotations. annotatable_only: If true, only returns data assets that are annotatable by the caller. filter_exp: A expression to further filter data assets limit: The number of resource names to limit the resutls to. Returns: Generator that yields resource names of data assets. """ request = utils.GetMessagesModule( ).DatapolDataAssetsListResourceNamesRequest( annotations=annotations or [], includeAnnotatedByGroup=include_annotated_by_group, annotatableOnly=annotatable_only, filter=filter_exp) return list_pager.YieldFromList(utils.GetClientInstance().dataAssets, request, limit=limit, method='ListResourceNames', field='dataAssets', batch_size_attribute='pageSize')
def Create(parent, annotation_name, description, parent_annotation=None, child_annotations=None): """Makes an API call to create an annotation in the given taxonomy. Args: parent: Resource name of a taxonomy. annotation_name: Name of the annotation. description: a short description to the annotation. parent_annotation: Name of the parent annotation to this annotation. child_annotations: Names of child annotations of this annotaiton. Returns: An Annotation message. """ messages = utils.GetMessagesModule() return _GetService().Create( messages.DatapolOrgsPolicyTaxonomiesAnnotationsCreateRequest( parent=parent, annotation=messages.Annotation( annotationName=annotation_name, description=description, parentAnnotation=parent_annotation, childAnnotations=child_annotations if child_annotations else [])))
def Get(taxonomy_name): """Makes an API call to get the definition of a taxonomy. Args: taxonomy_name: Name of the taxonomy. Returns: A Taxonomy message. """ return _GetService().Get( utils.GetMessagesModule().DatapolTaxonomyStoresDataTaxonomiesGetRequest( name=utils.GetTaxonomyRelativeName(taxonomy_name)))
def Get(name): """Makes an API call to get the definition of a taxonomy. Args: name: Resource name of the taxonomy. Returns: A Taxonomy message. """ return _GetService().Get( utils.GetMessagesModule().DatapolOrgsPolicyTaxonomiesGetRequest( name=name))
def Delete(name): """Deletes an annotation on a data asset. Args: name: Resource name of the annotation tag. Returns: An Empty message. """ client = utils.GetClientInstance().data_orgs_policyTaxonomies return client.DeleteAnnotationTag( utils.GetMessagesModule() .DatapolDataOrgsPolicyTaxonomiesDeleteAnnotationTagRequest(name=name))
def Delete(taxonomy_name): """Makes an API call to delete a taxonomy. Args: taxonomy_name: Name of the taxonomy. Returns: An Operation message which can be used to check on the progress of taxonomy deletion. """ return _GetService().Delete(utils.GetMessagesModule( ).DatapolTaxonomyStoresDataTaxonomiesDeleteRequest( name=utils.GetTaxonomyRelativeName(taxonomy_name)))
def Delete(name): """Makes an API call to delete a taxonomy. Args: name: Resource name of the taxonomy. Returns: An Operation message which can be used to check on the progress of taxonomy deletion. """ return _GetService().Delete( utils.GetMessagesModule().DatapolOrgsPolicyTaxonomiesDeleteRequest( name=name))
def Get(taxonomy_id, annotation_id): """Makes an API call to get the definition of an annotation. Args: taxonomy_id: Id of a taxonomy. annotation_id: Id of the annotation. Returns: An Annotation message. """ return _GetService().Get(utils.GetMessagesModule( ).DatapolTaxonomyStoresDataTaxonomiesAnnotationsGetRequest( name=utils.GetAnnotationRelativeName(taxonomy_id, annotation_id)))
def Get(taxonomy_name, annotation_name): """Makes an API call to get the definition of an annotation. Args: taxonomy_name: Name of a taxonomy. annotation_name: Name of the annotation. Returns: An Annotation message. """ return _GetService().Get( utils.GetMessagesModule() .DatapolOrgsPolicyTaxonomiesAnnotationsGetRequest( name=utils.GetAnnotationRelativeName(taxonomy_name, annotation_name)))
def GetIamPolicy(taxonomy_name): """Gets IAM policy for a given taxonomy. Args: taxonomy_name: Name of the taxonomy. Returns: An IamPolicy message. """ messages = utils.GetMessagesModule() return _GetService().GetIamPolicy( messages.DatapolTaxonomyStoresDataTaxonomiesGetIamPolicyRequest( resource=utils.GetTaxonomyRelativeName(taxonomy_name), getIamPolicyRequest=messages.GetIamPolicyRequest()))
def GetIamPolicy(resource): """Gets IAM policy for a given taxonomy. Args: resource: Resource name of the taxonomy. Returns: An IamPolicy message. """ messages = utils.GetMessagesModule() return _GetService().GetIamPolicy( messages.DatapolOrgsPolicyTaxonomiesGetIamPolicyRequest( resource=resource, getIamPolicyRequest=messages.GetIamPolicyRequest()))
def Delete(taxonomy_id, annotation_id): """Makes an API call to delete an annotation. Args: taxonomy_id: Id of a taxonomy. annotation_id: Id of the annotation. Returns: An Operation message which can be used to check on the progress of the project creation. """ return _GetService().Delete(utils.GetMessagesModule( ).DatapolTaxonomyStoresDataTaxonomiesAnnotationsDeleteRequest( name=utils.GetAnnotationRelativeName(taxonomy_id, annotation_id)))
def SetIamPolicy(resource, policy): """Sets IAM policy, for a given taxonomy. Args: resource: Resource name of the taxonomy. policy: An IamPolicy message. Returns: An IamPolicy message. """ messages = utils.GetMessagesModule() return _GetService().SetIamPolicy( messages.DatapolOrgsPolicyTaxonomiesSetIamPolicyRequest( resource=resource, setIamPolicyRequest=messages.SetIamPolicyRequest(policy=policy)))
def SetIamPolicy(taxonomy_name, policy): """Sets IAM policy, for a given taxonomy. Args: taxonomy_name: Name of the taxonomy. policy: An IamPolicy message. Returns: An IamPolicy message. """ messages = utils.GetMessagesModule() return _GetService().SetIamPolicy( messages.DatapolTaxonomyStoresDataTaxonomiesSetIamPolicyRequest( resource=utils.GetTaxonomyRelativeName(taxonomy_name), setIamPolicyRequest=messages.SetIamPolicyRequest(policy=policy)))
def Update(name, description): """Makes an API call to update an annotation. Args: name: Resource name of the annotation. description: New description to be updated. Returns: An Annotation message. """ messages = utils.GetMessagesModule() return _GetService().Patch( messages.DatapolOrgsPolicyTaxonomiesAnnotationsPatchRequest( name=name, updateAnnotationRequest=messages.UpdateAnnotationRequest( description=description)))
def Update(taxonomy_id, annotation_id, description): """Makes an API call to update an annotation. Args: taxonomy_id: Id of a taxonomy. annotation_id: Id of the annotation. description: New description to be updated. Returns: An Annotation message. """ messages = utils.GetMessagesModule() return _GetService().Patch( messages.DatapolTaxonomyStoresDataTaxonomiesAnnotationsPatchRequest( name=utils.GetAnnotationRelativeName(taxonomy_id, annotation_id), annotation=messages.Annotation(description=description)))
def List(limit=None): """Makes API calls to list taxonomies under the current organization. Args: limit: The number of taxonomies to limit the resutls to. Returns: Generator that yields taxonomies """ request = utils.GetMessagesModule().DatapolOrgsPolicyTaxonomiesListRequest( parent=_ORG_PATTERN.format(_GetOrganizationId())) return list_pager.YieldFromList(_GetService(), request, limit=limit, field='taxonomies', batch_size_attribute='pageSize')
def List(limit=None): """Makes API calls to list taxonomies under the current organization. Args: limit: The number of taxonomies to limit the resutls to. Returns: Generator that yields taxonomies """ request = utils.GetMessagesModule().DatapolOrgsPolicyTaxonomiesListRequest( parent=resources.REGISTRY.Create( 'datapol.org', orgsId=utils.GetOrganizationId()).RelativeName()) return list_pager.YieldFromList(_GetService(), request, limit=limit, field='taxonomies', batch_size_attribute='pageSize')
def List(parent, limit=None): """Makes API calls to list annotations under the given taxonomy. Args: parent: Resource name of a taxonomy. limit: The number of taxonomies to limit the resutls to. Returns: Generator that yields taxonomies """ request = utils.GetMessagesModule( ).DatapolOrgsPolicyTaxonomiesAnnotationsListRequest(parent=parent) return list_pager.YieldFromList( _GetService(), request, limit=limit, field='annotations', batch_size_attribute='pageSize')
def Apply(name, annotation_name): """Applies an annotation to a data asset. Args: name: Resource name of the annotation tag. annotation_name: Name of the annotation. This annotation must belong to the policy taxonomy specified in the resource name. Returns: An AnnotationTag message. """ client = utils.GetClientInstance().data_orgs_policyTaxonomies messages = utils.GetMessagesModule() return client.ApplyAnnotationTag( messages.DatapolDataOrgsPolicyTaxonomiesApplyAnnotationTagRequest( name=name, applyAnnotationTagRequest=messages.ApplyAnnotationTagRequest( annotationName=annotation_name)))
def ListTags(data, limit=None): """Lists all annotation tags on a data asset. Args: data: Resource name of the data. limit: The number of annotation tags to limit the resutls to. Returns: Generator that yields annnotation tags. """ request = utils.GetMessagesModule().DatapolDataOrgsAnnotationTagsListRequest( parent=data) return list_pager.YieldFromList( utils.GetClientInstance().data_orgs_annotationTags, request, limit=limit, field='tags', batch_size_attribute='pageSize')
def List(taxonomy_id, limit=None): """Makes API calls to list annotations under the given taxonomy. Args: taxonomy_id: Id of a taxonomy. limit: The number of taxonomies to limit the resutls to. Returns: Generator that yields taxonomies """ request = utils.GetMessagesModule( ).DatapolTaxonomyStoresDataTaxonomiesAnnotationsListRequest( parent=utils.GetTaxonomyRelativeName(taxonomy_id)) return list_pager.YieldFromList(_GetService(), request, limit=limit, field='annotations', batch_size_attribute='pageSize')
def Create(taxonomy_name, description): """Makes an API call to create a taxonomy. Args: taxonomy_name: Name of the taxononmy. Needs to be unique within the organization. description: A short description to the taxonomy. Returns: A Taxonomy message. """ messages = utils.GetMessagesModule() return _GetService().Create( messages.DatapolTaxonomyStoresDataTaxonomiesCreateRequest( parent=resources.REGISTRY.Create( 'datapol.taxonomyStores', taxonomyStoresId=utils.GetTaxonomyStoresId()).RelativeName(), dataTaxonomy=messages.DataTaxonomy( taxonomyName=taxonomy_name, description=description)))
def Create(taxonomy_name, description): """Makes an API call to create a taxonomy. Args: taxonomy_name: Name of the taxononmy. Needs to be unique within the organization. description: A short description to the taxonomy. Returns: A Taxonomy message. """ messages = utils.GetMessagesModule() org_id = _GetOrganizationId() return _GetService().Create( messages.DatapolOrgsPolicyTaxonomiesCreateRequest( parent=_ORG_PATTERN.format(org_id), policyTaxonomy=messages.PolicyTaxonomy(orgId=org_id, taxonomyName=taxonomy_name, description=description)))
def Delete(data, taxonomy_name): """Deletes an annotation on a data asset. Args: data: Name of the data to be annotated. taxonomy_name: Name of the policy taxonomy. Returns: An Empty message. """ client = utils.GetClientInstance().data_orgs_policyTaxonomies name = resources.REGISTRY.Create( 'datapol.data.tag', data=data, orgsId=utils.GetOrganizationId(), policyTaxonomiesId=taxonomy_name).RelativeName() try: return client.DeleteAnnotationTag(utils.GetMessagesModule( ).DatapolDataOrgsPolicyTaxonomiesDeleteAnnotationTagRequest(name=name)) except apitools_exceptions.HttpError as e: raise utils.ErrorWrapper(e, name)