reverse to 3101b14 trying to re-use mattermost_api crate

This commit is contained in:
Mylloon 2021-12-21 09:12:40 +01:00
parent 89a9fc6543
commit 76772e53f3
Signed by: Anri
GPG key ID: A82D63DFF8D1317F
4 changed files with 57 additions and 127 deletions

148
Cargo.lock generated
View file

@ -181,15 +181,6 @@ version = "0.11.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e" checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e"
[[package]]
name = "hermit-abi"
version = "0.1.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33"
dependencies = [
"libc",
]
[[package]] [[package]]
name = "http" name = "http"
version = "0.2.5" version = "0.2.5"
@ -282,15 +273,6 @@ dependencies = [
"hashbrown", "hashbrown",
] ]
[[package]]
name = "instant"
version = "0.1.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c"
dependencies = [
"cfg-if",
]
[[package]] [[package]]
name = "ipnet" name = "ipnet"
version = "2.3.1" version = "2.3.1"
@ -324,15 +306,6 @@ version = "0.2.108"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8521a1b57e76b1ec69af7599e75e38e7b7fad6610f037db8c79b127201b5d119" checksum = "8521a1b57e76b1ec69af7599e75e38e7b7fad6610f037db8c79b127201b5d119"
[[package]]
name = "lock_api"
version = "0.4.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712a4d093c9976e24e7dbca41db895dabcbac38eb5f4045393d17a95bdfb1109"
dependencies = [
"scopeguard",
]
[[package]] [[package]]
name = "log" name = "log"
version = "0.4.14" version = "0.4.14"
@ -353,8 +326,21 @@ name = "matter_bot"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"dotenv", "dotenv",
"mattermost_api",
]
[[package]]
name = "mattermost_api"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "838359d04b4dff6d27a0b0113a0219c5fad2bf97276f43bd765f77d286ba62be"
dependencies = [
"http",
"log",
"reqwest", "reqwest",
"tokio", "serde",
"serde_json",
"thiserror",
] ]
[[package]] [[package]]
@ -418,16 +404,6 @@ dependencies = [
"winapi", "winapi",
] ]
[[package]]
name = "num_cpus"
version = "1.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "05499f3756671c15885fee9034446956fff3f243d6077b91e5767df161f766b3"
dependencies = [
"hermit-abi",
"libc",
]
[[package]] [[package]]
name = "once_cell" name = "once_cell"
version = "1.8.0" version = "1.8.0"
@ -467,31 +443,6 @@ dependencies = [
"vcpkg", "vcpkg",
] ]
[[package]]
name = "parking_lot"
version = "0.11.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7d17b78036a60663b797adeaee46f5c9dfebb86948d1255007a1d6be0271ff99"
dependencies = [
"instant",
"lock_api",
"parking_lot_core",
]
[[package]]
name = "parking_lot_core"
version = "0.8.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d76e8e1493bcac0d2766c42737f34458f1c8c50c0d23bcb24ea953affb273216"
dependencies = [
"cfg-if",
"instant",
"libc",
"redox_syscall",
"smallvec",
"winapi",
]
[[package]] [[package]]
name = "percent-encoding" name = "percent-encoding"
version = "2.1.0" version = "2.1.0"
@ -649,12 +600,6 @@ dependencies = [
"winapi", "winapi",
] ]
[[package]]
name = "scopeguard"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd"
[[package]] [[package]]
name = "security-framework" name = "security-framework"
version = "2.4.2" version = "2.4.2"
@ -683,6 +628,20 @@ name = "serde"
version = "1.0.130" version = "1.0.130"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f12d06de37cf59146fbdecab66aa99f9fe4f78722e3607577a5375d66bd0c913" checksum = "f12d06de37cf59146fbdecab66aa99f9fe4f78722e3607577a5375d66bd0c913"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
version = "1.0.130"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d7bc1a1ab1961464eae040d96713baa5a724a8152c1222492465b54322ec508b"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]] [[package]]
name = "serde_json" name = "serde_json"
@ -707,27 +666,12 @@ dependencies = [
"serde", "serde",
] ]
[[package]]
name = "signal-hook-registry"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e51e73328dc4ac0c7ccbda3a494dfa03df1de2f46018127f60c693f2648455b0"
dependencies = [
"libc",
]
[[package]] [[package]]
name = "slab" name = "slab"
version = "0.4.5" version = "0.4.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9def91fd1e018fe007022791f865d0ccc9b3a0d5001e01aabb8b40e46000afb5" checksum = "9def91fd1e018fe007022791f865d0ccc9b3a0d5001e01aabb8b40e46000afb5"
[[package]]
name = "smallvec"
version = "1.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1ecab6c735a6bb4139c0caafd0cc3635748bbb3acf4550e8138122099251f309"
[[package]] [[package]]
name = "socket2" name = "socket2"
version = "0.4.2" version = "0.4.2"
@ -763,6 +707,26 @@ dependencies = [
"winapi", "winapi",
] ]
[[package]]
name = "thiserror"
version = "1.0.30"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "854babe52e4df1653706b98fcfc05843010039b406875930a70e4d9644e5c417"
dependencies = [
"thiserror-impl",
]
[[package]]
name = "thiserror-impl"
version = "1.0.30"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aa32fd3f627f367fe16f893e2597ae3c05020f8bba2666a4e6ea73d377e5714b"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]] [[package]]
name = "tinyvec" name = "tinyvec"
version = "1.5.1" version = "1.5.1"
@ -789,26 +753,10 @@ dependencies = [
"libc", "libc",
"memchr", "memchr",
"mio", "mio",
"num_cpus",
"once_cell",
"parking_lot",
"pin-project-lite", "pin-project-lite",
"signal-hook-registry",
"tokio-macros",
"winapi", "winapi",
] ]
[[package]]
name = "tokio-macros"
version = "1.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c9efc1aba077437943f7515666aa2b882dfabfbfdf89c819ea75a8d6e9eaba5e"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]] [[package]]
name = "tokio-native-tls" name = "tokio-native-tls"
version = "0.3.0" version = "0.3.0"

