From 003fde0f1e9fdb56c437b3a89e69ccefdfa9ef86 Mon Sep 17 00:00:00 2001 From: Kiana Sheibani Date: Sat, 2 Sep 2023 01:47:52 -0400 Subject: [PATCH] Move auth key function to query module --- cli/src/main.rs | 24 ------------------------ cli/src/queries.rs | 25 +++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 24 deletions(-) diff --git a/cli/src/main.rs b/cli/src/main.rs index c909501..8dedce1 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -1,34 +1,10 @@ #![feature(iterator_try_collect)] -use std::path::Path; - mod queries; use queries::*; mod datasets; -fn get_auth_key(config_dir: &Path) -> Option { - 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() { let mut config_dir = dirs::config_dir().unwrap(); config_dir.push("ggelo"); diff --git a/cli/src/queries.rs b/cli/src/queries.rs index 6022cf7..b2dd13a 100644 --- a/cli/src/queries.rs +++ b/cli/src/queries.rs @@ -1,5 +1,6 @@ use cynic::{GraphQlResponse, QueryBuilder}; use serde::{Deserialize, Serialize}; +use std::path::Path; pub mod search_games; pub use search_games::*; @@ -25,6 +26,30 @@ pub struct EntrantId(pub u64); #[derive(cynic::Scalar, Debug, Clone)] pub struct Timestamp(pub u64); +// Auth key + +pub fn get_auth_key(config_dir: &Path) -> Option { + 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 pub trait QueryUnwrap: 'static + QueryBuilder {