Exemplo n.º 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)
Exemplo n.º 2
0
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 [])))
Exemplo n.º 3
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')
Exemplo n.º 4
0
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 [])))
Exemplo n.º 5
0
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)))
Exemplo n.º 6
0
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))
Exemplo n.º 7
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))
Exemplo n.º 8
0
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)))
Exemplo n.º 9
0
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)))
Exemplo n.º 11
0
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)))
Exemplo n.º 12
0
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()))
Exemplo n.º 13
0
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)))
Exemplo n.º 15
0
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)))
Exemplo n.º 16
0
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)))
Exemplo n.º 17
0
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)))
Exemplo n.º 18
0
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)))
Exemplo n.º 19
0
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')
Exemplo n.º 20
0
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')
Exemplo n.º 21
0
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')
Exemplo n.º 22
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)))
Exemplo n.º 23
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')
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')
Exemplo n.º 25
0
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)))
Exemplo n.º 26
0
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)))
Exemplo n.º 27
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)