def analyze_iam_policy_longrunning_gcs(project_id, dump_file_path):
    # [START asset_quickstart_analyze_iam_policy_longrunning_gcs]
    from google.cloud import asset_v1

    # TODO project_id = 'Your Google Cloud Project ID'
    # TODO dump_file_path = 'Your analysis dump file path'

    client = asset_v1.AssetServiceClient()
    parent = "projects/{}".format(project_id)

    # Build analysis query
    analysis_query = asset_v1.IamPolicyAnalysisQuery()
    analysis_query.scope = parent
    analysis_query.resource_selector.full_resource_name = f"//cloudresourcemanager.googleapis.com/{parent}"
    analysis_query.options.expand_groups = True
    analysis_query.options.output_group_edges = True

    output_config = asset_v1.IamPolicyAnalysisOutputConfig()
    output_config.gcs_destination.uri = dump_file_path
    operation = client.analyze_iam_policy_longrunning(
        request={
            "analysis_query": analysis_query,
            "output_config": output_config
        })

    operation.result(300)
    print(operation.done())
def analyze_iam_policy_longrunning_bigquery(project_id, dataset, table):
    # [START asset_quickstart_analyze_iam_policy_longrunning_bigquery]
    from google.cloud import asset_v1

    # TODO project_id = 'Your Google Cloud Project ID'
    # TODO dataset = 'Your BigQuery dataset path'
    # TODO table = 'Your BigQuery table name'

    client = asset_v1.AssetServiceClient()
    parent = "projects/{}".format(project_id)

    # Build analysis query
    analysis_query = asset_v1.IamPolicyAnalysisQuery()
    analysis_query.scope = parent
    analysis_query.resource_selector.full_resource_name = f"//cloudresourcemanager.googleapis.com/{parent}"
    analysis_query.options.expand_groups = True
    analysis_query.options.output_group_edges = True

    output_config = asset_v1.IamPolicyAnalysisOutputConfig()
    output_config.bigquery_destination.dataset = dataset
    output_config.bigquery_destination.table_prefix = table
    output_config.bigquery_destination.write_disposition = "WRITE_TRUNCATE"
    operation = client.analyze_iam_policy_longrunning(
        request={
            "analysis_query": analysis_query,
            "output_config": output_config
        })

    operation.result(300)
    print(operation.done())
def sample_analyze_iam_policy_longrunning():
    # Create a client
    client = asset_v1.AssetServiceClient()

    # Initialize request argument(s)
    analysis_query = asset_v1.IamPolicyAnalysisQuery()
    analysis_query.scope = "scope_value"

    output_config = asset_v1.IamPolicyAnalysisOutputConfig()
    output_config.gcs_destination.uri = "uri_value"

    request = asset_v1.AnalyzeIamPolicyLongrunningRequest(
        analysis_query=analysis_query,
        output_config=output_config,
    )

    # Make the request
    operation = client.analyze_iam_policy_longrunning(request=request)

    print("Waiting for operation to complete...")

    response = operation.result()

    # Handle the response
    print(response)
async def sample_analyze_iam_policy():
    # Create a client
    client = asset_v1.AssetServiceAsyncClient()

    # Initialize request argument(s)
    analysis_query = asset_v1.IamPolicyAnalysisQuery()
    analysis_query.scope = "scope_value"

    request = asset_v1.AnalyzeIamPolicyRequest(analysis_query=analysis_query, )

    # Make the request
    response = await client.analyze_iam_policy(request=request)

    # Handle the response
    print(response)
def analyze_iam_policy(project_id):
    # [START asset_quickstart_analyze_iam_policy]
    from google.cloud import asset_v1

    # TODO project_id = 'Your Google Cloud Project ID'

    client = asset_v1.AssetServiceClient()
    parent = "projects/{}".format(project_id)

    # Build analysis query
    analysis_query = asset_v1.IamPolicyAnalysisQuery()
    analysis_query.scope = parent
    analysis_query.resource_selector.full_resource_name = f"//cloudresourcemanager.googleapis.com/{parent}"
    analysis_query.options.expand_groups = True
    analysis_query.options.output_group_edges = True

    response = client.analyze_iam_policy(
        request={"analysis_query": analysis_query})
    print(response)