1
1
//! Internal Configuration and state for our connector.
2
2
3
+ use crate :: connection_settings;
3
4
use crate :: environment:: Environment ;
4
5
use crate :: error:: WriteParsedConfigurationError ;
5
- use crate :: values:: { ConnectionUri , DatasetId , PoolSettings , ProjectId , Secret } ;
6
+ use crate :: values:: { DatasetId , PoolSettings , ProjectId , Secret , ServiceKey } ;
6
7
7
8
use super :: error:: ParseConfigurationError ;
8
9
use gcp_bigquery_client:: model:: query_request:: QueryRequest ;
@@ -51,10 +52,7 @@ const NOT_APPROX_COUNTABLE: [&str; 4] = ["image", "sql_variant", "ntext", "text"
51
52
pub struct ParsedConfiguration {
52
53
// Which version of the configuration format are we using
53
54
pub version : u32 ,
54
- // Connection string for a Postgres-compatible database
55
- pub service_key : ConnectionUri ,
56
- pub project_id : ProjectId ,
57
- pub dataset_id : DatasetId ,
55
+ pub connection_settings : connection_settings:: DatabaseConnectionSettings ,
58
56
#[ serde( skip_serializing_if = "PoolSettings::is_default" ) ]
59
57
#[ serde( default ) ]
60
58
pub pool_settings : PoolSettings ,
@@ -80,15 +78,7 @@ impl ParsedConfiguration {
80
78
pub fn empty ( ) -> Self {
81
79
Self {
82
80
version : CURRENT_VERSION ,
83
- service_key : ConnectionUri ( Secret :: FromEnvironment {
84
- variable : DEFAULT_SERVICE_KEY_VARIABLE . into ( ) ,
85
- } ) ,
86
- project_id : ProjectId ( Secret :: FromEnvironment {
87
- variable : DEFAULT_PROJECT_ID_VARIABLE . into ( ) ,
88
- } ) ,
89
- dataset_id : DatasetId ( Secret :: FromEnvironment {
90
- variable : DEFAULT_DATASET_ID_VARIABLE . into ( ) ,
91
- } ) ,
81
+ connection_settings : connection_settings:: DatabaseConnectionSettings :: empty ( ) ,
92
82
pool_settings : PoolSettings :: default ( ) ,
93
83
metadata : metadata:: Metadata :: default ( ) ,
94
84
// aggregate_functions: metadata::AggregateFunctions::default(),
@@ -101,19 +91,17 @@ pub async fn configure(
101
91
args : & ParsedConfiguration ,
102
92
environment : impl Environment ,
103
93
) -> anyhow:: Result < ParsedConfiguration > {
104
- let service_key = match & args. service_key {
105
- ConnectionUri ( Secret :: Plain ( value) ) => Cow :: Borrowed ( value) ,
106
- ConnectionUri ( Secret :: FromEnvironment { variable } ) => {
107
- Cow :: Owned ( environment. read ( variable) ?)
108
- }
94
+ let service_key = match & args. connection_settings . service_key {
95
+ ServiceKey ( Secret :: Plain ( value) ) => Cow :: Borrowed ( value) ,
96
+ ServiceKey ( Secret :: FromEnvironment { variable } ) => Cow :: Owned ( environment. read ( variable) ?) ,
109
97
} ;
110
98
111
- let project_id_ = match & args. project_id {
99
+ let project_id_ = match & args. connection_settings . project_id {
112
100
ProjectId ( Secret :: Plain ( value) ) => Cow :: Borrowed ( value) ,
113
101
ProjectId ( Secret :: FromEnvironment { variable } ) => Cow :: Owned ( environment. read ( variable) ?) ,
114
102
} ;
115
103
116
- let dataset_id_ = match & args. dataset_id {
104
+ let dataset_id_ = match & args. connection_settings . dataset_id {
117
105
DatasetId ( Secret :: Plain ( value) ) => Cow :: Borrowed ( value) ,
118
106
DatasetId ( Secret :: FromEnvironment { variable } ) => Cow :: Owned ( environment. read ( variable) ?) ,
119
107
} ;
@@ -220,9 +208,11 @@ pub async fn configure(
220
208
221
209
Ok ( ParsedConfiguration {
222
210
version : 1 ,
223
- service_key : args. service_key . clone ( ) ,
224
- project_id : args. project_id . clone ( ) ,
225
- dataset_id : args. dataset_id . clone ( ) ,
211
+ connection_settings : connection_settings:: DatabaseConnectionSettings {
212
+ service_key : args. connection_settings . service_key . clone ( ) ,
213
+ project_id : args. connection_settings . project_id . clone ( ) ,
214
+ dataset_id : args. connection_settings . dataset_id . clone ( ) ,
215
+ } ,
226
216
pool_settings : args. pool_settings . clone ( ) ,
227
217
metadata : metadata:: Metadata {
228
218
tables : tables_info,
0 commit comments