Пример #1
0
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')
Пример #2
0
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)
Пример #3
0
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))
Пример #4
0
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')
Пример #5
0
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)))
Пример #6
0
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)
Пример #7
0
def _GetService():
  """Gets the data policy taxonomiy service."""
  return utils.GetClientInstance().taxonomyStores_dataTaxonomies
Пример #8
0
def _GetService():
    """Gets the data policy taxonomiy service."""
    return utils.GetClientInstance().orgs_policyTaxonomies