Move auth key function to query module
This commit is contained in:
parent
ce03cbcd2a
commit
003fde0f1e
|
@ -1,34 +1,10 @@
|
||||||
#![feature(iterator_try_collect)]
|
#![feature(iterator_try_collect)]
|
||||||
|
|
||||||
use std::path::Path;
|
|
||||||
|
|
||||||
mod queries;
|
mod queries;
|
||||||
use queries::*;
|
use queries::*;
|
||||||
|
|
||||||
mod datasets;
|
mod datasets;
|
||||||
|
|
||||||
fn get_auth_key(config_dir: &Path) -> Option<String> {
|
|
||||||
use std::env::{var, VarError};
|
|
||||||
use std::fs::read_to_string;
|
|
||||||
|
|
||||||
match var("AUTH_KEY") {
|
|
||||||
Ok(key) => Some(key),
|
|
||||||
Err(VarError::NotUnicode(_)) => panic!("Invalid authorization key"),
|
|
||||||
Err(VarError::NotPresent) => {
|
|
||||||
let mut auth_file = config_dir.to_owned();
|
|
||||||
auth_file.push("auth.txt");
|
|
||||||
read_to_string(auth_file).ok().and_then(|s| {
|
|
||||||
let trimmed = s.trim();
|
|
||||||
if trimmed.is_empty() {
|
|
||||||
None
|
|
||||||
} else {
|
|
||||||
Some(trimmed.to_owned())
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let mut config_dir = dirs::config_dir().unwrap();
|
let mut config_dir = dirs::config_dir().unwrap();
|
||||||
config_dir.push("ggelo");
|
config_dir.push("ggelo");
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
use cynic::{GraphQlResponse, QueryBuilder};
|
use cynic::{GraphQlResponse, QueryBuilder};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
use std::path::Path;
|
||||||
|
|
||||||
pub mod search_games;
|
pub mod search_games;
|
||||||
pub use search_games::*;
|
pub use search_games::*;
|
||||||
|
@ -25,6 +26,30 @@ pub struct EntrantId(pub u64);
|
||||||
#[derive(cynic::Scalar, Debug, Clone)]
|
#[derive(cynic::Scalar, Debug, Clone)]
|
||||||
pub struct Timestamp(pub u64);
|
pub struct Timestamp(pub u64);
|
||||||
|
|
||||||
|
// Auth key
|
||||||
|
|
||||||
|
pub fn get_auth_key(config_dir: &Path) -> Option<String> {
|
||||||
|
use std::env::{var, VarError};
|
||||||
|
use std::fs::read_to_string;
|
||||||
|
|
||||||
|
match var("AUTH_KEY") {
|
||||||
|
Ok(key) => Some(key),
|
||||||
|
Err(VarError::NotUnicode(_)) => panic!("Invalid authorization key"),
|
||||||
|
Err(VarError::NotPresent) => {
|
||||||
|
let mut auth_file = config_dir.to_owned();
|
||||||
|
auth_file.push("auth.txt");
|
||||||
|
read_to_string(auth_file).ok().and_then(|s| {
|
||||||
|
let trimmed = s.trim();
|
||||||
|
if trimmed.is_empty() {
|
||||||
|
None
|
||||||
|
} else {
|
||||||
|
Some(trimmed.to_owned())
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Query machinery
|
// Query machinery
|
||||||
|
|
||||||
pub trait QueryUnwrap<Vars>: 'static + QueryBuilder<Vars> {
|
pub trait QueryUnwrap<Vars>: 'static + QueryBuilder<Vars> {
|
||||||
|
|
Loading…
Reference in a new issue