예제 #1
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)
예제 #2
0
파일: taxonomy.py 프로젝트: bopopescu/gnote
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 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(
    ).DatapolTaxonomyStoresDataTaxonomiesListRequest(
        parent=resources.REGISTRY.Create(
            'datapol.taxonomyStores',
            taxonomyStoresId=utils.GetTaxonomyStoresId()).RelativeName())
    return list_pager.YieldFromList(_GetService(),
                                    request,
                                    limit=limit,
                                    field='taxonomies',
                                    batch_size_attribute='pageSize')
예제 #4
0
def Delete(data, taxonomy_id):
    """Deletes an annotation on a data asset.

  Args:
    data: Name of the data to be annotated.
    taxonomy_id: Id of the policy taxonomy.

  Returns:
    An Empty message.
  """
    client = utils.GetClientInstance().data_taxonomyStores_dataTaxonomies
    name = resources.REGISTRY.Create(
        'datapol.data.tag',
        data=data,
        taxonomyStoresId=utils.GetTaxonomyStoresId(),
        dataTaxonomiesId=taxonomy_id).RelativeName()
    try:
        return client.DeleteAnnotationTag(utils.GetMessagesModule(
        ).DatapolDataTaxonomyStoresDataTaxonomiesDeleteAnnotationTagRequest(
            name=name))
    except apitools_exceptions.HttpError as e:
        raise utils.ErrorWrapper(e, name)