From d87ab9df2315c4bd6b0a9a06b28bc667f15be13c Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 16 Sep 2022 17:50:54 +0000 Subject: [PATCH 01/10] Bump mako from 1.1.4 to 1.2.2 Bumps [mako](https://github.com/sqlalchemy/mako) from 1.1.4 to 1.2.2. - [Release notes](https://github.com/sqlalchemy/mako/releases) - [Changelog](https://github.com/sqlalchemy/mako/blob/main/CHANGES) - [Commits](https://github.com/sqlalchemy/mako/commits) --- updated-dependencies: - dependency-name: mako dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 7ef6fdf2a5..19cfbafe13 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -mako==1.1.4 +mako==1.2.2 pyyaml<6 mkdocs==0.11 pytest From 70780388579b0362c09b76783f17a44fecf64f84 Mon Sep 17 00:00:00 2001 From: philippeitis <33013301+philippeitis@users.noreply.github.com> Date: Fri, 23 Sep 2022 00:21:27 -0700 Subject: [PATCH 02/10] Use generic Authy trait in place of yup_oauth2 --- src/generator/templates/Cargo.toml.mako | 7 +- src/generator/templates/api/api.rs.mako | 8 +- src/generator/templates/api/lib/mbuild.mako | 12 +-- src/rust/api/client.rs | 83 +++++++++++++++++++-- 4 files changed, 93 insertions(+), 17 deletions(-) diff --git a/src/generator/templates/Cargo.toml.mako b/src/generator/templates/Cargo.toml.mako index 1d23f7138c..2883b39972 100644 --- a/src/generator/templates/Cargo.toml.mako +++ b/src/generator/templates/Cargo.toml.mako @@ -32,7 +32,7 @@ mime = "^ 0.2.0" serde = "^ 1.0" serde_json = "^ 1.0" serde_derive = "^ 1.0" -yup-oauth2 = "^ 7.0" +yup-oauth2 = { version = "^ 7.0", optional = true } itertools = "^ 0.10" % for dep in cargo.get('dependencies', list()): ${dep} @@ -41,7 +41,7 @@ ${dep} <% api_name = util.library_name() crate_name_we_depend_on = None - + if make.depends_on_suffix is not None: crate_name_we_depend_on = library_to_crate_name(api_name, suffix=make.depends_on_suffix) %>\ @@ -53,3 +53,6 @@ ${dep} path = "../${api_name}" version = "${util.crate_version()}" % endif + +[features] +default = ["yup-oauth2"] diff --git a/src/generator/templates/api/api.rs.mako b/src/generator/templates/api/api.rs.mako index b5dfd40a1d..ee273b0d5c 100644 --- a/src/generator/templates/api/api.rs.mako +++ b/src/generator/templates/api/api.rs.mako @@ -30,7 +30,7 @@ use http::Uri; use hyper::client::connect; use tokio::io::{AsyncRead, AsyncWrite}; use tower_service; -use crate::client; +use crate::{client, client::Authy}; // ############## // UTILITIES ### @@ -55,7 +55,7 @@ ${lib.hub_usage_example(c)}\ #[derive(Clone)] pub struct ${hub_type}${ht_params} { pub client: hyper::Client, - pub auth: oauth2::authenticator::Authenticator, + pub auth: Box, _user_agent: String, _base_url: String, _root_url: String, @@ -65,10 +65,10 @@ impl<'a, ${', '.join(HUB_TYPE_PARAMETERS)}> client::Hub for ${hub_type}${ht_para impl<'a, ${', '.join(HUB_TYPE_PARAMETERS)}> ${hub_type}${ht_params} { - pub fn new(client: hyper::Client, authenticator: oauth2::authenticator::Authenticator) -> ${hub_type}${ht_params} { + pub fn new(client: hyper::Client, auth: A) -> ${hub_type}${ht_params} { ${hub_type} { client, - auth: authenticator, + auth: Box::new(auth), _user_agent: "${default_user_agent}".to_string(), _base_url: "${baseUrl}".to_string(), _root_url: "${rootUrl}".to_string(), diff --git a/src/generator/templates/api/lib/mbuild.mako b/src/generator/templates/api/lib/mbuild.mako index 18007e04fa..d9ff0f2980 100644 --- a/src/generator/templates/api/lib/mbuild.mako +++ b/src/generator/templates/api/lib/mbuild.mako @@ -387,7 +387,7 @@ match result { Error::HttpError(_) |Error::Io(_) |Error::MissingAPIKey - |Error::MissingToken(_) + |Error::MissingToken |Error::Cancelled |Error::UploadSizeLimitExceeded(_, _) |Error::Failure(_) @@ -706,14 +706,14 @@ else { loop { % if default_scope: - let token = match ${auth_call}.token(&self.${api.properties.scopes}.keys().collect::>()[..]).await { - Ok(token) => token.clone(), - Err(err) => { - match dlg.token(&err) { + let token = match ${auth_call}.get_token(&self.${api.properties.scopes}.keys().map(String::as_str).collect::>()[..]).await { + Some(token) => token.clone(), + None => { + match dlg.token() { Some(token) => token, None => { ${delegate_finish}(false); - return Err(client::Error::MissingToken(err)) + return Err(client::Error::MissingToken) } } } diff --git a/src/rust/api/client.rs b/src/rust/api/client.rs index 1c5e04cdbc..246fa7782e 100644 --- a/src/rust/api/client.rs +++ b/src/rust/api/client.rs @@ -1,7 +1,9 @@ use std::error; use std::error::Error as StdError; use std::fmt::{self, Display}; +use std::future::Future; use std::io::{self, Cursor, Read, Seek, SeekFrom, Write}; +use std::pin::Pin; use std::str::FromStr; use std::thread::sleep; use std::time::Duration; @@ -110,8 +112,7 @@ pub trait Delegate: Send { /// impending failure. /// The given Error provides information about why the token couldn't be acquired in the /// first place - fn token(&mut self, err: &oauth2::Error) -> Option { - let _ = err; + fn token(&mut self) -> Option { None } @@ -228,7 +229,7 @@ pub enum Error { MissingAPIKey, /// We required a Token, but didn't get one from the Authenticator - MissingToken(oauth2::Error), + MissingToken, /// The delgate instructed to cancel the operation Cancelled, @@ -272,8 +273,8 @@ impl Display for Error { writeln!(f, "Bad Request: {}", message)?; Ok(()) } - Error::MissingToken(ref err) => { - writeln!(f, "Token retrieval failed with error: {}", err) + Error::MissingToken => { + writeln!(f, "Token retrieval failed.") } Error::Cancelled => writeln!(f, "Operation cancelled by delegate"), Error::FieldClash(field) => writeln!( @@ -785,3 +786,75 @@ pub async fn get_body_as_string(res_body: &mut hyper::Body) -> String { let res_body_string = String::from_utf8_lossy(&res_body_buf); res_body_string.to_string() } + +pub trait Authy: AuthyClone { + fn get_token<'a>(&'a self, _scopes: &'a [&str]) -> Pin> + 'a>> { + async fn x() -> Option { + None + } + + Box::pin(x()) + } +} + +pub trait AuthyClone { + fn clone_box(&self) -> Box; +} + +impl AuthyClone for T +where + T: 'static + Authy + Clone, +{ + fn clone_box(&self) -> Box { + Box::new(self.clone()) + } +} + +impl Clone for Box { + fn clone(&self) -> Box { + self.clone_box() + } +} + +impl Authy for String { + fn get_token<'a>(&'a self, _scopes: &'a [&str]) -> Pin> + 'a>> { + async fn ident(s: &str) -> Option { + Some(s.to_string()) + } + Box::pin(ident(self)) + } +} + +impl Authy for () {} + +#[cfg(feature = "yup-oauth2")] +mod yup_oauth2_impl { + use core::future::Future; + use core::pin::Pin; + + use super::Authy; + + use tower_service::Service; + use yup_oauth2::authenticator::Authenticator; + use tokio::io::{AsyncRead, AsyncWrite}; + use http::Uri; + use hyper::client::connect::Connection; + + async fn helper(auth: &Authenticator, scopes: &[&str]) -> Option where + S: Service + Clone + Send + Sync + 'static, + S::Response: Connection + AsyncRead + AsyncWrite + Send + Unpin + 'static, + S::Future: Send + Unpin + 'static, + S::Error: Into> { + auth.token(scopes).await.ok().map(|t| t.as_str().to_string()) + } + + impl Authy for Authenticator where + S: Service + Clone + Send + Sync + 'static, + S::Response: Connection + AsyncRead + AsyncWrite + Send + Unpin + 'static, + S::Future: Send + Unpin + 'static, + S::Error: Into> { + fn get_token<'a>(&'a self, scopes: &'a [&str]) -> Pin> + 'a>> { + Box::pin(helper(self, scopes)) + } + } +} From cac4666204691332812b8f22ddc82782ad662e70 Mon Sep 17 00:00:00 2001 From: philippeitis <33013301+philippeitis@users.noreply.github.com> Date: Sat, 24 Sep 2022 11:55:55 -0700 Subject: [PATCH 03/10] Remove breaking changes, add TODOs --- requirements.txt | 2 +- src/generator/templates/Cargo.toml.mako | 9 ++- src/generator/templates/api/api.rs.mako | 6 +- src/generator/templates/api/lib/mbuild.mako | 19 ++++-- src/rust/api/client.rs | 71 ++++++++++----------- 5 files changed, 60 insertions(+), 47 deletions(-) diff --git a/requirements.txt b/requirements.txt index 19cfbafe13..89ad107608 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,6 @@ mako==1.2.2 pyyaml<6 -mkdocs==0.11 +mkdocs==1.3.1 pytest pytest-cov codecov diff --git a/src/generator/templates/Cargo.toml.mako b/src/generator/templates/Cargo.toml.mako index 2883b39972..97e0c72b21 100644 --- a/src/generator/templates/Cargo.toml.mako +++ b/src/generator/templates/Cargo.toml.mako @@ -32,7 +32,9 @@ mime = "^ 0.2.0" serde = "^ 1.0" serde_json = "^ 1.0" serde_derive = "^ 1.0" -yup-oauth2 = { version = "^ 7.0", optional = true } +## TODO: Make yup-oauth2 optional +## yup-oauth2 = { version = "^ 7.0", optional = true } +yup-oauth2 = "^ 7.0" itertools = "^ 0.10" % for dep in cargo.get('dependencies', list()): ${dep} @@ -54,5 +56,6 @@ path = "../${api_name}" version = "${util.crate_version()}" % endif -[features] -default = ["yup-oauth2"] +## TODO: Make yup-oauth2 optional +# [features] +# default = ["yup-oauth2"] diff --git a/src/generator/templates/api/api.rs.mako b/src/generator/templates/api/api.rs.mako index ee273b0d5c..cc81bcf07d 100644 --- a/src/generator/templates/api/api.rs.mako +++ b/src/generator/templates/api/api.rs.mako @@ -30,7 +30,7 @@ use http::Uri; use hyper::client::connect; use tokio::io::{AsyncRead, AsyncWrite}; use tower_service; -use crate::{client, client::Authy}; +use crate::{client, client::GetToken}; // ############## // UTILITIES ### @@ -55,7 +55,7 @@ ${lib.hub_usage_example(c)}\ #[derive(Clone)] pub struct ${hub_type}${ht_params} { pub client: hyper::Client, - pub auth: Box, + pub auth: Box, _user_agent: String, _base_url: String, _root_url: String, @@ -65,7 +65,7 @@ impl<'a, ${', '.join(HUB_TYPE_PARAMETERS)}> client::Hub for ${hub_type}${ht_para impl<'a, ${', '.join(HUB_TYPE_PARAMETERS)}> ${hub_type}${ht_params} { - pub fn new(client: hyper::Client, auth: A) -> ${hub_type}${ht_params} { + pub fn new(client: hyper::Client, auth: A) -> ${hub_type}${ht_params} { ${hub_type} { client, auth: Box::new(auth), diff --git a/src/generator/templates/api/lib/mbuild.mako b/src/generator/templates/api/lib/mbuild.mako index d9ff0f2980..a3f5d4b5cc 100644 --- a/src/generator/templates/api/lib/mbuild.mako +++ b/src/generator/templates/api/lib/mbuild.mako @@ -707,13 +707,24 @@ else { loop { % if default_scope: let token = match ${auth_call}.get_token(&self.${api.properties.scopes}.keys().map(String::as_str).collect::>()[..]).await { - Some(token) => token.clone(), - None => { - match dlg.token() { + // TODO: remove Ok / Err branches + Ok(Some(token)) => token.clone(), + Ok(None) => { + let err = oauth2::OtherError("unknown error occurred while generating oauth2 token".into()); + match dlg.token(&err) { Some(token) => token, None => { ${delegate_finish}(false); - return Err(client::Error::MissingToken) + return Err(client::Error::MissingToken(err)) + } + } + } + Err(err) => { + match dlg.token(&err) { + Some(token) => token, + None => { + ${delegate_finish}(false); + return Err(client::Error::MissingToken(err)) } } } diff --git a/src/rust/api/client.rs b/src/rust/api/client.rs index 246fa7782e..b558c376a0 100644 --- a/src/rust/api/client.rs +++ b/src/rust/api/client.rs @@ -107,12 +107,14 @@ pub trait Delegate: Send { None } + // TODO: Remove oauth2::Error /// Called whenever the Authenticator didn't yield a token. The delegate /// may attempt to provide one, or just take it as a general information about the /// impending failure. /// The given Error provides information about why the token couldn't be acquired in the /// first place - fn token(&mut self) -> Option { + fn token(&mut self, err: &oauth2::Error) -> Option { + let _ = err; None } @@ -228,8 +230,9 @@ pub enum Error { /// Neither through the authenticator, nor through the Delegate. MissingAPIKey, + // TODO: Remove oauth2::Error /// We required a Token, but didn't get one from the Authenticator - MissingToken, + MissingToken(oauth2::Error), /// The delgate instructed to cancel the operation Cancelled, @@ -273,8 +276,9 @@ impl Display for Error { writeln!(f, "Bad Request: {}", message)?; Ok(()) } - Error::MissingToken => { - writeln!(f, "Token retrieval failed.") + // TODO: Remove oauth2::Error + Error::MissingToken(ref err) => { + writeln!(f, "Token retrieval failed with error: {}", err) } Error::Cancelled => writeln!(f, "Operation cancelled by delegate"), Error::FieldClash(field) => writeln!( @@ -787,52 +791,52 @@ pub async fn get_body_as_string(res_body: &mut hyper::Body) -> String { res_body_string.to_string() } -pub trait Authy: AuthyClone { - fn get_token<'a>(&'a self, _scopes: &'a [&str]) -> Pin> + 'a>> { - async fn x() -> Option { - None - } +// TODO: Simplify this to Option +type TokenResult = std::result::Result, oauth2::Error>; - Box::pin(x()) +pub trait GetToken: GetTokenClone { + /// Called whenever there is the need for your applications API key after + /// the official authenticator implementation didn't provide one, for some reason. + /// If this method returns None as well, the underlying operation will fail + fn get_token<'a>(&'a self, _scopes: &'a [&str]) -> Pin + 'a>> { + Box::pin(async move { Ok(None) }) } } -pub trait AuthyClone { - fn clone_box(&self) -> Box; +pub trait GetTokenClone { + fn clone_box(&self) -> Box; } -impl AuthyClone for T +impl GetTokenClone for T where - T: 'static + Authy + Clone, + T: 'static + GetToken + Clone, { - fn clone_box(&self) -> Box { + fn clone_box(&self) -> Box { Box::new(self.clone()) } } -impl Clone for Box { - fn clone(&self) -> Box { +impl Clone for Box { + fn clone(&self) -> Box { self.clone_box() } } -impl Authy for String { - fn get_token<'a>(&'a self, _scopes: &'a [&str]) -> Pin> + 'a>> { - async fn ident(s: &str) -> Option { - Some(s.to_string()) - } - Box::pin(ident(self)) +impl GetToken for String { + fn get_token<'a>(&'a self, _scopes: &'a [&str]) -> Pin + 'a>> { + Box::pin(async move { Ok(Some(self.clone())) }) } } -impl Authy for () {} +impl GetToken for () {} -#[cfg(feature = "yup-oauth2")] +// TODO: Make this optional +// #[cfg(feature = "yup-oauth2")] mod yup_oauth2_impl { use core::future::Future; use core::pin::Pin; - use super::Authy; + use super::{GetToken, TokenResult}; use tower_service::Service; use yup_oauth2::authenticator::Authenticator; @@ -840,21 +844,16 @@ mod yup_oauth2_impl { use http::Uri; use hyper::client::connect::Connection; - async fn helper(auth: &Authenticator, scopes: &[&str]) -> Option where - S: Service + Clone + Send + Sync + 'static, - S::Response: Connection + AsyncRead + AsyncWrite + Send + Unpin + 'static, - S::Future: Send + Unpin + 'static, - S::Error: Into> { - auth.token(scopes).await.ok().map(|t| t.as_str().to_string()) - } - impl Authy for Authenticator where + impl GetToken for Authenticator where S: Service + Clone + Send + Sync + 'static, S::Response: Connection + AsyncRead + AsyncWrite + Send + Unpin + 'static, S::Future: Send + Unpin + 'static, S::Error: Into> { - fn get_token<'a>(&'a self, scopes: &'a [&str]) -> Pin> + 'a>> { - Box::pin(helper(self, scopes)) + fn get_token<'a>(&'a self, scopes: &'a [&str]) -> Pin + 'a>> { + Box::pin(async move { + self.token(scopes).await.map(|t| Some(t.as_str().to_owned())) + }) } } } From 7c045d7a259396bf1c4ce2b85415d1d3f7b858fa Mon Sep 17 00:00:00 2001 From: philippeitis <33013301+philippeitis@users.noreply.github.com> Date: Sat, 24 Sep 2022 12:13:30 -0700 Subject: [PATCH 04/10] Add yup-oauth2 error to auth error handling --- src/generator/templates/Cargo.toml.mako | 2 ++ src/generator/templates/api/lib/mbuild.mako | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/generator/templates/Cargo.toml.mako b/src/generator/templates/Cargo.toml.mako index 97e0c72b21..7885c43435 100644 --- a/src/generator/templates/Cargo.toml.mako +++ b/src/generator/templates/Cargo.toml.mako @@ -26,6 +26,8 @@ path = "src/main.rs" % endif [dependencies] +## TODO: temporary, remove when yup-oauth2 is optional +anyhow = "^ 1.0" hyper-rustls = "0.23.0" ## Must match the one hyper uses, otherwise there are duplicate similarly named `Mime` structs mime = "^ 0.2.0" diff --git a/src/generator/templates/api/lib/mbuild.mako b/src/generator/templates/api/lib/mbuild.mako index a3f5d4b5cc..7ba7c06a75 100644 --- a/src/generator/templates/api/lib/mbuild.mako +++ b/src/generator/templates/api/lib/mbuild.mako @@ -387,7 +387,7 @@ match result { Error::HttpError(_) |Error::Io(_) |Error::MissingAPIKey - |Error::MissingToken + |Error::MissingToken(_) |Error::Cancelled |Error::UploadSizeLimitExceeded(_, _) |Error::Failure(_) @@ -710,7 +710,7 @@ else { // TODO: remove Ok / Err branches Ok(Some(token)) => token.clone(), Ok(None) => { - let err = oauth2::OtherError("unknown error occurred while generating oauth2 token".into()); + let err = oauth2::Error::OtherError(anyhow::Error::msg("unknown error occurred while generating oauth2 token")); match dlg.token(&err) { Some(token) => token, None => { From fedf48445febb012d50286c9d73808cbf4cc636e Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Sun, 25 Sep 2022 08:32:27 +0800 Subject: [PATCH 05/10] See if this fixes CI by naively swapping 'pages' with 'nav'. --- src/generator/templates/cli/mkdocs.yml.mako | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/generator/templates/cli/mkdocs.yml.mako b/src/generator/templates/cli/mkdocs.yml.mako index 6566f5ad77..82e55adfc8 100644 --- a/src/generator/templates/cli/mkdocs.yml.mako +++ b/src/generator/templates/cli/mkdocs.yml.mako @@ -14,7 +14,7 @@ repo_url: ${util.github_source_root_url()} docs_dir: ${mkdocs.docs_dir} site_dir: ${mkdocs.site_dir} -pages: +nav: - ['index.md', 'Home'] % for resource in sorted(c.rta_map.keys()): % for method in sorted(c.rta_map[resource]): From 49ff295ab9cee7c4f0163fff4571eedde2f53618 Mon Sep 17 00:00:00 2001 From: philippeitis <33013301+philippeitis@users.noreply.github.com> Date: Sun, 25 Sep 2022 00:52:58 +0000 Subject: [PATCH 06/10] Use key-values for nav --- src/generator/templates/cli/mkdocs.yml.mako | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/generator/templates/cli/mkdocs.yml.mako b/src/generator/templates/cli/mkdocs.yml.mako index 82e55adfc8..6b8705a8fa 100644 --- a/src/generator/templates/cli/mkdocs.yml.mako +++ b/src/generator/templates/cli/mkdocs.yml.mako @@ -15,10 +15,10 @@ docs_dir: ${mkdocs.docs_dir} site_dir: ${mkdocs.site_dir} nav: -- ['index.md', 'Home'] +- Home: 'index.md' % for resource in sorted(c.rta_map.keys()): % for method in sorted(c.rta_map[resource]): -- ['${subcommand_md_filename(resource, method)}', '${pretty(resource)}', '${pretty(method)}'] +- '${subcommand_md_filename(resource, method)}': '${pretty(resource)}', '${pretty(method)}' % endfor # each method % endfor # each resource From b3397902c029db8debb482c1b378938fe7ccac3c Mon Sep 17 00:00:00 2001 From: philippeitis <33013301+philippeitis@users.noreply.github.com> Date: Sun, 25 Sep 2022 01:19:56 +0000 Subject: [PATCH 07/10] Update mkdocs.yml.mako --- src/generator/templates/cli/mkdocs.yml.mako | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/generator/templates/cli/mkdocs.yml.mako b/src/generator/templates/cli/mkdocs.yml.mako index 6b8705a8fa..251bad2199 100644 --- a/src/generator/templates/cli/mkdocs.yml.mako +++ b/src/generator/templates/cli/mkdocs.yml.mako @@ -17,8 +17,9 @@ site_dir: ${mkdocs.site_dir} nav: - Home: 'index.md' % for resource in sorted(c.rta_map.keys()): +- '${pretty(resource)}': % for method in sorted(c.rta_map[resource]): -- '${subcommand_md_filename(resource, method)}': '${pretty(resource)}', '${pretty(method)}' + - '${pretty(method)}': '${subcommand_md_filename(resource, method)}' % endfor # each method % endfor # each resource From 586a7d32648fe86cea48462c9a9599dd61f4c0d6 Mon Sep 17 00:00:00 2001 From: philippeitis <33013301+philippeitis@users.noreply.github.com> Date: Sun, 25 Sep 2022 01:32:16 +0000 Subject: [PATCH 08/10] Update root Cargo.toml file --- Cargo.toml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index c4f60196e8..80b5201f71 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,6 +19,7 @@ path = "src/rust/lib.rs" [dependencies] clap = "2" +http = "^0.2" hyper = "0.14" mime = "0.2" rustc-serialize = "*" @@ -30,4 +31,4 @@ strsim = "*" tokio = "^ 1.0" hyper-rustls = "^0.22" itertools = "^ 0.10" -tower-service = "^0.3" \ No newline at end of file +tower-service = "^0.3" From e61090cc75586f7bdcb78b78b849ce642922363c Mon Sep 17 00:00:00 2001 From: philippeitis <33013301+philippeitis@users.noreply.github.com> Date: Sun, 25 Sep 2022 01:48:03 +0000 Subject: [PATCH 09/10] Replace () with documented NoToken for clarity --- src/rust/api/client.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/rust/api/client.rs b/src/rust/api/client.rs index b558c376a0..25b2459830 100644 --- a/src/rust/api/client.rs +++ b/src/rust/api/client.rs @@ -795,7 +795,7 @@ pub async fn get_body_as_string(res_body: &mut hyper::Body) -> String { type TokenResult = std::result::Result, oauth2::Error>; pub trait GetToken: GetTokenClone { - /// Called whenever there is the need for your applications API key after + /// Called whenever there is the need for an oauth token after /// the official authenticator implementation didn't provide one, for some reason. /// If this method returns None as well, the underlying operation will fail fn get_token<'a>(&'a self, _scopes: &'a [&str]) -> Pin + 'a>> { @@ -828,7 +828,12 @@ impl GetToken for String { } } -impl GetToken for () {} +/// In the event that the API endpoint does not require an oauth2 token, `NoToken` should be provided to the hub to avoid specifying an +/// authenticator. +#[derive(Default, Clone)] +pub struct NoToken; + +impl GetToken for NoToken {} // TODO: Make this optional // #[cfg(feature = "yup-oauth2")] From 8e899ae23a540871eaeff78c7a682db2817c0ef8 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Sun, 25 Sep 2022 10:29:44 +0800 Subject: [PATCH 10/10] update changelog --- changelog.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/changelog.md b/changelog.md index 5084d83410..dda9907adf 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,11 @@ +## api/cli-vNEXT (YYYY-MM-DD) + +- New `GetToken` trait for custom ways of specifying a token. The latter can now be a String or be + `NoToken` as well. +- Upgrade `mkdocs` to a more recent version that doesn't break in more recent python interpreters. + ## api/cli-v3.0.0 (2022-3-8) - Support for yup-oauth 0.6