Skip to content
This repository has been archived by the owner on Sep 18, 2023. It is now read-only.

[WIP] experimantal: add ion channel experimental client #184

Closed
wants to merge 1 commit 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
1 change: 1 addition & 0 deletions extensions/cms/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ async-trait = "0.1.63"
clap = { version = "4.1.4", default-features = true, features = ["derive"] }
serde = { version = "1.0.92", features = ["derive"] }
serde_json = "1.0.87"
serde_with = "2.3.0"
thiserror = "1.0"
tokio = { version = "1.25.0", features = ["full"] }
uuid = { version = "1.2.2", features = ["serde", "v4"] }
Expand Down
52 changes: 52 additions & 0 deletions extensions/cms/src/commands/ionchannel.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
use crate::tasks::ionchannel::IonChannelTask;
use crate::Error;

use clap::Parser;
use harbcore::config::{ion_channel_org_id, ion_channel_token};
use harbcore::entities::tasks::Task;
use harbcore::tasks::TaskProvider;

/// Specifies the CLI args for the ionchannel command.
#[derive(Debug, Parser)]
pub struct IonChannelArgs {
/// Specifies to run the command against the local debug environment.
#[arg(short, long)]
debug: bool,
}

/// The Ion Channel Command handler.
pub async fn execute(args: &IonChannelArgs) -> Result<(), Error> {
let cx = match &args.debug {
false => harbcore::config::harbor_context().map_err(|e| Error::Config(e.to_string()))?,
true => harbcore::config::dev_context(None).map_err(|e| Error::Config(e.to_string()))?,
};

let token = ion_channel_token().map_err(|e| Error::Config(e.to_string()))?;
let org_id = ion_channel_org_id().map_err(|e| Error::Config(e.to_string()))?;

let mut task = Task::new(harbcore::entities::tasks::TaskKind::Extension(
"ion-channel::metrics".to_string(),
))
.map_err(|e| Error::IonChannel(e.to_string()))?;

let provider = IonChannelTask::new(cx, token, org_id)
.await
.map_err(|e| Error::IonChannel(e.to_string()))?;

provider
.execute(&mut task)
.await
.map_err(|e| Error::IonChannel(e.to_string()))
}

#[cfg(test)]
mod tests {
use super::*;
use crate::Error;

#[async_std::test]
#[ignore = "debug manual only"]
async fn can_execute() -> Result<(), Error> {
execute(&IonChannelArgs { debug: true }).await
}
}
3 changes: 3 additions & 0 deletions extensions/cms/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ pub mod fisma;

/// Handles exporting data to S3 for processing by the ETL backend.
pub mod export;

/// Handles synchronizing Ion Channel Metrics for the CMS Harbor Instance.
pub mod ionchannel;
6 changes: 6 additions & 0 deletions extensions/cms/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ pub enum Error {
/// Invalid subcommand.
#[error("invalid subcommand: {0}")]
InvalidSubcommand(String),
/// IonChannel provider error.
#[error("ion channel provider: {0}")]
IonChannel(String),
/// Serde error.
#[error("serde error: {0}")]
Serde(#[from] serde_json::Error),
/// Snyk service error.
#[error("snyk provider: {0}")]
Snyk(String),
Expand Down
Loading
Loading