From 2a85c58863f4d8a63c9adfea4ca0c73175a4892e Mon Sep 17 00:00:00 2001
From: Dominik George <dominik.george@teckids.org>
Date: Fri, 14 May 2021 10:37:23 +0200
Subject: [PATCH] [OAuth] Document full_key and get_data

---
 src/oauth.rs | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/src/oauth.rs b/src/oauth.rs
index 474eb9b..0b67156 100644
--- a/src/oauth.rs
+++ b/src/oauth.rs
@@ -45,6 +45,9 @@ use reqwest;
 use serde_json;
 use jq_rs;
 
+/// Construct a configuration key from parts
+///
+/// Simply joins all elements of the passed array with a '.'
 fn full_key(parts: Vec<&str>) -> String {
     parts.join(".")
 }
@@ -136,17 +139,24 @@ pub fn get_access_token_password<E: Copy>(conf: &Config, prefix: &str, username:
         }
 }
 
+/// Retrieve text data from a configured URL endpoint
+///
+/// Takes the same arguments as `get_data_jq`.
 fn get_data(conf: &Config, prefix: &str, endpoint: &str, param: String, token: &BasicTokenResponse) -> Result<String, Box<dyn error::Error>> {
+    /// Extract token as string from deserialized access token
     let access_token = token.access_token().secret();
+    let token_type = "Bearer".to_string();  // FIXME Probably we need to handle other token types
 
+    // Retreieve endpoint URL from configuration
     let mut endpoint_url: String = get_or_error(&conf, &full_key(vec![prefix, "urls", endpoint]), "")?;
     endpoint_url = endpoint_url.replace("{}", &param);
-
     debug!("Loading text data from {}", endpoint_url);
+
+    // Send off request to server
     let client = reqwest::blocking::Client::new();
     Ok(client
         .get(&endpoint_url)
-        .header(reqwest::header::AUTHORIZATION, format!("Bearer {}", access_token))
+        .header(reqwest::header::AUTHORIZATION, format!("{} {}", token_type, access_token))
         .send()?
         .text()?)
 }
-- 
GitLab