Skip to content

Commit

Permalink
feat(pipeline): data pipeline: areate encrypted archive (#34)
Browse files Browse the repository at this point in the history
- [x] encrypted archive creation for the data pipeline artifacts;
  • Loading branch information
rfprod authored Oct 24, 2023
1 parent 2aec817 commit 6db087a
Showing 1 changed file with 57 additions and 1 deletion.
58 changes: 57 additions & 1 deletion src/data_pipeline/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ impl DataPipeline {
total,
retry: false,
}
// result
}
};
});
Expand All @@ -159,6 +158,7 @@ impl DataPipeline {
continue;
} else {
println!("\n{}", "Download complete".green().bold());
self.create_artifact();
break;
}
}
Expand Down Expand Up @@ -347,4 +347,60 @@ impl DataPipeline {
}
result
}

fn create_artifact(&self) {
println!("\n{}", "Creating the artifact...".cyan().bold());
let cwd = env::current_dir().unwrap();
println!(
"\n{}:\n{:?}",
"The current directory is".cyan().bold(),
cwd.display()
);
let base_path = cwd.display().to_string() + "/.data/artifact/github/";
let create_dir_result = fs::create_dir_all(&base_path);
if let Ok(_tmp) = create_dir_result {
let source_path = cwd.display().to_string() + "/.data/output/github";
let output_path = base_path + "/github-repos.tar.gz";

Command::new("tar")
.args(["-czf", &output_path, &source_path])
.output()
.expect("Failed to create artifact");

println!(
"\n{}:\n{:?}",
"Created the archive".green().bold(),
output_path
);

let gpg_passphrase_env = env::var("GPG_PASSPHRASE");
let gpg_passphrase = match gpg_passphrase_env.unwrap().trim().parse::<String>() {
Ok(value) => value,
Err(_) => String::new(),
};

let encrypted_artifact_path = output_path.to_owned() + ".gpg";
Command::new("gpg")
.args([
"--batch",
"--yes",
"--passphrase",
&gpg_passphrase,
"--symmetric",
"--cipher-algo",
"aes256",
"--output",
&encrypted_artifact_path,
&output_path,
])
.output()
.expect("Failed to encrypt artifact");

println!(
"\n{}:\n{:?}",
"Encrypted the archive".green().bold(),
encrypted_artifact_path
);
}
}
}

0 comments on commit 6db087a

Please sign in to comment.