refactor: do not get api secret at compile time
This commit is contained in:
parent
2f3e5244ff
commit
0c770db006
1 changed files with 11 additions and 7 deletions
18
src/main.rs
18
src/main.rs
|
@ -1,22 +1,26 @@
|
|||
use reqwest::header;
|
||||
use reqwest::Error;
|
||||
use reqwest::{Client, Error};
|
||||
use std::env;
|
||||
|
||||
static APP_USER_AGENT: &str = concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION"),);
|
||||
static TOKEN: &str = env!("CANVAS_SECRET");
|
||||
|
||||
async fn get_request() -> Result<(), reqwest::Error> {
|
||||
fn create_client() -> Result<Client, Error> {
|
||||
let token =
|
||||
env::var("CANVAS_SECRET").expect("Canvas API key is not defined in the environment.");
|
||||
|
||||
let mut headers = header::HeaderMap::new();
|
||||
headers.insert(
|
||||
header::AUTHORIZATION,
|
||||
format!("Bearer {}", TOKEN).parse().unwrap(),
|
||||
format!("Bearer {}", token).parse().unwrap(),
|
||||
);
|
||||
let client = reqwest::Client::builder()
|
||||
reqwest::Client::builder()
|
||||
.user_agent(APP_USER_AGENT)
|
||||
.default_headers(headers)
|
||||
.build()?;
|
||||
.build()
|
||||
}
|
||||
|
||||
let response = client
|
||||
async fn get_request() -> Result<(), reqwest::Error> {
|
||||
let response = create_client()?
|
||||
.get("https://ucsb.instructure.com/api/v1/courses")
|
||||
.send()
|
||||
.await?;
|
||||
|
|
Loading…
Reference in a new issue