Skip to main content

compose_lens/model/
credential_spec.rs

1//! Source-aware service credential-spec configuration.
2
3use crate::source::SourceSpan;
4
5use super::{FieldReference, Located};
6
7/// An explicitly authored service `credential_spec` mapping.
8#[derive(Debug, Clone, PartialEq, Eq)]
9pub struct CredentialSpec {
10    span: SourceSpan,
11    config: Option<Located<String>>,
12    file: Option<Located<String>>,
13    registry: Option<Located<String>>,
14    extension_fields: Vec<FieldReference>,
15    unknown_fields: Vec<FieldReference>,
16}
17
18impl CredentialSpec {
19    pub(crate) const fn new(span: SourceSpan) -> Self {
20        Self {
21            span,
22            config: None,
23            file: None,
24            registry: None,
25            extension_fields: Vec::new(),
26            unknown_fields: Vec::new(),
27        }
28    }
29
30    pub(crate) fn set_config(&mut self, value: Located<String>) {
31        self.config = Some(value);
32    }
33
34    pub(crate) fn set_file(&mut self, value: Located<String>) {
35        self.file = Some(value);
36    }
37
38    pub(crate) fn set_registry(&mut self, value: Located<String>) {
39        self.registry = Some(value);
40    }
41
42    pub(crate) fn push_extension(&mut self, field: FieldReference) {
43        self.extension_fields.push(field);
44    }
45
46    pub(crate) fn push_unknown(&mut self, field: FieldReference) {
47        self.unknown_fields.push(field);
48    }
49
50    /// Returns the complete authored credential-spec mapping span.
51    #[must_use]
52    pub const fn span(&self) -> SourceSpan {
53        self.span
54    }
55
56    /// Returns the raw authored config reference without resolving top-level configs.
57    #[must_use]
58    pub const fn config(&self) -> Option<&Located<String>> {
59        self.config.as_ref()
60    }
61
62    /// Returns the raw authored file reference without accessing the filesystem.
63    #[must_use]
64    pub const fn file(&self) -> Option<&Located<String>> {
65        self.file.as_ref()
66    }
67
68    /// Returns the raw authored registry reference without account or registry access.
69    #[must_use]
70    pub const fn registry(&self) -> Option<&Located<String>> {
71        self.registry.as_ref()
72    }
73
74    /// Returns retained `x-*` members.
75    #[must_use]
76    pub fn extension_fields(&self) -> &[FieldReference] {
77        &self.extension_fields
78    }
79
80    /// Returns retained unknown or malformed members.
81    #[must_use]
82    pub fn unknown_fields(&self) -> &[FieldReference] {
83        &self.unknown_fields
84    }
85}