ssh_auth_cargo_publish_lib/lib.rs
1// ssh_auth_cargo_publish/src/lib.rs
2
3// region: auto_md_to_doc_comments include README.md A //!
4//! # ssh_auth_cargo_publish
5//!
6//! **Store and use encrypted secret_token for crates.io with SSH key**
7//! ***version: 1.0.3 date: 2024-04-30 author: [bestia.dev](https://bestia.dev) repository: [GitHub](https://github.com/automation-tasks-rs/ssh_auth_cargo_publish)***
8//!
9//! 
10//! 
11//! 
12//!
13//! [](https://github.com/CRUSTDE-ContainerizedRustDevEnv/ssh_auth_cargo_publish/blob/main/LICENSE)
14//! [](https://github.com/CRUSTDE-ContainerizedRustDevEnv/ssh_auth_cargo_publish/)
15//!
16//! [](https://github.com/automation-tasks-rs/ssh_auth_cargo_publish/)
17//! [](https://github.com/automation-tasks-rs/ssh_auth_cargo_publish/)
18//! [](https://github.com/automation-tasks-rs/ssh_auth_cargo_publish/)
19//! [](https://github.com/automation-tasks-rs/ssh_auth_cargo_publish/)
20//! [](https://github.com/automation-tasks-rs/ssh_auth_cargo_publish/)
21//!
22//! Hashtags: #maintained #ready-for-use #rustlang #automation #workflow
23//! My projects on GitHub are more like a tutorial than a finished product: [bestia-dev tutorials](https://github.com/bestia-dev/tutorials_rust_wasm).
24//! I recommend using the [CRUSTDE - Containerized Rust Development Environment](https://github.com/CRUSTDE-ContainerizedRustDevEnv/crustde_cnt_img_pod) to write Rust projects on Linux, isolated from your system.
25//!
26//! ## Motivation
27//!
28//! To access crates.io with `cargo publish` you need an access secret_token.
29//! IMPORTANT: Treat access secret_tokens like your password and keep them secret. Store your secret_tokens securely in a credential manager for example.
30//! Access secret_tokens are impossible to remember for an average human. We need to store them somewhere.
31//! This command stores the crates.io secret_token:
32//!
33//! ```bash
34//! cargo login
35//! ```
36//!
37//! WARNING: Be aware that by default they store the secret_token in "plain-text" in the file: `~/.cargo/credentials`.
38//! Ok, I see there was some development in this area and now is possible to use "credentials providers".
39//!
40//! I want to secure this secret_token with encryption with an SSH key.
41//! We have already a lot of experience creating, managing and securing our SSH keys. The private key is secured by a passphrase we can remember and type. Every use of the secret_token will need user interaction to type the passphrase. Very secure.
42//!
43//! If we are very self-confident in our current session, we can store the SSH key in ssh-agent and write our passphrase only once.
44//! WARNING: a dedicated attacker could read from ssh-agent and discover the access secret_token without our user interaction. Use this at your discretion.
45//!
46//! ## Replacement command
47//!
48//! Put the executable `ssh_auth_cargo_publish` into the folder you intend to use it.
49//! After copying, make it executable with `chmod +x ssh_auth_cargo_publish`.
50//! Instead of `cargo publish ...` use `ssh_auth_cargo_publish`.
51//! If it finds the encrypted secret_token it will ask you for the passphrase to the private SSH key.
52//! Else it will ask you to store the secret_token.
53//!
54//! ## Development details
55//!
56//! Read the development details in a separate md file:
57//! [DEVELOPMENT.md](DEVELOPMENT.md)
58//!
59//! ## Releases changelog
60//!
61//! Read the releases changelog in a separate md file:
62//! [RELEASES.md](RELEASES.md)
63//!
64//! ## TODO
65//!
66//! And code happily ever after...
67//!
68//! ## Open-source and free as a beer
69//!
70//! My open-source projects are free as a beer (MIT license).
71//! I just love programming.
72//! But I need also to drink. If you find my projects and tutorials helpful, please buy me a beer by donating to my [PayPal](https://paypal.me/LucianoBestia).
73//! You know the price of a beer in your local bar ;-)
74//! So I can drink a free beer for your health :-)
75//! [Na zdravje!](https://translate.google.com/?hl=en&sl=sl&tl=en&text=Na%20zdravje&op=translate) [Alla salute!](https://dictionary.cambridge.org/dictionary/italian-english/alla-salute) [Prost!](https://dictionary.cambridge.org/dictionary/german-english/prost) [Nazdravlje!](https://matadornetwork.com/nights/how-to-say-cheers-in-50-languages/) 🍻
76//!
77//! [//bestia.dev](https://bestia.dev)
78//! [//github.com/bestia-dev](https://github.com/bestia-dev)
79//! [//bestiadev.substack.com](https://bestiadev.substack.com)
80//! [//youtube.com/@bestia-dev-tutorials](https://youtube.com/@bestia-dev-tutorials)
81//!
82// endregion: auto_md_to_doc_comments include README.md A //!
83
84// access to modules
85mod crates_mod;
86mod error_mod;
87mod secrets_always_local_mod;
88
89// `pub use` allows the caller of the lib to access modules functions, structs or all(*)
90pub use crates_mod::publish;
91
92// // https://github.com/shiena/ansicolor/blob/master/README.md
93
94/// ANSI color
95#[allow(dead_code)]
96pub const RED: &str = "\x1b[31m";
97/// ANSI color
98#[allow(dead_code)]
99pub const YELLOW: &str = "\x1b[33m";
100/// ANSI color
101#[allow(dead_code)]
102pub const GREEN: &str = "\x1b[32m";
103/// ANSI color
104#[allow(dead_code)]
105pub const RESET: &str = "\x1b[0m";
106/// ANSI color
107#[allow(dead_code)]
108pub const BLUE: &str = "\x1b[34m";