aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2019-12-16 00:40:30 -0500
committerJesse Luehrs <doy@tozt.net>2019-12-16 00:41:18 -0500
commitee5de447d977999e7f5b4b41685d74ce28d63535 (patch)
tree561e40c24c3dbb15ed705dbaf4d0493fc0e60f25
parent01f148cae5b09271788f328880407616d7bdeea8 (diff)
downloadteleterm-ee5de447d977999e7f5b4b41685d74ce28d63535.tar.gz
teleterm-ee5de447d977999e7f5b4b41685d74ce28d63535.zip
move client id file manipulation out of oauth
it doesn't actually have anything to do with the oauth flow
-rw-r--r--teleterm/src/client.rs41
-rw-r--r--teleterm/src/cmd/stream.rs2
-rw-r--r--teleterm/src/cmd/watch.rs2
-rw-r--r--teleterm/src/oauth.rs38
4 files changed, 41 insertions, 42 deletions
diff --git a/teleterm/src/client.rs b/teleterm/src/client.rs
index 67420f0..250ca1c 100644
--- a/teleterm/src/client.rs
+++ b/teleterm/src/client.rs
@@ -1,5 +1,6 @@
use crate::prelude::*;
use rand::Rng as _;
+use std::io::Read as _;
const HEARTBEAT_DURATION: std::time::Duration =
std::time::Duration::from_secs(30);
@@ -388,8 +389,7 @@ impl<S: tokio::io::AsyncRead + tokio::io::AsyncWrite + Send + 'static>
))
})
.and_then(move |(msg, sock)| {
- crate::oauth::save_client_auth_id(auth_type, &id)
- .map(|_| (msg, sock))
+ save_client_auth_id(auth_type, &id).map(|_| (msg, sock))
})
.and_then(|(msg, sock)| {
let response = format!(
@@ -648,3 +648,40 @@ impl<S: tokio::io::AsyncRead + tokio::io::AsyncWrite + Send + 'static>
component_future::poll_stream(self, Self::POLL_FNS)
}
}
+
+pub fn load_client_auth_id(
+ auth: crate::protocol::AuthType,
+) -> Option<String> {
+ client_id_file(auth, true).and_then(|id_file| {
+ std::fs::File::open(id_file).ok().and_then(|mut file| {
+ let mut id = vec![];
+ file.read_to_end(&mut id).ok().map(|_| {
+ std::string::String::from_utf8_lossy(&id).to_string()
+ })
+ })
+ })
+}
+
+fn save_client_auth_id(
+ auth: crate::protocol::AuthType,
+ id: &str,
+) -> impl futures::Future<Item = (), Error = Error> {
+ let id_file = client_id_file(auth, false).unwrap();
+ let id = id.to_string();
+ tokio::fs::File::create(id_file.clone())
+ .with_context(move || crate::error::CreateFile {
+ filename: id_file.to_string_lossy().to_string(),
+ })
+ .and_then(|file| {
+ tokio::io::write_all(file, id).context(crate::error::WriteFile)
+ })
+ .map(|_| ())
+}
+
+fn client_id_file(
+ auth: crate::protocol::AuthType,
+ must_exist: bool,
+) -> Option<std::path::PathBuf> {
+ let filename = format!("client-oauth-{}", auth.name());
+ crate::dirs::Dirs::new().data_file(&filename, must_exist)
+}
diff --git a/teleterm/src/cmd/stream.rs b/teleterm/src/cmd/stream.rs
index 4c3f229..c47804a 100644
--- a/teleterm/src/cmd/stream.rs
+++ b/teleterm/src/cmd/stream.rs
@@ -36,7 +36,7 @@ impl crate::config::Config for Config {
}
}
crate::protocol::AuthType::RecurseCenter => {
- let id = crate::oauth::load_client_auth_id(self.client.auth);
+ let id = crate::client::load_client_auth_id(self.client.auth);
crate::protocol::Auth::recurse_center(
id.as_ref().map(std::string::String::as_str),
)
diff --git a/teleterm/src/cmd/watch.rs b/teleterm/src/cmd/watch.rs
index 7e6cb2d..e2e43e2 100644
--- a/teleterm/src/cmd/watch.rs
+++ b/teleterm/src/cmd/watch.rs
@@ -34,7 +34,7 @@ impl crate::config::Config for Config {
}
}
crate::protocol::AuthType::RecurseCenter => {
- let id = crate::oauth::load_client_auth_id(self.client.auth);
+ let id = crate::client::load_client_auth_id(self.client.auth);
crate::protocol::Auth::recurse_center(
id.as_ref().map(std::string::String::as_str),
)
diff --git a/teleterm/src/oauth.rs b/teleterm/src/oauth.rs
index ee914b4..d76a1b7 100644
--- a/teleterm/src/oauth.rs
+++ b/teleterm/src/oauth.rs
@@ -1,6 +1,5 @@
use crate::prelude::*;
use oauth2::TokenResponse as _;
-use std::io::Read as _;
mod recurse_center;
pub use recurse_center::RecurseCenter;
@@ -77,43 +76,6 @@ pub trait Oauth {
) -> Box<dyn futures::Future<Item = String, Error = Error> + Send>;
}
-pub fn save_client_auth_id(
- auth: crate::protocol::AuthType,
- id: &str,
-) -> impl futures::Future<Item = (), Error = Error> {
- let id_file = client_id_file(auth, false).unwrap();
- let id = id.to_string();
- tokio::fs::File::create(id_file.clone())
- .with_context(move || crate::error::CreateFile {
- filename: id_file.to_string_lossy().to_string(),
- })
- .and_then(|file| {
- tokio::io::write_all(file, id).context(crate::error::WriteFile)
- })
- .map(|_| ())
-}
-
-pub fn load_client_auth_id(
- auth: crate::protocol::AuthType,
-) -> Option<String> {
- client_id_file(auth, true).and_then(|id_file| {
- std::fs::File::open(id_file).ok().and_then(|mut file| {
- let mut id = vec![];
- file.read_to_end(&mut id).ok().map(|_| {
- std::string::String::from_utf8_lossy(&id).to_string()
- })
- })
- })
-}
-
-fn client_id_file(
- auth: crate::protocol::AuthType,
- must_exist: bool,
-) -> Option<std::path::PathBuf> {
- let filename = format!("client-oauth-{}", auth.name());
- crate::dirs::Dirs::new().data_file(&filename, must_exist)
-}
-
fn cache_refresh_token(
token_cache_file: std::path::PathBuf,
token: &oauth2::basic::BasicTokenResponse,