3
3
use crate :: connection_settings;
4
4
use crate :: environment:: Environment ;
5
5
use crate :: error:: WriteParsedConfigurationError ;
6
- use crate :: values:: { DatasetId , PoolSettings , ProjectId , Secret , ServiceKey } ;
6
+ use crate :: values:: { DatasetId , PoolSettings , ProjectId , Secret , ServiceKey , WorkloadIdentityAuth } ;
7
7
8
8
use super :: error:: ParseConfigurationError ;
9
9
use gcp_bigquery_client:: model:: query_request:: QueryRequest ;
@@ -94,10 +94,44 @@ pub async fn configure(
94
94
args : & ParsedConfiguration ,
95
95
environment : impl Environment ,
96
96
) -> anyhow:: Result < ParsedConfiguration > {
97
- let service_key = match & args. connection_settings . service_key {
98
- ServiceKey ( Secret :: Plain ( value) ) => Cow :: Borrowed ( value) ,
99
- ServiceKey ( Secret :: FromEnvironment { variable } ) => Cow :: Owned ( environment. read ( variable) ?) ,
97
+ let bigquery_client = match & args. connection_settings . workload_identity_auth {
98
+ Some ( WorkloadIdentityAuth ( Secret :: Plain ( value) ) ) => {
99
+ let url = Cow :: Borrowed ( value) ;
100
+ std:: env:: set_var ( "BIG_QUERY_AUTH_URL" , url. as_ref ( ) ) ;
101
+ gcp_bigquery_client:: Client :: with_workload_identity ( false ) . await . unwrap ( )
102
+ } ,
103
+ Some ( WorkloadIdentityAuth ( Secret :: FromEnvironment { variable } ) ) => {
104
+ let url: Cow < ' _ , String > = Cow :: Owned ( environment. read ( variable) ?) ;
105
+ std:: env:: set_var ( "BIG_QUERY_AUTH_URL" , url. as_ref ( ) ) ;
106
+ gcp_bigquery_client:: Client :: with_workload_identity ( false ) . await . unwrap ( )
107
+ } ,
108
+ None => {
109
+ match & args. connection_settings . service_key {
110
+ Some ( ServiceKey ( Secret :: Plain ( value) ) ) => {
111
+ let service_key = Cow :: Borrowed ( value) ;
112
+ let service_account_key = yup_oauth2:: parse_service_account_key ( service_key. as_str ( ) ) . unwrap ( ) ;
113
+ gcp_bigquery_client:: Client :: from_service_account_key ( service_account_key, false ) . await . unwrap ( )
114
+ } ,
115
+ Some ( ServiceKey ( Secret :: FromEnvironment { variable } ) ) => {
116
+ let service_key: Cow < ' _ , String > = Cow :: Owned ( environment. read ( variable) ?) ;
117
+ let service_account_key = yup_oauth2:: parse_service_account_key ( service_key. as_str ( ) ) . unwrap ( ) ;
118
+ gcp_bigquery_client:: Client :: from_service_account_key ( service_account_key, false ) . await . unwrap ( )
119
+ } ,
120
+ None => {
121
+ return Err ( anyhow:: anyhow!( "Neither Workload Identity Auth URL or Service key is provided" ) ) ;
122
+ } ,
123
+ }
124
+ }
100
125
} ;
126
+ // let service_key = match &args.connection_settings.service_key {
127
+ // Some(ServiceKey(Secret::Plain(value))) => Cow::Borrowed(value),
128
+ // Some(ServiceKey(Secret::FromEnvironment { variable })) => Cow::Owned(environment.read(variable)?),
129
+ // };
130
+
131
+ // let workload_identity_auth = match &args.connection_settings.workload_identity_auth {
132
+ // WorkloadIdentityAuth(Secret::Plain(value)) => Cow::Borrowed(value),
133
+ // WorkloadIdentityAuth(Secret::FromEnvironment { variable }) => Cow::Owned(environment.read(variable)?),
134
+ // };
101
135
102
136
let project_id_ = match & args. connection_settings . project_id {
103
137
ProjectId ( Secret :: Plain ( value) ) => Cow :: Borrowed ( value) ,
@@ -109,19 +143,37 @@ pub async fn configure(
109
143
DatasetId ( Secret :: FromEnvironment { variable } ) => Cow :: Owned ( environment. read ( variable) ?) ,
110
144
} ;
111
145
112
- let service_account_key = yup_oauth2:: parse_service_account_key ( service_key. as_str ( ) ) . unwrap ( ) ;
146
+ // let service_account_key = yup_oauth2::parse_service_account_key(service_key.as_str()).unwrap();
113
147
114
148
let project_id = project_id_. as_str ( ) ;
115
149
let dataset_id = dataset_id_. as_str ( ) ;
116
150
117
151
let schema_name = format ! ( "{project_id}.{dataset_id}" ) ;
118
152
let database_name = schema_name. clone ( ) ;
119
153
120
- // Init BigQuery client
121
- let bigquery_client =
122
- gcp_bigquery_client:: Client :: from_service_account_key ( service_account_key, false )
123
- . await
124
- . unwrap ( ) ;
154
+ // let bigquery_client = match
155
+ // BIG_QUERY_AUTH_URL
156
+
157
+ // let big_query_auth_url = match std::env::var("HASURA_BIGQUERY_WORKLOAD_IDENTITY_AUTH") {
158
+ // Ok(val) => val,
159
+ // Err(_) => {
160
+ // return Err(anyhow::anyhow!(
161
+ // "Environment variable HASURA_BIGQUERY_WORKLOAD_IDENTITY_AUTH not set"
162
+ // ))
163
+ // }
164
+ // };
165
+
166
+ // std::env::set_var("BIG_QUERY_AUTH_URL", workload_identity_auth.as_ref());
167
+
168
+ // if
169
+
170
+ // let bigquery_client_auth = gcp_bigquery_client::Client::with_workload_identity(true).await.unwrap();
171
+
172
+ // // Init BigQuery client
173
+ // let bigquery_client =
174
+ // gcp_bigquery_client::Client::from_service_account_key(service_account_key, false)
175
+ // .await
176
+ // .unwrap();
125
177
126
178
// get scalar_types
127
179
@@ -221,6 +273,7 @@ pub async fn configure(
221
273
version : 1 ,
222
274
connection_settings : connection_settings:: DatabaseConnectionSettings {
223
275
service_key : args. connection_settings . service_key . clone ( ) ,
276
+ workload_identity_auth : args. connection_settings . workload_identity_auth . clone ( ) ,
224
277
project_id : args. connection_settings . project_id . clone ( ) ,
225
278
dataset_id : args. connection_settings . dataset_id . clone ( ) ,
226
279
} ,
0 commit comments