1+ # Copyright 2025 Google LLC
2+ #
3+ # Licensed under the Apache License, Version 2.0 (the "License");
4+ # you may not use this file except in compliance with the License.
5+ # You may obtain a copy of the License at
6+ #
7+ # http://www.apache.org/licenses/LICENSE-2.0
8+ #
9+ # Unless required by applicable law or agreed to in writing, software
10+ # distributed under the License is distributed on an "AS IS" BASIS,
11+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+ # See the License for the specific language governing permissions and
13+ # limitations under the License.
14+
115import functions_framework
216from spanner_client import SpannerClient
317from storage_client import StorageClient
418from flask import jsonify
519import logging
620import import_utils
21+ import os
22+ import sys
23+ from absl import flags
724
825logging .getLogger ().setLevel (logging .INFO )
926
10- _PROJECT_ID = 'datcom-import-automation-prod'
11- _SPANNER_PROJECT_ID = 'datcom-store'
12- _SPANNER_INSTANCE_ID = 'dc-kg-test'
13- _SPANNER_DATABASE_ID = 'dc_graph_import'
14- _GCS_BUCKET_ID = 'datcom-prod-imports'
15- _LOCATION = 'us-central1'
27+ FLAGS = flags .FLAGS
28+
29+ flags .DEFINE_string (
30+ 'project_id' , os .environ .get ('PROJECT_ID' , 'datcom-import-automation-prod' ),
31+ 'GCP Project ID' )
32+ flags .DEFINE_string ('spanner_project_id' ,
33+ os .environ .get ('SPANNER_PROJECT_ID' , 'datcom-store' ),
34+ 'Spanner Project ID' )
35+ flags .DEFINE_string ('spanner_instance_id' ,
36+ os .environ .get ('SPANNER_INSTANCE_ID' , 'dc-kg-test' ),
37+ 'Spanner Instance ID' )
38+ flags .DEFINE_string ('spanner_database_id' ,
39+ os .environ .get ('SPANNER_DATABASE_ID' , 'dc_graph_import' ),
40+ 'Spanner Database ID' )
41+ flags .DEFINE_string ('gcs_bucket_id' ,
42+ os .environ .get ('GCS_BUCKET_ID' , 'datcom-prod-imports' ),
43+ 'GCS Bucket ID' )
44+ flags .DEFINE_string ('location' , os .environ .get ('LOCATION' , 'us-central1' ),
45+ 'GCP Location' )
1646
1747
1848def _validate_params (request_json , required_params ):
@@ -36,9 +66,9 @@ def ingestion_helper(request):
3666 return (validation_error , 400 )
3767
3868 actionType = request_json ['actionType' ]
39- spanner = SpannerClient (_SPANNER_PROJECT_ID , _SPANNER_INSTANCE_ID ,
40- _SPANNER_DATABASE_ID )
41- storage = StorageClient (_GCS_BUCKET_ID )
69+ spanner = SpannerClient (FLAGS . spanner_project_id , FLAGS . spanner_instance_id ,
70+ FLAGS . spanner_database_id )
71+ storage = StorageClient (FLAGS . gcs_bucket_id )
4272
4373 if actionType == 'get_import_list' :
4474 # Gets the list of imports that are ready for ingestion.
@@ -76,8 +106,8 @@ def ingestion_helper(request):
76106 import_list = request_json ['importList' ]
77107 workflow_id = request_json ['workflowId' ]
78108 job_id = request_json ['jobId' ]
79- metrics = import_utils .get_ingestion_metrics (_PROJECT_ID , _LOCATION ,
80- job_id )
109+ metrics = import_utils .get_ingestion_metrics (FLAGS . project_id ,
110+ FLAGS . location , job_id )
81111 spanner .update_ingestion_status (import_list , workflow_id , job_id ,
82112 metrics )
83113 return ('Updated ingestion status' , 200 )
0 commit comments