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

Commit

Permalink
fix: correct copy pasta error in export command handler (#178)
Browse files Browse the repository at this point in the history
  • Loading branch information
DerekStrickland committed Aug 22, 2023
1 parent 5bd2bd2 commit 4c634c6
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 12 deletions.
41 changes: 29 additions & 12 deletions extensions/cms/src/commands/export.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
use clap::Parser;
use harbcore::entities::tasks::{Task, TaskKind};
use harbcore::services::analytics::{
FileSystemStorageProvider, S3StorageProvider, StorageProvider,
};
use harbcore::tasks::TaskProvider;
use platform::persistence::mongodb::Store;
use std::sync::Arc;

use crate::tasks::fisma::FismaTask;
use crate::tasks::export::{ExportService, ExportTask};
use crate::Error;

/// Specifies the CLI args for the Export command.
Expand All @@ -15,26 +20,38 @@ pub struct ExportArgs {

/// The Export Command handler.
pub async fn execute(args: &ExportArgs) -> Result<(), Error> {
let storage: Arc<dyn StorageProvider>;

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()))?,
false => {
storage = Arc::new(S3StorageProvider {});
harbcore::config::harbor_context().map_err(|e| Error::Config(e.to_string()))?
}
true => {
storage = Arc::new(FileSystemStorageProvider::new(
"/tmp/harbor-debug/extensions/export".to_string(),
));
harbcore::config::dev_context(None).map_err(|e| Error::Config(e.to_string()))?
}
};

let token = std::env::var("SNYK_TOKEN")
.map_err(|e| Error::Config(e.to_string()))
.unwrap();
let store = Arc::new(
Store::new(&cx)
.await
.map_err(|e| Error::Export(e.to_string()))?,
);

let mut task = Task::new(TaskKind::Extension("fisma".to_string()))
.map_err(|e| Error::Fisma(e.to_string()))?;
let service = ExportService::new(store, storage);

let provider = FismaTask::new(cx, token)
.await
.map_err(|e| Error::Fisma(e.to_string()))?;
let mut task = Task::new(TaskKind::Extension("export".to_string()))
.map_err(|e| Error::Export(e.to_string()))?;

let provider = ExportTask::new(service);

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

#[cfg(test)]
Expand Down
3 changes: 3 additions & 0 deletions extensions/cms/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ pub enum Error {
/// Configuration error.
#[error("config: {0}")]
Config(String),
/// Export provider error.
#[error("fisma provider: {0}")]
Export(String),
/// Fisma provider error.
#[error("fisma provider: {0}")]
Fisma(String),
Expand Down

0 comments on commit 4c634c6

Please sign in to comment.