Add token storage in a .env file

This commit is contained in:
Mylloon 2021-12-03 10:48:11 +01:00
parent dc35cdbe4d
commit 3101b14ec2
5 changed files with 21 additions and 1 deletions

2
.gitignore vendored
View file

@ -1 +1,3 @@
/target /target
.env

7
Cargo.lock generated
View file

@ -60,6 +60,12 @@ version = "0.8.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc" checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc"
[[package]]
name = "dotenv"
version = "0.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "77c90badedccf4105eca100756a0b1289e191f6fcbdadd3cee1d2f614f97da8f"
[[package]] [[package]]
name = "encoding_rs" name = "encoding_rs"
version = "0.8.29" version = "0.8.29"
@ -319,6 +325,7 @@ checksum = "a3e378b66a060d48947b590737b30a1be76706c8dd7b8ba0f2fe3989c68a853f"
name = "matter_bot" name = "matter_bot"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"dotenv",
"mattermost_api", "mattermost_api",
] ]

View file

@ -6,4 +6,5 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
dotenv = "0.15.0"
mattermost_api = "0.1.0" mattermost_api = "0.1.0"

View file

@ -5,3 +5,8 @@
```bash ```bash
sudo apt install libssl-dev sudo apt install libssl-dev
``` ```
`.env` placé dans la racine du projet qui contient le token, exemple :
```
TOKEN=votre_token_ici
```

View file

@ -1,3 +1,8 @@
use dotenv::dotenv;
use std::env;
fn main() { 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");
} }