pub struct GoogleSigner { /* private fields */ }Expand description
Implementations§
Source§impl Signer
impl Signer
Sourcepub fn region(&mut self, region: &str) -> &mut Self
pub fn region(&mut self, region: &str) -> &mut Self
Set the region name that used for google v4 signing.
Default to auto
Sourcepub fn sign(&self, req: &mut impl SignableRequest, token: &Token) -> Result<()>
pub fn sign(&self, req: &mut impl SignableRequest, token: &Token) -> Result<()>
Signing request.
§Example
use anyhow::Result;
use reqsign::GoogleSigner;
use reqsign::GoogleTokenLoader;
use reqwest::Client;
use reqwest::Request;
use reqwest::Url;
#[tokio::main]
async fn main() -> Result<()> {
// Signer will load region and credentials from environment by default.
let token_loader = GoogleTokenLoader::new(
"https://www.googleapis.com/auth/devstorage.read_only",
Client::new(),
);
let signer = GoogleSigner::new("storage");
// Construct request
let url = Url::parse("https://storage.googleapis.com/storage/v1/b/test")?;
let mut req = reqwest::Request::new(http::Method::GET, url);
// Signing request with Signer
let token = token_loader.load().await?.unwrap();
signer.sign(&mut req, &token)?;
// Sending already signed request.
let resp = Client::new().execute(req).await?;
println!("resp got status: {}", resp.status());
Ok(())
}§TODO
we can also send API via signed JWT: Addendum: Service account authorization without OAuth
Sourcepub fn sign_query(
&self,
req: &mut impl SignableRequest,
duration: Duration,
cred: &Credential,
) -> Result<()>
pub fn sign_query( &self, req: &mut impl SignableRequest, duration: Duration, cred: &Credential, ) -> Result<()>
Sign the query with a duration.
§Example
use std::time::Duration;
use anyhow::Result;
use reqsign::GoogleCredentialLoader;
use reqsign::GoogleSigner;
use reqwest::Client;
use reqwest::Url;
#[tokio::main]
async fn main() -> Result<()> {
// Signer will load region and credentials from environment by default.
let credential_loader = GoogleCredentialLoader::default();
let signer = GoogleSigner::new("stroage");
// Construct request
let url = Url::parse("https://storage.googleapis.com/testbucket-reqsign/CONTRIBUTING.md")?;
let mut req = reqwest::Request::new(http::Method::GET, url);
// Signing request with Signer
let credential = credential_loader.load()?.unwrap();
signer.sign_query(&mut req, Duration::from_secs(3600), &credential)?;
println!("signed request: {:?}", req);
// Sending already signed request.
let resp = Client::new().execute(req).await?;
println!("resp got status: {}", resp.status());
println!("resp got body: {}", resp.text().await?);
Ok(())
}Auto Trait Implementations§
impl Freeze for Signer
impl RefUnwindSafe for Signer
impl Send for Signer
impl Sync for Signer
impl Unpin for Signer
impl UnsafeUnpin for Signer
impl UnwindSafe for Signer
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ServiceExt for T
impl<T> ServiceExt for T
Source§fn map_response_body<F>(self, f: F) -> MapResponseBody<Self, F>where
Self: Sized,
fn map_response_body<F>(self, f: F) -> MapResponseBody<Self, F>where
Self: Sized,
Apply a transformation to the response body. Read more
Source§fn decompression(self) -> Decompression<Self>where
Self: Sized,
fn decompression(self) -> Decompression<Self>where
Self: Sized,
Decompress response bodies. Read more
Source§fn trace_for_http(self) -> Trace<Self, SharedClassifier<ServerErrorsAsFailures>>where
Self: Sized,
fn trace_for_http(self) -> Trace<Self, SharedClassifier<ServerErrorsAsFailures>>where
Self: Sized,
High level tracing that classifies responses using HTTP status codes. Read more
Source§fn trace_for_grpc(self) -> Trace<Self, SharedClassifier<GrpcErrorsAsFailures>>where
Self: Sized,
fn trace_for_grpc(self) -> Trace<Self, SharedClassifier<GrpcErrorsAsFailures>>where
Self: Sized,
High level tracing that classifies responses using gRPC headers. Read more