s2_api/v1/
basin.rs

1use s2_common::types::{
2    self,
3    basin::{BasinName, BasinNamePrefix, BasinNameStartAfter},
4};
5use serde::{Deserialize, Serialize};
6
7use super::config::BasinConfig;
8
9#[rustfmt::skip]
10#[derive(Debug, Clone, Serialize, Deserialize)]
11#[cfg_attr(feature = "utoipa", derive(utoipa::IntoParams))]
12#[cfg_attr(feature = "utoipa", into_params(parameter_in = Query))]
13pub struct ListBasinsRequest {
14    /// Filter to basins whose names begin with this prefix.
15    #[cfg_attr(feature = "utoipa", param(value_type = String, default = "", required = false))]
16    pub prefix: Option<BasinNamePrefix>,
17    /// Filter to basins whose names lexicographically start after this string.
18    /// It must be greater than or equal to the `prefix` if specified.
19    #[cfg_attr(feature = "utoipa", param(value_type = String, default = "", required = false))]
20    pub start_after: Option<BasinNameStartAfter>,
21    /// Number of results, up to a maximum of 1000.
22    #[cfg_attr(feature = "utoipa", param(value_type = usize, maximum = 1000, default = 1000, required = false))]
23    pub limit: Option<usize>,
24}
25
26super::impl_list_request_conversions!(
27    ListBasinsRequest,
28    types::basin::BasinNamePrefix,
29    types::basin::BasinNameStartAfter
30);
31
32#[rustfmt::skip]
33#[derive(Debug, Clone, Serialize, Deserialize)]
34#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
35pub struct ListBasinsResponse {
36    /// Matching basins.
37    #[cfg_attr(feature = "utoipa", schema(max_items = 1000))]
38    pub basins: Vec<BasinInfo>,
39    /// Indicates that there are more basins that match the criteria.
40    pub has_more: bool,
41}
42
43#[rustfmt::skip]
44#[derive(Debug, Clone, Serialize, Deserialize)]
45#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
46pub struct BasinInfo {
47    /// Basin name.
48    pub name: BasinName,
49    /// Basin scope.
50    pub scope: Option<BasinScope>,
51    /// Basin state.
52    pub state: BasinState,
53}
54
55impl From<types::basin::BasinInfo> for BasinInfo {
56    fn from(value: types::basin::BasinInfo) -> Self {
57        let types::basin::BasinInfo { name, scope, state } = value;
58
59        Self {
60            name,
61            scope: scope.map(Into::into),
62            state: state.into(),
63        }
64    }
65}
66
67#[rustfmt::skip]
68#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
69#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
70pub enum BasinScope {
71    /// AWS `us-east-1` region.
72    #[serde(rename = "aws:us-east-1")]
73    AwsUsEast1,
74}
75
76impl From<BasinScope> for types::basin::BasinScope {
77    fn from(value: BasinScope) -> Self {
78        match value {
79            BasinScope::AwsUsEast1 => Self::AwsUsEast1,
80        }
81    }
82}
83
84impl From<types::basin::BasinScope> for BasinScope {
85    fn from(value: types::basin::BasinScope) -> Self {
86        match value {
87            types::basin::BasinScope::AwsUsEast1 => Self::AwsUsEast1,
88        }
89    }
90}
91
92#[rustfmt::skip]
93#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
94#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
95#[serde(rename_all = "kebab-case")]
96pub enum BasinState {
97    /// Basin is active.
98    Active,
99    /// Basin is being created.
100    Creating,
101    /// Basin is being deleted.
102    Deleting,
103}
104
105impl From<types::basin::BasinState> for BasinState {
106    fn from(value: types::basin::BasinState) -> Self {
107        match value {
108            types::basin::BasinState::Active => Self::Active,
109            types::basin::BasinState::Creating => Self::Creating,
110            types::basin::BasinState::Deleting => Self::Deleting,
111        }
112    }
113}
114
115#[rustfmt::skip]
116#[derive(Debug, Clone, Serialize, Deserialize)]
117#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
118pub struct CreateOrReconfigureBasinRequest {
119    /// Basin configuration.
120    pub config: Option<BasinConfig>,
121    /// Basin scope.
122    /// This cannot be reconfigured.
123    pub scope: Option<BasinScope>,
124}
125
126#[rustfmt::skip]
127#[derive(Debug, Clone, Serialize, Deserialize)]
128#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
129pub struct CreateBasinRequest {
130    /// Basin name which must be globally unique.
131    /// It can be between 8 and 48 bytes in length, and comprise lowercase letters, numbers and hyphens.
132    /// It cannot begin or end with a hyphen.
133    pub basin: BasinName,
134    /// Basin configuration.
135    pub config: Option<BasinConfig>,
136    /// Basin scope.
137    pub scope: Option<BasinScope>,
138}