Skip to content

Commit 35e555b

Browse files
author
py
committed
format
1 parent 7abb235 commit 35e555b

File tree

3 files changed

+52
-46
lines changed

3 files changed

+52
-46
lines changed

crates/configuration/src/to_runtime_configuration.rs

+18-24
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@ pub fn make_runtime_configuration(
1616
environment: impl Environment,
1717
) -> Result<crate::Configuration, MakeRuntimeConfigurationError> {
1818
let auth: (bool, String) = match parsed_config.connection_settings.workload_identity_auth {
19-
Some(WorkloadIdentityAuth(Secret::Plain(key))) => {
20-
Ok((true, key))
21-
},
19+
Some(WorkloadIdentityAuth(Secret::Plain(key))) => Ok((true, key)),
2220
Some(WorkloadIdentityAuth(Secret::FromEnvironment { variable })) => {
2321
let variable_value = environment.read(&variable).map_err(|error| {
2422
MakeRuntimeConfigurationError::MissingEnvironmentVariable {
@@ -27,29 +25,25 @@ pub fn make_runtime_configuration(
2725
}
2826
})?;
2927
Ok((true, variable_value))
30-
},
31-
None => {
32-
match parsed_config.connection_settings.service_key {
33-
Some(ServiceKey(Secret::Plain(key))) => {
34-
Ok((false, key))
35-
},
36-
Some(ServiceKey(Secret::FromEnvironment { variable })) => {
37-
let variable_value = environment.read(&variable).map_err(|error| {
38-
MakeRuntimeConfigurationError::MissingEnvironmentVariable {
39-
file_path: super::version1::CONFIGURATION_FILENAME.into(),
40-
message: error.to_string(),
41-
}
42-
})?;
43-
Ok((false, variable_value))
44-
},
45-
None => {
46-
return Err(MakeRuntimeConfigurationError::MissingEnvironmentVariable {
28+
}
29+
None => match parsed_config.connection_settings.service_key {
30+
Some(ServiceKey(Secret::Plain(key))) => Ok((false, key)),
31+
Some(ServiceKey(Secret::FromEnvironment { variable })) => {
32+
let variable_value = environment.read(&variable).map_err(|error| {
33+
MakeRuntimeConfigurationError::MissingEnvironmentVariable {
4734
file_path: super::version1::CONFIGURATION_FILENAME.into(),
48-
message: "Neither Workload Identity Auth URL or Service key is provided".into(),
49-
});
50-
},
35+
message: error.to_string(),
36+
}
37+
})?;
38+
Ok((false, variable_value))
5139
}
52-
}
40+
None => {
41+
return Err(MakeRuntimeConfigurationError::MissingEnvironmentVariable {
42+
file_path: super::version1::CONFIGURATION_FILENAME.into(),
43+
message: "Neither Workload Identity Auth URL or Service key is provided".into(),
44+
});
45+
}
46+
},
5347
}?;
5448

5549
let project_id = match parsed_config.connection_settings.project_id {

crates/configuration/src/version1.rs

+31-21
Original file line numberDiff line numberDiff line change
@@ -98,30 +98,40 @@ pub async fn configure(
9898
Some(WorkloadIdentityAuth(Secret::Plain(value))) => {
9999
let url = Cow::Borrowed(value);
100100
std::env::set_var("BIG_QUERY_AUTH_URL", url.as_ref());
101-
gcp_bigquery_client::Client::with_workload_identity(false).await.unwrap()
102-
},
101+
gcp_bigquery_client::Client::with_workload_identity(false)
102+
.await
103+
.unwrap()
104+
}
103105
Some(WorkloadIdentityAuth(Secret::FromEnvironment { variable })) => {
104106
let url: Cow<'_, String> = Cow::Owned(environment.read(variable)?);
105107
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-
}
108+
gcp_bigquery_client::Client::with_workload_identity(false)
109+
.await
110+
.unwrap()
124111
}
112+
None => match &args.connection_settings.service_key {
113+
Some(ServiceKey(Secret::Plain(value))) => {
114+
let service_key = Cow::Borrowed(value);
115+
let service_account_key =
116+
yup_oauth2::parse_service_account_key(service_key.as_str()).unwrap();
117+
gcp_bigquery_client::Client::from_service_account_key(service_account_key, false)
118+
.await
119+
.unwrap()
120+
}
121+
Some(ServiceKey(Secret::FromEnvironment { variable })) => {
122+
let service_key: Cow<'_, String> = Cow::Owned(environment.read(variable)?);
123+
let service_account_key =
124+
yup_oauth2::parse_service_account_key(service_key.as_str()).unwrap();
125+
gcp_bigquery_client::Client::from_service_account_key(service_account_key, false)
126+
.await
127+
.unwrap()
128+
}
129+
None => {
130+
return Err(anyhow::anyhow!(
131+
"Neither Workload Identity Auth URL or Service key is provided"
132+
));
133+
}
134+
},
125135
};
126136
// let service_key = match &args.connection_settings.service_key {
127137
// Some(ServiceKey(Secret::Plain(value))) => Cow::Borrowed(value),
@@ -165,7 +175,7 @@ pub async fn configure(
165175

166176
// std::env::set_var("BIG_QUERY_AUTH_URL", workload_identity_auth.as_ref());
167177

168-
// if
178+
// if
169179

170180
// let bigquery_client_auth = gcp_bigquery_client::Client::with_workload_identity(true).await.unwrap();
171181

crates/connectors/ndc-bigquery/src/state.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ pub async fn create_state(
3232
let bigquery_client = match &configuration.auth {
3333
(true, workload_identity_auth) => {
3434
std::env::set_var("BIG_QUERY_AUTH_URL", workload_identity_auth);
35-
gcp_bigquery_client::Client::with_workload_identity(false).await.unwrap()
35+
gcp_bigquery_client::Client::with_workload_identity(false)
36+
.await
37+
.unwrap()
3638
}
3739
(false, service_key) => {
3840
let service_account_key =

0 commit comments

Comments
 (0)