View file

@ -7,6 +7,4 @@ edition = "2021"
[dependencies] [dependencies]
dotenv = "0.15.0" dotenv = "0.15.0"
mattermost_api = "0.1.0"
reqwest = "0.11.7"
tokio = { version = "1.14.0", features = ["full"] }

View file

@ -1,29 +1,12 @@
# matter_bot # matter_bot
Bot Mattermost écrit en Rust qui se connecte via pseudo/mot de passe depuis Gitlab.
## Pré-requis ## Pré-requis
`openssl` requis. `openssl` requis par [`mattermost_api`](https://github.com/Celeo/mattermost_api)
```bash ```bash
sudo apt install libssl-dev sudo apt install libssl-dev
``` ```
`.env` placé dans la racine du projet qui contient votre **login ID** et votre **mot de passe**, ainsi que votre **user ID**, exemple : `.env` placé dans la racine du projet qui contient le token, exemple :
Si vous avez mis en place un code de vérification, alors vous devez créer une "application" dans vos paramètres Gitlab.
Le code secret obtenu sera votre mot de passe.
Pour obtenir un user ID, rendez vous sur ce site :
``` ```
https://{GITLAB_INSTANCE}/api/v4/users?username={TON_PSEUDO} TOKEN=votre_token_ici
``` ```
En remplaçant `{GITLAB_INSTANCE}` par l'url de votre instance Gitlab et `{TON_PSEUDO}` par votre pseudo Gitlab.
```
USER_ID_MATTER_BOT=votre_user-id_ici
LOGIN_ID_MATTER_BOT=votre_login-ID_ici
PASSWORD_MATTER_BOT=votre_mot-de-passe_ici
```
### Ressources utilisés
- [Using Mattermost API via Gitlab oAuth as an end-user with username and password](https://stackoverflow.com/a/36652283)
- Je me suis totalement inspiré de cette personne pour me connecter à Mattermost en passant par Gitlab

View file

@ -1,7 +1,8 @@
mod mattermost; // importe le module mattermost use dotenv::dotenv;
use std::env;
fn main() { fn main() {
let res = mattermost::connexion(); // Vérification si fichier .env trouvé
dotenv().expect("Le fichier .env n'a pas été trouvé...");
println!("{:?}", res); let _token = env::var("TOKEN").expect("Token non trouvé dans le fichier .env");
} }