Skip to content

Commit d26cf77

Browse files
committed
feat(mbuild): use of oauth2::Scheme
That way, we improved our API, reduced code bloat, and are very clear about the what we do for Authorization.
1 parent 030c40d commit d26cf77

4 files changed

Lines changed: 14 additions & 10 deletions

File tree

gen/groupsmigration1/src/cmn.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use std;
66

77
use mime::{Mime, TopLevel, SubLevel, Attr, Value};
88
use oauth2;
9+
use oauth2::TokenType;
910
use hyper;
1011
use hyper::header::{ContentType, ContentLength, Headers, UserAgent, Authorization};
1112
use hyper::http::LINE_ENDING;
@@ -368,7 +369,7 @@ pub struct ResumableUploadHelper<'a, NC: 'a, A: 'a> {
368369
pub delegate: &'a mut Delegate,
369370
pub auth: &'a mut A,
370371
pub user_agent: &'a str,
371-
pub auth_token: String,
372+
pub auth_header: Authorization<oauth2::Scheme>,
372373
pub url: &'a str,
373374
pub reader: &'a mut ReadSeek,
374375
pub media_type: Mime,
@@ -382,7 +383,7 @@ impl<'a, NC, A> ResumableUploadHelper<'a, NC, A>
382383
fn query_transfer_status(&'a mut self) -> (u64, hyper::HttpResult<hyper::client::Response>) {
383384
self.client.post(self.url)
384385
.header(UserAgent(self.user_agent.to_string()))
385-
.header(Authorization("Bearer ".to_string() + &self.auth_token));
386+
.header(self.auth_header.clone());
386387
(0, Err(hyper::error::HttpError::HttpStatusError))
387388
}
388389

gen/groupsmigration1/src/lib.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ impl<'a, C, NC, A> ArchiveInsertCall<'a, C, NC, A> where NC: hyper::net::Network
517517

518518

519519
let mut should_ask_dlg_for_url = false;
520-
let mut upload_url_from_server = true;
520+
let mut upload_url_from_server;
521521
let mut upload_url: Option<String> = None;
522522

523523
loop {
@@ -529,7 +529,8 @@ impl<'a, C, NC, A> ArchiveInsertCall<'a, C, NC, A> where NC: hyper::net::Network
529529
dlg.finished(false);
530530
return Result::MissingToken
531531
}
532-
let auth_header = Authorization("Bearer ".to_string() + &token.unwrap().access_token);
532+
let auth_header = Authorization(oauth2::Scheme { token_type: oauth2::TokenType::Bearer,
533+
access_token: token.unwrap().access_token });
533534
let mut req_result = {
534535
if should_ask_dlg_for_url && (upload_url = dlg.upload_url()) == () && upload_url.is_some() {
535536
should_ask_dlg_for_url = false;
@@ -608,7 +609,7 @@ impl<'a, C, NC, A> ArchiveInsertCall<'a, C, NC, A> where NC: hyper::net::Network
608609
delegate: dlg,
609610
auth: &mut *self.hub.auth.borrow_mut(),
610611
user_agent: &self.hub._user_agent,
611-
auth_token: auth_header.0.clone(),
612+
auth_header: auth_header.clone(),
612613
url: url,
613614
reader: &mut reader,
614615
media_type: reader_mime_type.clone(),

src/mako/lib/mbuild.mako

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -657,7 +657,7 @@ else {
657657
658658
% if resumable_media_param:
659659
let mut should_ask_dlg_for_url = false;
660-
let mut upload_url_from_server = true;
660+
let mut upload_url_from_server;
661661
let mut upload_url: Option<String> = None;
662662
% endif
663663
@@ -671,7 +671,8 @@ else {
671671
${delegate_finish}(false);
672672
return Result::MissingToken
673673
}
674-
let auth_header = Authorization("Bearer ".to_string() + &token.unwrap().access_token);
674+
let auth_header = Authorization(oauth2::Scheme { token_type: oauth2::TokenType::Bearer,
675+
access_token: token.unwrap().access_token });
675676
% endif
676677
% if request_value:
677678
request_value_reader.seek(io::SeekFrom::Start(0)).unwrap();
@@ -786,7 +787,7 @@ else {
786787
delegate: dlg,
787788
auth: &mut *self.hub.auth.borrow_mut(),
788789
user_agent: &self.hub._user_agent,
789-
auth_token: auth_header.0.clone(),
790+
auth_header: auth_header.clone(),
790791
url: url,
791792
reader: &mut reader,
792793
media_type: reader_mime_type.clone(),

src/rust/cmn.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use std;
44

55
use mime::{Mime, TopLevel, SubLevel, Attr, Value};
66
use oauth2;
7+
use oauth2::TokenType;
78
use hyper;
89
use hyper::header::{ContentType, ContentLength, Headers, UserAgent, Authorization};
910
use hyper::http::LINE_ENDING;
@@ -366,7 +367,7 @@ pub struct ResumableUploadHelper<'a, NC: 'a, A: 'a> {
366367
pub delegate: &'a mut Delegate,
367368
pub auth: &'a mut A,
368369
pub user_agent: &'a str,
369-
pub auth_token: String,
370+
pub auth_header: Authorization<oauth2::Scheme>,
370371
pub url: &'a str,
371372
pub reader: &'a mut ReadSeek,
372373
pub media_type: Mime,
@@ -380,7 +381,7 @@ impl<'a, NC, A> ResumableUploadHelper<'a, NC, A>
380381
fn query_transfer_status(&'a mut self) -> (u64, hyper::HttpResult<hyper::client::Response>) {
381382
self.client.post(self.url)
382383
.header(UserAgent(self.user_agent.to_string()))
383-
.header(Authorization("Bearer ".to_string() + &self.auth_token));
384+
.header(self.auth_header.clone());
384385
(0, Err(hyper::error::HttpError::HttpStatusError))
385386
}
386387

0 commit comments

Comments
 (0)