Skip to content

Commit

Permalink
chore: add basic auth support to cli export
Browse files Browse the repository at this point in the history
  • Loading branch information
shuiyisong committed Oct 18, 2023
1 parent ca7a4af commit 4765673
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/cmd/src/cli/export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ use std::sync::Arc;

use async_trait::async_trait;
use clap::{Parser, ValueEnum};
use client::api::v1::auth_header::AuthScheme;
use client::api::v1::Basic;
use client::{Client, Database, DEFAULT_SCHEMA_NAME};
use common_query::Output;
use common_recordbatch::util::collect;
Expand All @@ -32,7 +34,8 @@ use tokio::sync::Semaphore;
use crate::cli::{Instance, Tool};
use crate::error::{
CollectRecordBatchesSnafu, ConnectServerSnafu, EmptyResultSnafu, Error, FileIoSnafu,
InvalidDatabaseNameSnafu, NotDataFromOutputSnafu, RequestDatabaseSnafu, Result,
IllegalConfigSnafu, InvalidDatabaseNameSnafu, NotDataFromOutputSnafu, RequestDatabaseSnafu,
Result,
};

type TableReference = (String, String, String);
Expand Down Expand Up @@ -71,6 +74,10 @@ pub struct ExportCommand {
/// Things to export
#[clap(long, short = 't', value_enum)]
target: ExportTarget,

/// basic authentication for connecting to the server
#[clap(long)]
auth_basic: Option<String>,
}

impl ExportCommand {
Expand All @@ -83,12 +90,22 @@ impl ExportCommand {
addr: self.addr.clone(),
})?;
let (catalog, schema) = split_database(&self.database)?;
let database_client = Database::new(
let mut database_client = Database::new(
catalog.clone(),
schema.clone().unwrap_or(DEFAULT_SCHEMA_NAME.to_string()),
client,
);

if let Some(auth_basic) = &self.auth_basic {
let (username, password) = auth_basic.split_once(':').context(IllegalConfigSnafu {
msg: "auth_basic cannot be split by ':'".to_string(),
})?;
database_client.set_auth(AuthScheme::Basic(Basic {
username: username.to_string(),
password: password.to_string(),
}));
}

Ok(Instance::Tool(Box::new(Export {
client: database_client,
catalog,
Expand Down

0 comments on commit 4765673

Please sign in to comment.