File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -384,6 +384,12 @@ pub enum ConnectionsCommands {
384384 format : String ,
385385 } ,
386386
387+ /// Refresh a connection's schema
388+ Refresh {
389+ /// Connection ID
390+ connection_id : String ,
391+ } ,
392+
387393 /// Delete a connection from a workspace
388394 Delete {
389395 /// Connection ID
Original file line number Diff line number Diff line change @@ -328,3 +328,52 @@ pub fn list(workspace_id: &str, format: &str) {
328328 _ => unreachable ! ( ) ,
329329 }
330330}
331+
332+ pub fn refresh ( workspace_id : & str , connection_id : & str ) {
333+ let profile_config = match config:: load ( "default" ) {
334+ Ok ( c) => c,
335+ Err ( e) => {
336+ eprintln ! ( "{e}" ) ;
337+ std:: process:: exit ( 1 ) ;
338+ }
339+ } ;
340+
341+ let api_key = match & profile_config. api_key {
342+ Some ( key) if key != "PLACEHOLDER" => key. clone ( ) ,
343+ _ => {
344+ eprintln ! ( "error: not authenticated. Run 'hotdata auth login' to log in." ) ;
345+ std:: process:: exit ( 1 ) ;
346+ }
347+ } ;
348+
349+ let body = serde_json:: json!( {
350+ "connection_id" : connection_id,
351+ "data" : false ,
352+ } ) ;
353+
354+ let url = format ! ( "{}/refresh" , profile_config. api_url) ;
355+ let client = reqwest:: blocking:: Client :: new ( ) ;
356+
357+ let resp = match client
358+ . post ( & url)
359+ . header ( "Authorization" , format ! ( "Bearer {api_key}" ) )
360+ . header ( "X-Workspace-Id" , workspace_id)
361+ . json ( & body)
362+ . send ( )
363+ {
364+ Ok ( r) => r,
365+ Err ( e) => {
366+ eprintln ! ( "error connecting to API: {e}" ) ;
367+ std:: process:: exit ( 1 ) ;
368+ }
369+ } ;
370+
371+ if !resp. status ( ) . is_success ( ) {
372+ use crossterm:: style:: Stylize ;
373+ eprintln ! ( "{}" , crate :: util:: api_error( resp. text( ) . unwrap_or_default( ) ) . red( ) ) ;
374+ std:: process:: exit ( 1 ) ;
375+ }
376+
377+ use crossterm:: style:: Stylize ;
378+ println ! ( "{}" , "Schema refresh completed." . green( ) ) ;
379+ }
Original file line number Diff line number Diff line change @@ -134,6 +134,9 @@ fn main() {
134134 }
135135 }
136136 }
137+ ConnectionsCommands :: Refresh { connection_id } => {
138+ connections:: refresh ( & workspace_id, & connection_id)
139+ }
137140 _ => eprintln ! ( "not yet implemented" ) ,
138141 }
139142 } ,
You can’t perform that action at this time.
0 commit comments