Mercurial > lbo > hg > async-google-apis
changeset 136:798df1eb1fd2
Only require authenticator if API needs authorization
author | Lewin Bormann <lbo@spheniscida.de> |
---|---|
date | Mon, 26 Oct 2020 18:29:30 +0100 |
parents | c8b387f52907 |
children | a9d80ac30fb6 |
files | generate/generate.py generate/templates.py |
diffstat | 2 files changed, 11 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/generate/generate.py Mon Oct 26 18:25:06 2020 +0100 +++ b/generate/generate.py Mon Oct 26 18:29:30 2020 +0100 @@ -410,6 +410,7 @@ ServiceImplementationTmpl, { 'service': service, 'name': capitalize_first(discdoc.get('name', '')), + 'wants_auth': 'auth' in discdoc, 'methods': [{ 'text': t } for t in method_fragments]
--- a/generate/templates.py Mon Oct 26 18:25:06 2020 +0100 +++ b/generate/templates.py Mon Oct 26 18:29:30 2020 +0100 @@ -91,18 +91,24 @@ /// The {{{name}}} {{{service}}} service represents the {{{service}}} resource. pub struct {{{service}}}Service { client: TlsClient, + {{#wants_auth}} authenticator: Box<dyn 'static + std::ops::Deref<Target=Authenticator>>, scopes: Vec<String>, + {{/wants_auth}} } impl {{{service}}}Service { /// Create a new {{service}}Service object. The easiest way to call this is wrapping the Authenticator /// into an `Rc`: `new(client.clone(), Rc::new(authenticator))`. /// This way, one authenticator can be shared among several services. - pub fn new<A: 'static + std::ops::Deref<Target=Authenticator>>(client: TlsClient, auth: A) -> {{service}}Service { - {{{service}}}Service { client: client, authenticator: Box::new(auth), scopes: vec![] } + pub fn new + {{#wants_auth}}<A: 'static + std::ops::Deref<Target=Authenticator>> + {{/wants_auth}}(client: TlsClient{{#wants_auth}}, auth: A{{/wants_auth}}) -> {{service}}Service { + {{{service}}}Service { client: client + {{#wants_auth}}, authenticator: Box::new(auth), scopes: vec![]{{/wants_auth}} } } + {{#wants_auth}} /// Explicitly select which scopes should be requested for authorization. Otherwise, /// a possibly too large scope will be requested. /// @@ -110,9 +116,10 @@ pub fn set_scopes<S: AsRef<str>, T: AsRef<[S]>>(&mut self, scopes: T) { self.scopes = scopes.as_ref().into_iter().map(|s| s.as_ref().to_string()).collect(); } + {{/wants_auth}} {{#methods}} -{{{text}}} + {{{text}}} {{/methods}} } '''