1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/*
 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
 * SPDX-License-Identifier: Apache-2.0
 */

use crate::box_error::BoxError;
use crate::client::auth::{AuthSchemeId, AuthSchemeOptionResolverParams, ResolveAuthSchemeOptions};
use std::borrow::Cow;

/// New-type around a `Vec<AuthSchemeId>` that implements `ResolveAuthSchemeOptions`.
#[derive(Debug)]
pub struct StaticAuthSchemeOptionResolver {
    auth_scheme_options: Vec<AuthSchemeId>,
}

impl StaticAuthSchemeOptionResolver {
    /// Creates a new instance of `StaticAuthSchemeOptionResolver`.
    pub fn new(auth_scheme_options: Vec<AuthSchemeId>) -> Self {
        Self {
            auth_scheme_options,
        }
    }
}

impl ResolveAuthSchemeOptions for StaticAuthSchemeOptionResolver {
    fn resolve_auth_scheme_options(
        &self,
        _params: &AuthSchemeOptionResolverParams,
    ) -> Result<Cow<'_, [AuthSchemeId]>, BoxError> {
        Ok(Cow::Borrowed(&self.auth_scheme_options))
    }
}

/// Empty params to be used with [`StaticAuthSchemeOptionResolver`].
#[derive(Debug)]
pub struct StaticAuthSchemeOptionResolverParams;

impl StaticAuthSchemeOptionResolverParams {
    /// Creates a new `StaticAuthSchemeOptionResolverParams`.
    pub fn new() -> Self {
        Self
    }
}

impl From<StaticAuthSchemeOptionResolverParams> for AuthSchemeOptionResolverParams {
    fn from(params: StaticAuthSchemeOptionResolverParams) -> Self {
        AuthSchemeOptionResolverParams::new(params)
    }
}