Skip to content

Commit

Permalink
add(hub-util): sdf endpoint consts and refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
digikata committed Jun 4, 2024
1 parent df884e4 commit 02b19f5
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
11 changes: 11 additions & 0 deletions crates/fluvio-hub-protocol/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ pub const HUB_API_LIST_META: &str = concatcp!(HUB_API_V, "/list_with_meta");
pub const HUB_API_CONN_PKG: &str = concatcp!(HUB_API_V, "/connector/pkg");
pub const HUB_API_CONN_LIST: &str = concatcp!(HUB_API_V, "/connector/list");

// sdf specific api
pub const HUB_API_SDF_PKG: &str = concatcp!(HUB_API_V, "/sdf/pkg");
pub const HUB_API_SDF_LIST: &str = concatcp!(HUB_API_V, "/sdf/list");
pub const HUB_API_SDF_PKG_PUB: &str = concatcp!(HUB_API_V, "/sdf/pkg/pub/pkg");
pub const HUB_API_SDF_DATAFLOW_PUB: &str = concatcp!(HUB_API_V, "/sdf/pkg/pub/dataflow");

pub const HUB_MANIFEST_BLOB: &str = "manifest.tar.gz";
pub const HUB_PACKAGE_EXT: &str = "ipkg";
pub const HUB_PACKAGE_META: &str = "package-meta.yaml";
Expand All @@ -27,3 +33,8 @@ pub const HUB_SIGNFILE_BASE: &str = "signature";
pub const DEF_CARGO_TOML_PATH: &str = "Cargo.toml";
pub const DEF_HUB_INIT_DIR: &str = ".hub";
pub const DEF_HUB_PKG_META: &str = concatcp!(DEF_HUB_INIT_DIR, "/", HUB_PACKAGE_META); // .hub/package-meta.yaml

// This is required in sdf hub package_meta manifests
pub const SDF_PKG_KIND: &str = "sdf-kind";
pub const SDF_PKG_KIND_DATAFLOW: &str = "dataflow";
pub const SDF_PKG_KIND_PACKAGE: &str = "pkg";
28 changes: 28 additions & 0 deletions crates/fluvio-hub-util/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,34 @@ pub async fn push_package_conn(pkgpath: &str, access: &HubAccess, target: &str)
push_package_api(&url, pkgpath, access).await
}

/// push package to connector api
pub async fn push_package_sdf(pkgpath: &str, access: &HubAccess, target: &str) -> Result<()> {
use crate::{
SDF_PKG_KIND, SDF_PKG_KIND_DATAFLOW, SDF_PKG_KIND_PACKAGE, HUB_API_SDF_DATAFLOW_PUB,
HUB_API_SDF_PKG_PUB,
};

info!("sdf package target: {target}");
let pm = package_get_meta(pkgpath)?;
let Some(sdf_kind) = pm.tag_get(SDF_PKG_KIND) else {
let msg = format!("Invalid sdf hub package_meta: missing tag for {SDF_PKG_KIND}");
return Err(HubError::PackagePublish(msg));
};
let sdf_kind = sdf_kind.first().cloned().unwrap_or_default().value;
let endpoint = match sdf_kind.as_str() {
SDF_PKG_KIND_DATAFLOW => HUB_API_SDF_DATAFLOW_PUB,
SDF_PKG_KIND_PACKAGE => HUB_API_SDF_PKG_PUB,
_ => {
let msg = format!("Invalid sdf hub package_meta {SDF_PKG_KIND}: {sdf_kind}");
return Err(HubError::PackagePublish(msg));
}
};
let host = &access.remote;
let url = format!("{host}/{endpoint}/{}/{}/{}", pm.group, pm.name, pm.version);
debug!(url, "package url");
push_package_api(&url, pkgpath, access).await
}

pub async fn push_package_api(put_url: &str, pkgpath: &str, access: &HubAccess) -> Result<()> {
let pm = package_get_meta(pkgpath)?;
packagename_validate(&pm.name)?;
Expand Down

0 comments on commit 02b19f5

Please sign in to comment.