From 3101b14ec2f5032a230321bd174fb9b4ce8f6298 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Fri, 3 Dec 2021 10:48:11 +0100 Subject: [PATCH] Add token storage in a .env file --- .gitignore | 2 ++ Cargo.lock | 7 +++++++ Cargo.toml | 1 + README.md | 5 +++++ src/main.rs | 7 ++++++- 5 files changed, 21 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index ea8c4bf..83a00ee 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ /target + +.env diff --git a/Cargo.lock b/Cargo.lock index 5e5aa60..9fac160 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -60,6 +60,12 @@ version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc" +[[package]] +name = "dotenv" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77c90badedccf4105eca100756a0b1289e191f6fcbdadd3cee1d2f614f97da8f" + [[package]] name = "encoding_rs" version = "0.8.29" @@ -319,6 +325,7 @@ checksum = "a3e378b66a060d48947b590737b30a1be76706c8dd7b8ba0f2fe3989c68a853f" name = "matter_bot" version = "0.1.0" dependencies = [ + "dotenv", "mattermost_api", ] diff --git a/Cargo.toml b/Cargo.toml index 179e427..6d2bc5e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,4 +6,5 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +dotenv = "0.15.0" mattermost_api = "0.1.0" diff --git a/README.md b/README.md index 3c3a570..687149e 100644 --- a/README.md +++ b/README.md @@ -5,3 +5,8 @@ ```bash sudo apt install libssl-dev ``` + +`.env` placé dans la racine du projet qui contient le token, exemple : +``` +TOKEN=votre_token_ici +``` diff --git a/src/main.rs b/src/main.rs index e7a11a9..ff101c2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,8 @@ +use dotenv::dotenv; +use std::env; + fn main() { - println!("Hello, world!"); + // Vérification si fichier .env trouvé + dotenv().expect("Le fichier .env n'a pas été trouvé..."); + let _token = env::var("TOKEN").expect("Token non trouvé dans le fichier .env"); }