Skip to content

Commit

Permalink
auto
Browse files Browse the repository at this point in the history
  • Loading branch information
bestia.dev committed Apr 22, 2024
1 parent 5930e47 commit 625809b
Show file tree
Hide file tree
Showing 19 changed files with 923 additions and 92 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cargo-auto"
version = "2024.422.15"
version = "2024.422.132"
authors = ["bestia.dev"]
homepage = "https://bestia.dev"
edition = "2021"
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
[//]: # (auto_cargo_toml_to_md start)

**Automation tasks coded in Rust language for the workflow of Rust projects**
***version: 2024.422.15 date: 2024-04-22 author: [bestia.dev](https://bestia.dev) repository: [GitHub](https://github.com/automation-tasks-rs/cargo-auto)***
***version: 2024.422.132 date: 2024-04-22 author: [bestia.dev](https://bestia.dev) repository: [GitHub](https://github.com/automation-tasks-rs/cargo-auto)***

![maintained](https://img.shields.io/badge/maintained-green)
![ready-for-use](https://img.shields.io/badge/ready_for_use-green)
Expand All @@ -28,11 +28,11 @@
![cargo-auto](https://bestia.dev/webpage_hit_counter/get_svg_image/959103982.svg)

[//]: # (auto_lines_of_code start)
[![Lines in Rust code](https://img.shields.io/badge/Lines_in_Rust-3142-green.svg)](https://github.com/automation-tasks-rs/cargo-auto/)
[![Lines in Doc comments](https://img.shields.io/badge/Lines_in_Doc_comments-1191-blue.svg)](https://github.com/automation-tasks-rs/cargo-auto/)
[![Lines in Rust code](https://img.shields.io/badge/Lines_in_Rust-3141-green.svg)](https://github.com/automation-tasks-rs/cargo-auto/)
[![Lines in Doc comments](https://img.shields.io/badge/Lines_in_Doc_comments-1950-blue.svg)](https://github.com/automation-tasks-rs/cargo-auto/)
[![Lines in Comments](https://img.shields.io/badge/Lines_in_comments-704-purple.svg)](https://github.com/automation-tasks-rs/cargo-auto/)
[![Lines in examples](https://img.shields.io/badge/Lines_in_examples-0-yellow.svg)](https://github.com/automation-tasks-rs/cargo-auto/)
[![Lines in tests](https://img.shields.io/badge/Lines_in_tests-10869-orange.svg)](https://github.com/automation-tasks-rs/cargo-auto/)
[![Lines in tests](https://img.shields.io/badge/Lines_in_tests-10898-orange.svg)](https://github.com/automation-tasks-rs/cargo-auto/)

[//]: # (auto_lines_of_code end)

Expand Down
2 changes: 2 additions & 0 deletions RELEASES.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ The TODO section is part of the [README.md](https://github.com/automation-tasks-

## Unreleased

- auto

## Version 2024.419.1824 (2024-04-19)

- no log file for tracing
Expand Down
1 change: 1 addition & 0 deletions automation_tasks_rs/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ Cargo.lock

# not needed in commits, but also not a problem if they are committed
/.file_hashes.json
/.old_metadata.json
4 changes: 2 additions & 2 deletions automation_tasks_rs/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ fn task_release() {
{YELLOW}1. Check if the template `new_cli` is working. Open a new terminal in VSCode and run:{RESET}
{GREEN}cd ~/rustprojects{RESET}
{GREEN}./cargo-auto/target/release/{package_name} new_cli hello_world bestia.dev;{RESET}
{GREEN}./cargo-auto/target/release/{package_name} new_cli hello_world bestia-dev;{RESET}
{GREEN}code hello_world{RESET}
{YELLOW}In the new VSCODE window terminal, first change in Cargo.toml/repository from "github_owner" to your github username.{RESET}
{YELLOW} Then try the workflow: cargo auto build, cargo auto release, cargo auto doc,... all to the end.{RESET}
Expand All @@ -286,7 +286,7 @@ fn task_release() {
{YELLOW}2. Check if the template `new_wasm` is working. Open a new terminal in VSCode and run:{RESET}
{GREEN}cd ~/rustprojects{RESET}
{GREEN}./cargo-auto/target/release/{package_name} new_wasm hello_world bestia.dev luciano_bestia;{RESET}
{GREEN}./cargo-auto/target/release/{package_name} new_wasm hello_world bestia-dev bestia.dev luciano_bestia;{RESET}
{GREEN}code hello_world{RESET}
{YELLOW}In the new VSCODE window terminal, first change in Cargo.toml/repository from "github_owner" to your github username.{RESET}
{YELLOW} Then try the workflow: cargo auto build, cargo auto release, cargo auto doc,... all to the end.{RESET}
Expand Down
10 changes: 5 additions & 5 deletions src/bin/cargo-auto/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//! # cargo-auto
//!
//! **Automation tasks coded in Rust language for the workflow of Rust projects**
//! ***version: 2024.419.1824 date: 2024-04-19 author: [bestia.dev](https://bestia.dev) repository: [GitHub](https://github.com/automation-tasks-rs/cargo-auto)***
//! ***version: 2024.422.132 date: 2024-04-22 author: [bestia.dev](https://bestia.dev) repository: [GitHub](https://github.com/automation-tasks-rs/cargo-auto)***
//!
//! ![maintained](https://img.shields.io/badge/maintained-green)
//! ![ready-for-use](https://img.shields.io/badge/ready_for_use-green)
Expand All @@ -26,11 +26,11 @@
//! [![Newest docs](https://img.shields.io/badge/newest_docs-blue.svg)](https://automation-tasks-rs.github.io/cargo-auto/cargo_auto/index.html)
//! ![cargo-auto](https://bestia.dev/webpage_hit_counter/get_svg_image/959103982.svg)
//!
//! [![Lines in Rust code](https://img.shields.io/badge/Lines_in_Rust-3106-green.svg)](https://github.com/automation-tasks-rs/cargo-auto/)
//! [![Lines in Doc comments](https://img.shields.io/badge/Lines_in_Doc_comments-1191-blue.svg)](https://github.com/automation-tasks-rs/cargo-auto/)
//! [![Lines in Comments](https://img.shields.io/badge/Lines_in_comments-699-purple.svg)](https://github.com/automation-tasks-rs/cargo-auto/)
//! [![Lines in Rust code](https://img.shields.io/badge/Lines_in_Rust-3141-green.svg)](https://github.com/automation-tasks-rs/cargo-auto/)
//! [![Lines in Doc comments](https://img.shields.io/badge/Lines_in_Doc_comments-1950-blue.svg)](https://github.com/automation-tasks-rs/cargo-auto/)
//! [![Lines in Comments](https://img.shields.io/badge/Lines_in_comments-704-purple.svg)](https://github.com/automation-tasks-rs/cargo-auto/)
//! [![Lines in examples](https://img.shields.io/badge/Lines_in_examples-0-yellow.svg)](https://github.com/automation-tasks-rs/cargo-auto/)
//! [![Lines in tests](https://img.shields.io/badge/Lines_in_tests-10704-orange.svg)](https://github.com/automation-tasks-rs/cargo-auto/)
//! [![Lines in tests](https://img.shields.io/badge/Lines_in_tests-10898-orange.svg)](https://github.com/automation-tasks-rs/cargo-auto/)
//!
//! Hashtags: #maintained #ready-for-use #rustlang #automation #workflow
//! My projects on GitHub are more like a tutorial than a finished product: [bestia-dev tutorials](https://github.com/bestia-dev/tutorials_rust_wasm).
Expand Down
10 changes: 5 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//! # cargo-auto
//!
//! **Automation tasks coded in Rust language for the workflow of Rust projects**
//! ***version: 2024.419.1824 date: 2024-04-19 author: [bestia.dev](https://bestia.dev) repository: [GitHub](https://github.com/automation-tasks-rs/cargo-auto)***
//! ***version: 2024.422.132 date: 2024-04-22 author: [bestia.dev](https://bestia.dev) repository: [GitHub](https://github.com/automation-tasks-rs/cargo-auto)***
//!
//! ![maintained](https://img.shields.io/badge/maintained-green)
//! ![ready-for-use](https://img.shields.io/badge/ready_for_use-green)
Expand All @@ -26,11 +26,11 @@
//! [![Newest docs](https://img.shields.io/badge/newest_docs-blue.svg)](https://automation-tasks-rs.github.io/cargo-auto/cargo_auto/index.html)
//! ![cargo-auto](https://bestia.dev/webpage_hit_counter/get_svg_image/959103982.svg)
//!
//! [![Lines in Rust code](https://img.shields.io/badge/Lines_in_Rust-3106-green.svg)](https://github.com/automation-tasks-rs/cargo-auto/)
//! [![Lines in Doc comments](https://img.shields.io/badge/Lines_in_Doc_comments-1191-blue.svg)](https://github.com/automation-tasks-rs/cargo-auto/)
//! [![Lines in Comments](https://img.shields.io/badge/Lines_in_comments-699-purple.svg)](https://github.com/automation-tasks-rs/cargo-auto/)
//! [![Lines in Rust code](https://img.shields.io/badge/Lines_in_Rust-3141-green.svg)](https://github.com/automation-tasks-rs/cargo-auto/)
//! [![Lines in Doc comments](https://img.shields.io/badge/Lines_in_Doc_comments-1950-blue.svg)](https://github.com/automation-tasks-rs/cargo-auto/)
//! [![Lines in Comments](https://img.shields.io/badge/Lines_in_comments-704-purple.svg)](https://github.com/automation-tasks-rs/cargo-auto/)
//! [![Lines in examples](https://img.shields.io/badge/Lines_in_examples-0-yellow.svg)](https://github.com/automation-tasks-rs/cargo-auto/)
//! [![Lines in tests](https://img.shields.io/badge/Lines_in_tests-10704-orange.svg)](https://github.com/automation-tasks-rs/cargo-auto/)
//! [![Lines in tests](https://img.shields.io/badge/Lines_in_tests-10898-orange.svg)](https://github.com/automation-tasks-rs/cargo-auto/)
//!
//! Hashtags: #maintained #ready-for-use #rustlang #automation #workflow
//! My projects on GitHub are more like a tutorial than a finished product: [bestia-dev tutorials](https://github.com/bestia-dev/tutorials_rust_wasm).
Expand Down
44 changes: 28 additions & 16 deletions src/template_new_auto_mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -783,18 +783,7 @@ pub(crate) mod ssh_mod {
)
}
let identity_private_file_path_expanded = cargo_auto_encrypt_secret_lib::file_path_home_expand(identity_private_file_path);
if !camino::Utf8Path::new(&identity_private_file_path_expanded).exists() {
eprintln!("{RED}Identity file {identity_private_file_path_expanded} that contains the SSH private key does not exist! {RESET}");
eprintln!(" {YELLOW}Create the SSH key manually in bash with this command:{RESET}");
if identity_private_file_path_expanded.as_str().contains("github_api") {
eprintln!(r#"{GREEN}ssh-keygen -t ed25519 -f \"{identity_private_file_path_expanded}\" -C \"github api token\"{RESET}"#);
} else if identity_private_file_path_expanded.as_str().contains("github_api") {
eprintln!(r#"{GREEN}ssh-keygen -t ed25519 -f \"{identity_private_file_path_expanded}\" -C \"crates io token\"{RESET}"#);
}
eprintln!(" ");
panic!("{RED}Error: File {identity_private_file_path_expanded} does not exist! {RESET}");
}
let identity_private_file_path_expanded = expand_path_check_private_key_exists(identity_private_file_path);
let fingerprint_from_file = cargo_auto_encrypt_secret_lib::get_fingerprint_from_file(&identity_private_file_path_expanded);
Expand Down Expand Up @@ -829,6 +818,24 @@ pub(crate) mod ssh_mod {
}
}
}
/// Expand path and check if identity file exists
///
/// Inform the user how to generate identity file.
pub fn expand_path_check_private_key_exists(identity_private_file_path: &camino::Utf8Path) -> camino::Utf8PathBuf {
let identity_private_file_path_expanded = cargo_auto_encrypt_secret_lib::file_path_home_expand(identity_private_file_path);
if !camino::Utf8Path::new(&identity_private_file_path_expanded).exists() {
eprintln!("{RED}Identity file {identity_private_file_path_expanded} that contains the SSH private key does not exist! {RESET}");
eprintln!(" {YELLOW}Create the SSH key manually in bash with this command:{RESET}");
if identity_private_file_path_expanded.as_str().contains("github_api") {
eprintln!(r#"{GREEN}ssh-keygen -t ed25519 -f "{identity_private_file_path_expanded}" -C "github api token"{RESET}"#);
} else if identity_private_file_path_expanded.as_str().contains("crates_io") {
eprintln!(r#"{GREEN}ssh-keygen -t ed25519 -f "{identity_private_file_path_expanded}" -C "crates io token"{RESET}"#);
}
eprintln!(" ");
panic!("{RED}Error: File {identity_private_file_path_expanded} does not exist! {RESET}");
}
identity_private_file_path_expanded
}
}
pub(crate) mod github_mod {
Expand Down Expand Up @@ -912,7 +919,9 @@ pub(crate) mod github_mod {
let encrypted_string_file_path = camino::Utf8Path::new("~/.ssh/github_api_token_encrypted.txt");
let encrypted_string_file_path_expanded = cargo_auto_encrypt_secret_lib::file_path_home_expand(encrypted_string_file_path);
let identity_file_path = camino::Utf8Path::new("~/.ssh/github_api_token_ssh_1");
let identity_private_file_path = camino::Utf8Path::new("~/.ssh/github_api_token_ssh_1");
let _identity_private_file_path_expanded = crate::secrets_always_local_mod::ssh_mod::expand_path_check_private_key_exists(identity_private_file_path);
if !encrypted_string_file_path_expanded.exists() {
// ask interactive
println!(" {BLUE}Do you want to store the GitHub API token encrypted with an SSH key? (y/n){RESET}");
Expand All @@ -924,7 +933,7 @@ pub(crate) mod github_mod {
// get the passphrase and token interactively
let mut ssh_context = super::ssh_mod::SshContext::new();
// encrypt and save the encrypted token
cargo_auto_encrypt_secret_lib::encrypt_with_ssh_interactive_save_file(&mut ssh_context, identity_file_path, encrypted_string_file_path);
cargo_auto_encrypt_secret_lib::encrypt_with_ssh_interactive_save_file(&mut ssh_context, identity_private_file_path, encrypted_string_file_path);
// read the token and decrypt, return GitHubClient
read_token_and_decrypt_return_github_client(ssh_context, encrypted_string_file_path)
}
Expand Down Expand Up @@ -1100,7 +1109,10 @@ pub(crate) mod crate_io_mod {
let encrypted_string_file_path = camino::Utf8Path::new("~/.ssh/crates_io_token_encrypted.txt");
let encrypted_string_file_path_expanded = cargo_auto_encrypt_secret_lib::file_path_home_expand(encrypted_string_file_path);
let identity_file_path = camino::Utf8Path::new("~/.ssh/crates_io_token_ssh_1");
let identity_private_file_path = camino::Utf8Path::new("~/.ssh/crates_io_token_ssh_1");
let _identity_private_file_path_expanded = crate::secrets_always_local_mod::ssh_mod::expand_path_check_private_key_exists(identity_private_file_path);
if !encrypted_string_file_path_expanded.exists() {
// ask interactive
println!(" {BLUE}Do you want to store the crates.io token encrypted with an SSH key? (y/n){RESET}");
Expand All @@ -1112,7 +1124,7 @@ pub(crate) mod crate_io_mod {
// get the passphrase and token interactively
let mut ssh_context = super::ssh_mod::SshContext::new();
// encrypt and save the encrypted token
cargo_auto_encrypt_secret_lib::encrypt_with_ssh_interactive_save_file(&mut ssh_context, identity_file_path, encrypted_string_file_path);
cargo_auto_encrypt_secret_lib::encrypt_with_ssh_interactive_save_file(&mut ssh_context, identity_private_file_path, encrypted_string_file_path);
// read the token and decrypt, return CratesIoClient
read_token_and_decrypt_return_crate_io_client(ssh_context, encrypted_string_file_path)
}
Expand Down
Loading

0 comments on commit 625809b

Please sign in to comment.