-
Notifications
You must be signed in to change notification settings - Fork 332
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* new subcommand for "export" in CLI * new cmd submodule for exporting config tarballs * logic to also output to stdout * README additions * limitations documented Signed-off-by: Ava Hahn <[email protected]>
- Loading branch information
Showing
7 changed files
with
130 additions
and
22 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,52 @@ | ||
use crate::unitctl::UnitCtl; | ||
use crate::wait; | ||
use crate::UnitctlError; | ||
use crate::requests::send_empty_body_deserialize_response; | ||
use unit_client_rs::unit_client::UnitClient; | ||
use tar::{Builder, Header}; | ||
use std::fs::File; | ||
use std::io::stdout; | ||
|
||
|
||
pub async fn cmd( | ||
cli: &UnitCtl, | ||
filename: &String | ||
) -> Result<(), UnitctlError> { | ||
if !filename.ends_with(".tar") { | ||
eprintln!("Warning: writing uncompressed tarball to {}", filename); | ||
} | ||
|
||
let control_socket = wait::wait_for_socket(cli).await?; | ||
let client = UnitClient::new(control_socket); | ||
|
||
let config_res = serde_json::to_string_pretty( | ||
&send_empty_body_deserialize_response(&client, "GET", "/config").await? | ||
); | ||
if let Err(e) = config_res { | ||
return Err(UnitctlError::DeserializationError{message: e.to_string()}) | ||
} | ||
|
||
let current_config = config_res | ||
.unwrap() | ||
.into_bytes(); | ||
|
||
//let current_js_modules = send_empty_body_deserialize_response(&client, "GET", "/js_modules") | ||
// .await?; | ||
|
||
let mut conf_header = Header::new_gnu(); | ||
conf_header.set_size(current_config.len() as u64); | ||
conf_header.set_mode(0o644); | ||
conf_header.set_cksum(); | ||
|
||
// builder has a different type depending on output | ||
if filename == "-" { | ||
let mut ar = Builder::new(stdout()); | ||
ar.append_data(&mut conf_header, "config.json", current_config.as_slice()).unwrap(); | ||
} else { | ||
let file = File::create(filename).unwrap(); | ||
let mut ar = Builder::new(file); | ||
ar.append_data(&mut conf_header, "config.json", current_config.as_slice()).unwrap(); | ||
} | ||
|
||
Ok(()) | ||
} |
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