Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Merged by Bors] - feat: fluvio connector support update #2992

Closed
wants to merge 4 commits into from
Closed
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
19 changes: 18 additions & 1 deletion crates/fluvio-connector-package/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,12 @@ impl ConnectorConfig {
let mut file = File::open(path.into())?;
let mut contents = String::new();
file.read_to_string(&mut contents)?;
let mut connector_config: Self = serde_yaml::from_str(&contents)?;
ConnectorConfig::config_from_str(&contents)
}

/// Only parses the meta section of the config
pub fn config_from_str(config_str: &str) -> Result<Self> {
let mut connector_config: Self = serde_yaml::from_str(config_str)?;
connector_config.normalize_batch_size()?;

debug!("Using connector config {connector_config:#?}");
Expand Down Expand Up @@ -632,4 +637,16 @@ mod tests {
BTreeMap::from([("regex".to_string(), "\\w".into())])
);
}

#[test]
fn sample_yaml_test_files() {
let testfiles = vec!["tests/sample-http.yaml", "tests/sample-mqtt.yaml"];

for tfile in testfiles {
let res = ConnectorConfig::from_file(tfile);
assert!(res.is_ok(), "failed to load {tfile}");
let connector_cfg = res.unwrap();
println!("{tfile}: {connector_cfg:?}");
}
}
}
10 changes: 10 additions & 0 deletions crates/fluvio-connector-package/tests/sample-http.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
meta:
version: latest
name: cat-facts
type: http-source
topic: cat-facts
create-topic: true
http:
endpoint: "https://catfact.ninja/fact"
interval: 10s

15 changes: 15 additions & 0 deletions crates/fluvio-connector-package/tests/sample-mqtt.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
meta:
version: latest
name: my-mqtt-connector
type: mqtt-source
topic: mqtt-topic
create-topic: true
mqtt:
url: "mqtt://test.mosquitto.org/"
topic: "mqtt-to-fluvio"
client_id: "my_mqtt"
timeout:
secs: 30
nanos: 0
payload_output_type: json

4 changes: 4 additions & 0 deletions crates/fluvio-hub-util/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ pub fn cli_pkgname_to_filename(pkgname: &str) -> Result<String> {
/// returns recommended name and data
pub async fn get_package(pkgurl: &str, access: &HubAccess) -> Result<Vec<u8>> {
let actiontoken = access.get_download_token().await?;
get_package_with_token(pkgurl, &actiontoken).await
}

pub async fn get_package_with_token(pkgurl: &str, actiontoken: &str) -> Result<Vec<u8>> {
let mut resp = surf::get(pkgurl)
.header("Authorization", actiontoken)
.await
Expand Down