* 1.made load_credentials accept credential path as a parameter. 2.partial implement bigtable comparasion function
* finding missing blocks in bigtables in a specified range
* refactor compare-blocks,add unit test for missing_blocks and fmt
* compare-block fix last block bug
* refactor compare-block and improve wording
* Update ledger-tool/src/bigtable.rs
Co-authored-by: Tyera Eulberg <teulberg@gmail.com>
* update compare-block command-line description
* style:improve wording/naming/code style
Co-authored-by: Tyera Eulberg <teulberg@gmail.com>
(cherry picked from commit d9220652ad
)
Co-authored-by: pieceofr <komimi.p@gmail.com>
This commit is contained in:
@ -16,17 +16,15 @@ use {
|
||||
},
|
||||
};
|
||||
|
||||
fn load_credentials() -> Result<Credentials, String> {
|
||||
// Use standard GOOGLE_APPLICATION_CREDENTIALS environment variable
|
||||
let credentials_file = std::env::var("GOOGLE_APPLICATION_CREDENTIALS")
|
||||
.map_err(|_| "GOOGLE_APPLICATION_CREDENTIALS environment variable not found".to_string())?;
|
||||
|
||||
Credentials::from_file(&credentials_file).map_err(|err| {
|
||||
format!(
|
||||
"Failed to read GCP credentials from {}: {}",
|
||||
credentials_file, err
|
||||
)
|
||||
})
|
||||
fn load_credentials(filepath: Option<String>) -> Result<Credentials, String> {
|
||||
let path = match filepath {
|
||||
Some(f) => f,
|
||||
None => std::env::var("GOOGLE_APPLICATION_CREDENTIALS").map_err(|_| {
|
||||
"GOOGLE_APPLICATION_CREDENTIALS environment variable not found".to_string()
|
||||
})?,
|
||||
};
|
||||
Credentials::from_file(&path)
|
||||
.map_err(|err| format!("Failed to read GCP credentials from {}: {}", path, err))
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
@ -38,8 +36,8 @@ pub struct AccessToken {
|
||||
}
|
||||
|
||||
impl AccessToken {
|
||||
pub async fn new(scope: Scope) -> Result<Self, String> {
|
||||
let credentials = load_credentials()?;
|
||||
pub async fn new(scope: Scope, credential_filepath: Option<String>) -> Result<Self, String> {
|
||||
let credentials = load_credentials(credential_filepath)?;
|
||||
if let Err(err) = credentials.rsa_key() {
|
||||
Err(format!("Invalid rsa key: {}", err))
|
||||
} else {
|
||||
|
@ -125,6 +125,7 @@ impl BigTableConnection {
|
||||
instance_name: &str,
|
||||
read_only: bool,
|
||||
timeout: Option<Duration>,
|
||||
credential_path: Option<String>,
|
||||
) -> Result<Self> {
|
||||
match std::env::var("BIGTABLE_EMULATOR_HOST") {
|
||||
Ok(endpoint) => {
|
||||
@ -141,11 +142,14 @@ impl BigTableConnection {
|
||||
}
|
||||
|
||||
Err(_) => {
|
||||
let access_token = AccessToken::new(if read_only {
|
||||
Scope::BigTableDataReadOnly
|
||||
} else {
|
||||
Scope::BigTableData
|
||||
})
|
||||
let access_token = AccessToken::new(
|
||||
if read_only {
|
||||
Scope::BigTableDataReadOnly
|
||||
} else {
|
||||
Scope::BigTableData
|
||||
},
|
||||
credential_path,
|
||||
)
|
||||
.await
|
||||
.map_err(Error::AccessToken)?;
|
||||
|
||||
|
@ -345,9 +345,14 @@ pub struct LedgerStorage {
|
||||
}
|
||||
|
||||
impl LedgerStorage {
|
||||
pub async fn new(read_only: bool, timeout: Option<std::time::Duration>) -> Result<Self> {
|
||||
pub async fn new(
|
||||
read_only: bool,
|
||||
timeout: Option<std::time::Duration>,
|
||||
credential_path: Option<String>,
|
||||
) -> Result<Self> {
|
||||
let connection =
|
||||
bigtable::BigTableConnection::new("solana-ledger", read_only, timeout).await?;
|
||||
bigtable::BigTableConnection::new("solana-ledger", read_only, timeout, credential_path)
|
||||
.await?;
|
||||
Ok(Self { connection })
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user