Skip to main content

rustack_ssm_model/
operations.rs

1//! SSM operation enum.
2
3use std::fmt;
4
5/// All supported SSM Parameter Store operations.
6///
7/// Phase 0 implements 6 core operations. The remaining operations are defined
8/// here for forward compatibility but will return "not implemented" until their
9/// respective phases are complete.
10#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
11pub enum SsmOperation {
12    // Phase 0: Core parameter CRUD
13    /// Create or update a parameter.
14    PutParameter,
15    /// Get a single parameter by name (supports version/label selectors).
16    GetParameter,
17    /// Batch get up to 10 parameters by name.
18    GetParameters,
19    /// Get parameters under a path hierarchy.
20    GetParametersByPath,
21    /// Delete a single parameter.
22    DeleteParameter,
23    /// Batch delete up to 10 parameters.
24    DeleteParameters,
25
26    // Phase 1: Discovery and tagging
27    /// Describe parameters with filtering.
28    DescribeParameters,
29    /// Get the version history of a parameter.
30    GetParameterHistory,
31    /// Add tags to a resource.
32    AddTagsToResource,
33    /// Remove tags from a resource.
34    RemoveTagsFromResource,
35    /// List tags for a resource.
36    ListTagsForResource,
37
38    // Phase 2: Labels
39    /// Attach a label to a specific parameter version.
40    LabelParameterVersion,
41    /// Remove a label from a parameter version.
42    UnlabelParameterVersion,
43}
44
45impl SsmOperation {
46    /// Returns the AWS operation name string.
47    #[must_use]
48    pub fn as_str(&self) -> &'static str {
49        match self {
50            Self::PutParameter => "PutParameter",
51            Self::GetParameter => "GetParameter",
52            Self::GetParameters => "GetParameters",
53            Self::GetParametersByPath => "GetParametersByPath",
54            Self::DeleteParameter => "DeleteParameter",
55            Self::DeleteParameters => "DeleteParameters",
56            Self::DescribeParameters => "DescribeParameters",
57            Self::GetParameterHistory => "GetParameterHistory",
58            Self::AddTagsToResource => "AddTagsToResource",
59            Self::RemoveTagsFromResource => "RemoveTagsFromResource",
60            Self::ListTagsForResource => "ListTagsForResource",
61            Self::LabelParameterVersion => "LabelParameterVersion",
62            Self::UnlabelParameterVersion => "UnlabelParameterVersion",
63        }
64    }
65
66    /// Parse an operation name string into an `SsmOperation`.
67    #[must_use]
68    pub fn from_name(name: &str) -> Option<Self> {
69        match name {
70            "PutParameter" => Some(Self::PutParameter),
71            "GetParameter" => Some(Self::GetParameter),
72            "GetParameters" => Some(Self::GetParameters),
73            "GetParametersByPath" => Some(Self::GetParametersByPath),
74            "DeleteParameter" => Some(Self::DeleteParameter),
75            "DeleteParameters" => Some(Self::DeleteParameters),
76            "DescribeParameters" => Some(Self::DescribeParameters),
77            "GetParameterHistory" => Some(Self::GetParameterHistory),
78            "AddTagsToResource" => Some(Self::AddTagsToResource),
79            "RemoveTagsFromResource" => Some(Self::RemoveTagsFromResource),
80            "ListTagsForResource" => Some(Self::ListTagsForResource),
81            "LabelParameterVersion" => Some(Self::LabelParameterVersion),
82            "UnlabelParameterVersion" => Some(Self::UnlabelParameterVersion),
83            _ => None,
84        }
85    }
86
87    /// Returns `true` if this operation is implemented in Phase 0.
88    #[must_use]
89    pub fn is_phase0(&self) -> bool {
90        matches!(
91            self,
92            Self::PutParameter
93                | Self::GetParameter
94                | Self::GetParameters
95                | Self::GetParametersByPath
96                | Self::DeleteParameter
97                | Self::DeleteParameters
98        )
99    }
100
101    /// Returns `true` if this operation is implemented in Phase 1.
102    #[must_use]
103    pub fn is_phase1(&self) -> bool {
104        matches!(
105            self,
106            Self::DescribeParameters
107                | Self::GetParameterHistory
108                | Self::AddTagsToResource
109                | Self::RemoveTagsFromResource
110                | Self::ListTagsForResource
111        )
112    }
113
114    /// Returns `true` if this operation is implemented in Phase 2.
115    #[must_use]
116    pub fn is_phase2(&self) -> bool {
117        matches!(
118            self,
119            Self::LabelParameterVersion | Self::UnlabelParameterVersion
120        )
121    }
122
123    /// Returns `true` if this operation is implemented.
124    #[must_use]
125    pub fn is_implemented(&self) -> bool {
126        self.is_phase0() || self.is_phase1() || self.is_phase2()
127    }
128}
129
130impl fmt::Display for SsmOperation {
131    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
132        f.write_str(self.as_str())
133    }
134}