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::client::auth::{AuthOptionResolver, AuthOptionResolverParams, AuthSchemeId};
use crate::client::orchestrator::BoxError;
use std::borrow::Cow;

/// New-type around a `Vec<HttpAuthOption>` that implements `AuthOptionResolver`.
///
/// This is useful for clients that don't require `AuthOptionResolverParams` to resolve auth options.
#[derive(Debug)]
pub struct StaticAuthOptionResolver {
    auth_options: Vec<AuthSchemeId>,
}

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

impl AuthOptionResolver for StaticAuthOptionResolver {
    fn resolve_auth_options(
        &self,
        _params: &AuthOptionResolverParams,
    ) -> Result<Cow<'_, [AuthSchemeId]>, BoxError> {
        Ok(Cow::Borrowed(&self.auth_options))
    }
}

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

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

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