Fetch gitlab token from env vars

Signed-off-by: baalajimaestro <me@baalajimaestro.me>
This commit is contained in:
baalajimaestro 2022-12-11 19:52:20 +05:30
parent b7ee0a0c7c
commit 3d3e3512db
Signed by: baalajimaestro
GPG key ID: F93C394FE9BBAFD5

View file

@ -2,6 +2,7 @@ use actix_web::{get, App, HttpResponse, HttpServer, Responder, web::{Data, Query
use tera::{Tera, Context}; use tera::{Tera, Context};
use serde::{Serialize, Deserialize}; use serde::{Serialize, Deserialize};
use reqwest::{Client, header::HeaderMap}; use reqwest::{Client, header::HeaderMap};
use std::env;
struct Template { struct Template {
paste: Tera, paste: Tera,
@ -31,9 +32,10 @@ struct ResponseJSON {
async fn paste_render(data: Data<Template>, paste: Query<Paste>) -> impl Responder { async fn paste_render(data: Data<Template>, paste: Query<Paste>) -> impl Responder {
let my_data = data.get_ref(); let my_data = data.get_ref();
let mut context = Context::new(); let mut context = Context::new();
let gitlab_token = env::var("GITLAB_TOKEN").unwrap_or("".to_string());
let client = Client::new(); let client = Client::new();
let mut headers = HeaderMap::new(); let mut headers = HeaderMap::new();
headers.insert("PRIVATE-TOKEN", "".parse().unwrap()); headers.insert("PRIVATE-TOKEN", gitlab_token.parse().unwrap());
let paste_content: String; let paste_content: String;
if paste.paste_id.is_some() { if paste.paste_id.is_some() {
let response = client.get(format!("https://git.baalajimaestro.me/api/v4/projects/12/repository/files/paste%2F{}.md?ref=master", paste.paste_id.as_ref().unwrap())).headers(headers).send().await.unwrap(); let response = client.get(format!("https://git.baalajimaestro.me/api/v4/projects/12/repository/files/paste%2F{}.md?ref=master", paste.paste_id.as_ref().unwrap())).headers(headers).send().await.unwrap();