Skip to main content

conductor/models/
secret.rs

1// Copyright {{.Year}} Conductor OSS
2// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.
3
4use serde::{Deserialize, Serialize};
5
6/// Metadata tag for resources.
7#[derive(Debug, Clone, Default, Serialize, Deserialize)]
8#[serde(rename_all = "camelCase")]
9pub struct MetadataTag {
10    /// Tag key.
11    pub key: String,
12
13    /// Tag type.
14    #[serde(rename = "type", skip_serializing_if = "Option::is_none")]
15    pub tag_type: Option<String>,
16
17    /// Tag value.
18    #[serde(skip_serializing_if = "Option::is_none")]
19    pub value: Option<String>,
20}
21
22impl MetadataTag {
23    /// Create a new metadata tag.
24    pub fn new(key: impl Into<String>) -> Self {
25        Self {
26            key: key.into(),
27            tag_type: None,
28            value: None,
29        }
30    }
31
32    /// Create a tag with key and value.
33    pub fn with_value(key: impl Into<String>, value: impl Into<String>) -> Self {
34        Self {
35            key: key.into(),
36            tag_type: None,
37            value: Some(value.into()),
38        }
39    }
40
41    /// Set the tag type.
42    #[must_use]
43    pub fn with_type(mut self, tag_type: impl Into<String>) -> Self {
44        self.tag_type = Some(tag_type.into());
45        self
46    }
47}