Exemple #1
0
def export_assets(project_id, dump_file_path):
    # [START asset_quickstart_exportassets]
    from google.cloud import asset_v1beta1
    from google.cloud.asset_v1beta1.proto import asset_service_pb2

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

    client = asset_v1beta1.AssetServiceClient()
    parent = client.project_path(project_id)
    output_config = asset_service_pb2.OutputConfig()
    output_config.gcs_destination.uri = dump_file_path
    response = client.export_assets(parent, output_config)
    print(response.result())
def main(request):
    request_json = request.get_json()
    if 'key' not in request.args or request.args.get('key') != KEY:
        return "Unauthorized export"
    if request.args and 'fileName' in request.args:
        project_id = request.args.get('fileName')
        dump_file_path = DESTINATION_PATH
        client = asset_v1beta1.AssetServiceClient()
        parent = "organizations/" + ORGANIZATION_ID
        output_config = asset_service_pb2.OutputConfig()
        output_config.gcs_destination.uri = dump_file_path
        response = client.export_assets(parent, output_config)
        return "Export requestsuccess"
    else:
        raise ValueError("Please specify a fileName")
def main(request):
    request_json = request.get_json()
    if 'key' not in request.args or request.args.get('key') != KEY:
        return "Unauthorized export"

    client = asset_v1beta1.AssetServiceClient()
    parent = "organizations/" + ORGANIZATION_ID
    output_config = asset_service_pb2.OutputConfig()
    output_config.gcs_destination.uri = DESTINATION_PATH
    response = client.export_assets(parent, output_config, None, None,
                                    "IAM_POLICY")
    logging.info(response.result())
    logging.info("isdone:")
    logging.info(response.done())
    logging.info("errors:")
    try:
        logging.info(response.error())
    except:
        logging.info("no errors")
    return "Export request success"