-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: make it running without GCP env #1471
Open
nicolasburtey
wants to merge
1
commit into
main
Choose a base branch
from
chore--make-it-running-without-GCP-env
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+52
−26
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
mod error; | ||
pub mod error; | ||
|
||
use error::ServiceAccountError; | ||
use gcp_bigquery_client::yup_oauth2::ServiceAccountKey; | ||
|
@@ -9,7 +9,7 @@ pub struct ServiceAccountConfig { | |
#[serde(skip)] | ||
pub gcp_project: String, | ||
#[serde(skip)] | ||
pub sa_creds_base64: String, | ||
pub sa_creds_base64: Option<String>, | ||
#[serde(skip)] | ||
service_account_key: Option<ServiceAccountKey>, | ||
|
||
|
@@ -21,7 +21,7 @@ impl Default for ServiceAccountConfig { | |
fn default() -> Self { | ||
Self { | ||
gcp_project: "".to_string(), | ||
sa_creds_base64: "".to_string(), | ||
sa_creds_base64: None, | ||
service_account_key: None, | ||
gcp_location: default_gcp_location(), | ||
} | ||
|
@@ -31,8 +31,14 @@ impl Default for ServiceAccountConfig { | |
impl ServiceAccountConfig { | ||
pub fn set_sa_creds_base64( | ||
mut self, | ||
sa_creds_base64: String, | ||
sa_creds_base64: Option<String>, | ||
) -> Result<Self, ServiceAccountError> { | ||
if sa_creds_base64.is_none() { | ||
return Ok(self); | ||
} | ||
|
||
println!("sa_creds_base64: {:?}", sa_creds_base64); | ||
|
||
self.sa_creds_base64 = sa_creds_base64; | ||
|
||
let creds = self.get_json_creds()?; | ||
|
@@ -48,19 +54,27 @@ impl ServiceAccountConfig { | |
Ok(self) | ||
} | ||
|
||
pub fn service_account_key(&self) -> ServiceAccountKey { | ||
pub fn service_account_key(&self) -> Result<ServiceAccountKey, ServiceAccountError> { | ||
self.service_account_key | ||
.clone() | ||
.expect("Service Account not set") | ||
.as_ref() | ||
.cloned() | ||
.ok_or(ServiceAccountError::CredentialsNotProvided) | ||
} | ||
|
||
pub fn get_json_creds(&self) -> Result<String, ServiceAccountError> { | ||
fn get_json_creds(&self) -> Result<String, ServiceAccountError> { | ||
if self.sa_creds_base64.is_none() { | ||
return Err(ServiceAccountError::CredentialsNotProvided); | ||
} | ||
|
||
let creds = self | ||
Comment on lines
+65
to
+68
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. redundant since |
||
.sa_creds_base64 | ||
.as_ref() | ||
.ok_or(ServiceAccountError::CredentialsNotProvided)? | ||
.as_bytes(); | ||
|
||
use base64::{engine::general_purpose, Engine as _}; | ||
|
||
Ok(std::str::from_utf8( | ||
&general_purpose::STANDARD.decode(self.sa_creds_base64.as_bytes())?, | ||
)? | ||
.to_string()) | ||
Ok(std::str::from_utf8(&general_purpose::STANDARD.decode(creds)?)?.to_string()) | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,21 +35,27 @@ struct Cli { | |
#[clap(env = "SUMSUB_SECRET", default_value = "")] | ||
sumsub_secret: String, | ||
#[clap(env = "SA_CREDS_BASE64", default_value = "")] | ||
sa_creds_base64: String, | ||
sa_creds_base64_raw: String, | ||
#[clap(env = "DEV_ENV_NAME_PREFIX")] | ||
dev_env_name_prefix: Option<String>, | ||
} | ||
|
||
pub async fn run() -> anyhow::Result<()> { | ||
let cli = Cli::parse(); | ||
|
||
let sa_creds_base64 = if cli.sa_creds_base64_raw.is_empty() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That this is optional should be handled in the cli field / clap attribute. |
||
None | ||
} else { | ||
Some(cli.sa_creds_base64_raw) | ||
}; | ||
|
||
let config = Config::init( | ||
cli.config, | ||
EnvSecrets { | ||
pg_con: cli.pg_con, | ||
sumsub_key: cli.sumsub_key, | ||
sumsub_secret: cli.sumsub_secret, | ||
sa_creds_base64: cli.sa_creds_base64, | ||
sa_creds_base64, | ||
}, | ||
cli.dev_env_name_prefix, | ||
)?; | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this intended ?