Skip to content

Commit 830edfb

Browse files
committed
Implement review feedback.
1 parent 0e15b86 commit 830edfb

File tree

1 file changed

+55
-107
lines changed

1 file changed

+55
-107
lines changed

src/builder.rs

Lines changed: 55 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -133,135 +133,83 @@ impl SecurityContextBuilder {
133133
self
134134
}
135135

136-
pub fn se_linux_level(&mut self, level: &str) -> &mut Self {
137-
self.security_context.se_linux_options =
138-
Some(self.security_context.se_linux_options.clone().map_or(
139-
SELinuxOptions {
140-
level: Some(level.to_string()),
141-
..SELinuxOptions::default()
142-
},
143-
|o| SELinuxOptions {
144-
level: Some(level.to_string()),
145-
..o
146-
},
147-
));
136+
pub fn se_linux_level(&mut self, level: impl Into<String>) -> &mut Self {
137+
let mut sc = self
138+
.security_context
139+
.se_linux_options
140+
.get_or_insert_with(SELinuxOptions::default);
141+
sc.level = Some(level.into());
148142
self
149143
}
150-
pub fn se_linux_role(&mut self, role: &str) -> &mut Self {
151-
self.security_context.se_linux_options =
152-
Some(self.security_context.se_linux_options.clone().map_or(
153-
SELinuxOptions {
154-
role: Some(role.to_string()),
155-
..SELinuxOptions::default()
156-
},
157-
|o| SELinuxOptions {
158-
role: Some(role.to_string()),
159-
..o
160-
},
161-
));
144+
pub fn se_linux_role(&mut self, role: impl Into<String>) -> &mut Self {
145+
let mut sc = self
146+
.security_context
147+
.se_linux_options
148+
.get_or_insert_with(SELinuxOptions::default);
149+
sc.role = Some(role.into());
162150
self
163151
}
164-
pub fn se_linux_type(&mut self, type_: &str) -> &mut Self {
165-
self.security_context.se_linux_options =
166-
Some(self.security_context.se_linux_options.clone().map_or(
167-
SELinuxOptions {
168-
type_: Some(type_.to_string()),
169-
..SELinuxOptions::default()
170-
},
171-
|o| SELinuxOptions {
172-
type_: Some(type_.to_string()),
173-
..o
174-
},
175-
));
152+
153+
pub fn se_linux_type(&mut self, type_: impl Into<String>) -> &mut Self {
154+
let mut sc = self
155+
.security_context
156+
.se_linux_options
157+
.get_or_insert_with(SELinuxOptions::default);
158+
sc.type_ = Some(type_.into());
176159
self
177160
}
178-
pub fn se_linux_user(&mut self, user: &str) -> &mut Self {
179-
self.security_context.se_linux_options =
180-
Some(self.security_context.se_linux_options.clone().map_or(
181-
SELinuxOptions {
182-
user: Some(user.to_string()),
183-
..SELinuxOptions::default()
184-
},
185-
|o| SELinuxOptions {
186-
user: Some(user.to_string()),
187-
..o
188-
},
189-
));
161+
162+
pub fn se_linux_user(&mut self, user: impl Into<String>) -> &mut Self {
163+
let mut sc = self
164+
.security_context
165+
.se_linux_options
166+
.get_or_insert_with(SELinuxOptions::default);
167+
sc.user = Some(user.into());
190168
self
191169
}
192170

193-
pub fn seccomp_profile_localhost(&mut self, profile: &str) -> &mut Self {
194-
self.security_context.seccomp_profile =
195-
Some(self.security_context.seccomp_profile.clone().map_or(
196-
SeccompProfile {
197-
localhost_profile: Some(profile.to_string()),
198-
..SeccompProfile::default()
199-
},
200-
|o| SeccompProfile {
201-
localhost_profile: Some(profile.to_string()),
202-
..o
203-
},
204-
));
171+
pub fn seccomp_profile_localhost(&mut self, profile: impl Into<String>) -> &mut Self {
172+
let mut sc = self
173+
.security_context
174+
.seccomp_profile
175+
.get_or_insert_with(SeccompProfile::default);
176+
sc.localhost_profile = Some(profile.into());
205177
self
206178
}
207179

208-
pub fn seccomp_profile_type(&mut self, type_: &str) -> &mut Self {
209-
self.security_context.seccomp_profile =
210-
Some(self.security_context.seccomp_profile.clone().map_or(
211-
SeccompProfile {
212-
type_: type_.to_string(),
213-
..SeccompProfile::default()
214-
},
215-
|o| SeccompProfile {
216-
type_: type_.to_string(),
217-
..o
218-
},
219-
));
180+
pub fn seccomp_profile_type(&mut self, type_: impl Into<String>) -> &mut Self {
181+
let mut sc = self
182+
.security_context
183+
.seccomp_profile
184+
.get_or_insert_with(SeccompProfile::default);
185+
sc.type_ = type_.into();
220186
self
221187
}
222188

223-
pub fn win_credential_spec(&mut self, spec: &str) -> &mut Self {
224-
self.security_context.windows_options =
225-
Some(self.security_context.windows_options.clone().map_or(
226-
WindowsSecurityContextOptions {
227-
gmsa_credential_spec: Some(spec.to_string()),
228-
..WindowsSecurityContextOptions::default()
229-
},
230-
|o| WindowsSecurityContextOptions {
231-
gmsa_credential_spec: Some(spec.to_string()),
232-
..o
233-
},
234-
));
189+
pub fn win_credential_spec(&mut self, spec: impl Into<String>) -> &mut Self {
190+
let mut wo = self
191+
.security_context
192+
.windows_options
193+
.get_or_insert_with(WindowsSecurityContextOptions::default);
194+
wo.gmsa_credential_spec = Some(spec.into());
235195
self
236196
}
237197

238-
pub fn win_credential_spec_name(&mut self, name: &str) -> &mut Self {
239-
self.security_context.windows_options =
240-
Some(self.security_context.windows_options.clone().map_or(
241-
WindowsSecurityContextOptions {
242-
gmsa_credential_spec_name: Some(name.to_string()),
243-
..WindowsSecurityContextOptions::default()
244-
},
245-
|o| WindowsSecurityContextOptions {
246-
gmsa_credential_spec_name: Some(name.to_string()),
247-
..o
248-
},
249-
));
198+
pub fn win_credential_spec_name(&mut self, name: impl Into<String>) -> &mut Self {
199+
let mut wo = self
200+
.security_context
201+
.windows_options
202+
.get_or_insert_with(WindowsSecurityContextOptions::default);
203+
wo.gmsa_credential_spec_name = Some(name.into());
250204
self
251205
}
252206

253207
pub fn win_run_as_user_name(&mut self, name: &str) -> &mut Self {
254-
self.security_context.windows_options =
255-
Some(self.security_context.windows_options.clone().map_or(
256-
WindowsSecurityContextOptions {
257-
run_as_user_name: Some(name.to_string()),
258-
..WindowsSecurityContextOptions::default()
259-
},
260-
|o| WindowsSecurityContextOptions {
261-
run_as_user_name: Some(name.to_string()),
262-
..o
263-
},
264-
));
208+
let mut wo = self
209+
.security_context
210+
.windows_options
211+
.get_or_insert_with(WindowsSecurityContextOptions::default);
212+
wo.run_as_user_name = Some(name.into());
265213
self
266214
}
267215
}

0 commit comments

Comments
 (0)