Skip to main content

coven/
storage_admin.rs

1//! Guided console steps for making an S3 member key by hand (§20.10).
2
3use super::StorageConnections;
4use crate::*;
5
6/// What guided console steps need to make a member key by hand (§20.10).
7#[derive(Clone, Debug, PartialEq, Eq)]
8pub struct GuidedAccessKey {
9    /// The bucket the key must reach, which the store has to itself.
10    pub bucket: String,
11    /// The IAM-style member policy, filled in for this store's bucket.
12    pub policy: String,
13}
14
15impl StorageConnections {
16    pub(crate) async fn guided_access_key(&self) -> Result<GuidedAccessKey, SyncError> {
17        let location = self.codes.location().await?.ok_or(SyncError::NoStorage)?;
18        let StorageConfig::S3 { bucket, .. } = &location else {
19            return Err(StorageFailure::InvalidConfiguration
20                .with_source("only S3 locations have member keys")
21                .into());
22        };
23        Ok(GuidedAccessKey {
24            bucket: bucket.clone(),
25            policy: coven_storage::providers::s3_member_policy(&location)?,
26        })
27    }
28}
29
30#[cfg(test)]
31#[path = "storage_admin_tests.rs"]
32mod tests;