Skip to main content

ProfileStore

Struct ProfileStore 

Source
pub struct ProfileStore {
    path: PathBuf,
    manual: Vec<Profile>,
    discovered_validated_at: HashMap<ProfileId, i64>,
}
Expand description

Aggregate profile store.

Holds manual profiles in memory (loaded from and persisted to ${app_config_dir}/profiles.json). AWS-discovered and env profiles are re-read from their sources on every list call.

Fields§

§path: PathBuf

Path to profiles.json.

§manual: Vec<Profile>

In-memory set of manual profiles.

§discovered_validated_at: HashMap<ProfileId, i64>

Session-scoped validated_at cache for AWS-discovered / env profiles.

These profiles are re-read from ~/.aws/* on every list() call so any validated_at we mark on the in-memory representation would be dropped on the next call. Persisting it to disk is wrong (the user’s ~/.aws/config is theirs and we shouldn’t write to it), so the cache lives here, in memory, for the lifetime of the session and is merged into the freshly-rebuilt profiles by list().

Without this, the validation gate (useValidatedProfile) blocks every action on a discovered profile because its validated_at stays None even after a successful profile_validate.

Implementations§

Source§

impl ProfileStore

Source

pub fn empty(path: PathBuf) -> Self

Construct an empty ProfileStore backed by path, without touching disk. Used as the last-resort fallback when both the primary and temp-dir profiles.json paths are unreadable — the user starts the session with no manual profiles but the app at least opens.

Source

pub fn load(path: impl Into<PathBuf>) -> Result<Self, AppError>

Create a new ProfileStore backed by path.

Loads existing manual profiles from disk if the file exists; starts empty otherwise. Never errors on a missing file.

Source

fn read_from_disk(path: &Path) -> Result<Vec<Profile>, AppError>

Source

fn flush(&self) -> Result<(), AppError>

Persist the current manual profiles to disk atomically.

Source

fn discovered_id(source: &ProfileSource, display_name: &str) -> ProfileId

Derive a stable, deterministic ProfileId for a discovered profile.

Uses a synthetic "aws-discovered:<source_tag>:<display_name>" ID so the value is stable across restarts without needing persistence. Collisions with manually-minted UUID v4 IDs are cosmetically impossible.

Source

pub fn list(&self) -> Vec<Profile>

Return the aggregated list of all profiles.

Aggregation order:

  1. AWS-discovered profiles (read from ~/.aws/* synchronously).
  2. Env-derived synthetic profile (when env vars are present).
  3. Manual profiles (from in-memory store, loaded from disk).

Dedup key: (source, display_name). Manual profiles always win, so they are processed last and overwrite any same-key discovered entry.

Source

pub fn get(&self, id: &ProfileId) -> Option<Profile>

Return the profile with the given id, or None if not found.

Source

pub fn create_manual( &mut self, name: String, secret: Secret, default_region: Option<String>, compat_flags: Option<CompatFlags>, keychain: &mut dyn KeychainBackend, ) -> Result<Profile, AppError>

Create a new manual profile.

  • Mints a stable UUID v4 for the new profile.
  • Persists the secret to the keychain via keychain.
  • Persists profile metadata to disk.

access_key_id and name must be non-empty; returns AppError::Validation otherwise.

Source

pub fn update( &mut self, id: &ProfileId, patch: ProfileUpdatePatch, ) -> Result<Profile, AppError>

Update a manual profile’s name and/or compat flags.

Only display_name, compat_flags, and default_region may be patched. Returns AppError::NotFound if the profile does not exist or is not a manual profile.

Source

pub fn delete( &mut self, id: &ProfileId, keychain: &mut dyn KeychainBackend, ) -> Result<(), AppError>

Delete a manual profile by id.

Also removes the associated keychain entry. Returns AppError::NotFound if the profile does not exist in the manual set.

Source

pub fn mark_validated(&mut self, id: &ProfileId, ts: i64)

Mark a profile as validated at the given Unix-millisecond timestamp.

For manual profiles the timestamp is persisted to profiles.json. For discovered/env profiles it is recorded in the session-scoped discovered_validated_at map and merged back into the freshly rebuilt profiles on every list call. Persisting discovered timestamps to disk would mean writing to the user’s ~/.aws/* files, which we deliberately do not do.

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.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<Unshared, Shared> IntoShared<Shared> for Unshared
where Shared: FromUnshared<Unshared>,

§

fn into_shared(self) -> Shared

Creates a shared type from an unshared type.
§

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<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

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