Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,12 @@ pub enum ConnectionsCommands {
format: String,
},

/// Refresh a connection's schema
Refresh {
/// Connection ID
connection_id: String,
},

/// Delete a connection from a workspace
Delete {
/// Connection ID
Expand Down
49 changes: 49 additions & 0 deletions src/connections.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,3 +328,52 @@ pub fn list(workspace_id: &str, format: &str) {
_ => unreachable!(),
}
}

pub fn refresh(workspace_id: &str, connection_id: &str) {
let profile_config = match config::load("default") {
Ok(c) => c,
Err(e) => {
eprintln!("{e}");
std::process::exit(1);
}
};

let api_key = match &profile_config.api_key {
Some(key) if key != "PLACEHOLDER" => key.clone(),
_ => {
eprintln!("error: not authenticated. Run 'hotdata auth login' to log in.");
std::process::exit(1);
}
};

let body = serde_json::json!({
"connection_id": connection_id,
"data": false,
});

let url = format!("{}/refresh", profile_config.api_url);
let client = reqwest::blocking::Client::new();

let resp = match client
.post(&url)
.header("Authorization", format!("Bearer {api_key}"))
.header("X-Workspace-Id", workspace_id)
.json(&body)
.send()
{
Ok(r) => r,
Err(e) => {
eprintln!("error connecting to API: {e}");
std::process::exit(1);
}
};

if !resp.status().is_success() {
use crossterm::style::Stylize;
eprintln!("{}", crate::util::api_error(resp.text().unwrap_or_default()).red());
std::process::exit(1);
}

use crossterm::style::Stylize;
println!("{}", "Schema refresh completed.".green());
}
3 changes: 3 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ fn main() {
}
}
}
ConnectionsCommands::Refresh { connection_id } => {
connections::refresh(&workspace_id, &connection_id)
}
_ => eprintln!("not yet implemented"),
}
},
Expand Down
Loading