Skip to main content

FakeImds

Struct FakeImds 

Source
pub struct FakeImds {
    state: Mutex<ImdsState>,
    lifetime: Duration,
}
Expand description

The instance metadata service, as far as InstanceCredentials is concerned: a source of temporary credentials, each with a stated expiry.

Every read issues a new access key id, so a test can tell which credential a request was signed with, and FakeAws refuses a request signed with one this holder no longer considers live — the way Route53 answers ExpiredTokenException to a signature made with a lapsed instance-profile credential.

Fields§

§state: Mutex<ImdsState>§lifetime: Duration

Implementations§

Source§

impl FakeImds

Source

pub fn new() -> Arc<Self>

A metadata service whose credentials last six hours — long enough that InstanceCredentials::current never refreshes on its own, so a test that wants a refresh asks for one with FakeAws::expire_credential or FakeAws::expire_credential_after.

Source

pub fn with_lifetime(lifetime: Duration) -> Arc<Self>

A metadata service whose credentials last lifetime.

Source

pub fn credentials( self: &Arc<Self>, ) -> Result<Arc<InstanceCredentials>, ImdsError>

A credential holder that reads this service, with its first read already made — the same shape InstanceCredentials::from_instance_metadata returns.

§Errors

Whatever the first read answers, so a test can start from a metadata service that refuses.

Source

pub fn reads(&self) -> u64

How many times the credential endpoint has been read.

Source

pub fn issued(&self) -> Vec<String>

The access key ids this service has issued, oldest first.

Source

pub fn fail_next(&self, count: u32)

Answers the next count reads with an error instead of a credential.

Source

pub fn expire_current(&self)

Stops accepting the access key id this service issued most recently.

This is the service’s half of an expiry: a request still signed with that key id is refused from here on. The holder’s half — InstanceCredentials noticing that what it holds is past its stated expiry and reading again — is FakeAws::expire_credential, which does both.

Source

pub fn is_live(&self, access_key_id: &str) -> bool

Whether a request signed with access_key_id is still accepted.

Source

fn guard(&self) -> MutexGuard<'_, ImdsState>

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> PolicyExt for T
where T: ?Sized,

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more