-
Notifications
You must be signed in to change notification settings - Fork 486
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move hub connector commands to fluvio-hub-util
- Loading branch information
1 parent
bf4e866
commit d3063ce
Showing
12 changed files
with
75 additions
and
82 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
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 |
---|---|---|
|
@@ -3,15 +3,17 @@ use std::sync::Arc; | |
use std::fmt::Debug; | ||
|
||
use clap::Parser; | ||
use anyhow::Result; | ||
use anyhow::{Result, anyhow}; | ||
|
||
use fluvio_extension_common::Terminal; | ||
|
||
use crate::error::CliError; | ||
use crate::{cli_pkgname_to_filename, cli_conn_pkgname_to_url, get_package}; | ||
|
||
use super::get_hub_access; | ||
|
||
/// Download SmartConnector to the local folder | ||
#[derive(Debug, Parser)] | ||
#[command(arg_required_else_help = true)] | ||
pub struct ConnectorHubDownloadOpts { | ||
/// SmartConnector name: e.g. infinyon/[email protected] | ||
#[arg(value_name = "name", required = true)] | ||
|
@@ -37,10 +39,8 @@ impl ConnectorHubDownloadOpts { | |
let access = get_hub_access(&self.remote)?; | ||
|
||
let package_name = self.package_name; | ||
let file_name = fluvio_hub_util::cli_pkgname_to_filename(&package_name).map_err(|_| { | ||
CliError::HubError(format!( | ||
"invalid package name format {package_name}, is it the form infinyon/[email protected]" | ||
)) | ||
let file_name = cli_pkgname_to_filename(&package_name).map_err(|_| { | ||
anyhow!("invalid package name format {package_name}, is it the form infinyon/[email protected]") | ||
})?; | ||
|
||
let file_path = if let Some(mut output) = self.output { | ||
|
@@ -51,26 +51,18 @@ impl ConnectorHubDownloadOpts { | |
} else { | ||
PathBuf::from(file_name) | ||
}; | ||
println!( | ||
"downloading {package_name} to {}", | ||
file_path.to_string_lossy() | ||
); | ||
let path = file_path.to_string_lossy(); | ||
println!("downloading {package_name} to {path}"); | ||
|
||
let url = | ||
fluvio_hub_util::cli_conn_pkgname_to_url(&package_name, &access.remote, &self.target) | ||
.map_err(|_| CliError::HubError(format!("invalid pkgname {package_name}")))?; | ||
let url = cli_conn_pkgname_to_url(&package_name, &access.remote, &self.target) | ||
.map_err(|_| anyhow!("invalid pkgname {package_name}"))?; | ||
|
||
let data = fluvio_hub_util::get_package(&url, &access) | ||
let data = get_package(&url, &access) | ||
.await | ||
.map_err(|err| { | ||
CliError::HubError(format!("downloading {package_name} failed\nServer: {err}")) | ||
})?; | ||
.map_err(|err| anyhow!("downloading {package_name} failed\nServer: {err}"))?; | ||
|
||
std::fs::write(file_path, data).map_err(|err| { | ||
CliError::Other(format!( | ||
"unable to write downloaded package to the disk: {err}" | ||
)) | ||
})?; | ||
std::fs::write(file_path, data) | ||
.map_err(|err| anyhow!("unable to write downloaded package to the disk: {err}"))?; | ||
println!("... downloading complete"); | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
mod list; | ||
mod download; | ||
|
||
pub use list::ConnectorHubListOpts; | ||
pub use download::ConnectorHubDownloadOpts; | ||
use crate::HubAccess; | ||
use crate::PackageListMeta; | ||
|
||
use anyhow::Result; | ||
use anyhow::anyhow; | ||
|
||
pub fn get_hub_access(remote: &Option<String>) -> Result<HubAccess> { | ||
HubAccess::default_load(remote) | ||
.map_err(|_| anyhow!("missing access credentials, try 'fluvio cloud login'")) | ||
} | ||
|
||
pub async fn get_pkg_list(endpoint: &str, remote: &Option<String>) -> Result<PackageListMeta> { | ||
use crate::http; | ||
|
||
let access = get_hub_access(remote)?; | ||
|
||
let action_token = access | ||
.get_list_token() | ||
.await | ||
.map_err(|_| anyhow!("rejected access credentials, try 'fluvio cloud login'"))?; | ||
let url = format!("{}/{endpoint}", &access.remote); | ||
let mut res = http::get(&url) | ||
.header("Authorization", &action_token) | ||
.await | ||
.map_err(|e| anyhow!("list api access error {e}"))?; | ||
res.body_json() | ||
.await | ||
.map_err(|e| anyhow!("list api data parse error {e}")) | ||
} |
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