Skip to content

Commit 7c7a511

Browse files
author
Andrew
committed
Reapply "feedback 6"
This reverts commit 3713d14.
1 parent 3713d14 commit 7c7a511

File tree

2 files changed

+33
-41
lines changed

2 files changed

+33
-41
lines changed

dsc/src/resource_command.rs

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::args::OutputFormat;
55
use crate::util::{EXIT_DSC_ERROR, EXIT_INVALID_ARGS, EXIT_JSON_ERROR, add_type_name_to_json, write_output};
66
use dsc_lib::configure::config_doc::{Configuration, ExecutionKind};
77
use dsc_lib::configure::add_resource_export_results_to_configuration;
8-
use dsc_lib::dscresources::invoke_result::{GetResult, ResourceGetResponse};
8+
use dsc_lib::dscresources::{resource_manifest::Kind, invoke_result::{GetResult, ResourceGetResponse}};
99
use dsc_lib::dscerror::DscError;
1010
use tracing::{error, debug};
1111

@@ -22,6 +22,11 @@ pub fn get(dsc: &DscManager, resource_type: &str, mut input: String, format: &Op
2222
};
2323

2424
debug!("resource.type_name - {} implemented_as - {:?}", resource.type_name, resource.implemented_as);
25+
if resource.kind == Kind::Adapter {
26+
error!("Can not perform this operation on the adapter {} itself", resource.type_name);
27+
exit(EXIT_DSC_ERROR);
28+
}
29+
2530
if let Some(requires) = &resource.require_adapter {
2631
input = add_type_name_to_json(input, resource.type_name.clone());
2732
if let Some(pr) = get_resource(dsc, requires) {
@@ -59,6 +64,11 @@ pub fn get_all(dsc: &DscManager, resource_type: &str, format: &Option<OutputForm
5964
};
6065

6166
debug!("resource.type_name - {} implemented_as - {:?}", resource.type_name, resource.implemented_as);
67+
if resource.kind == Kind::Adapter {
68+
error!("Can not perform this operation on the adapter {} itself", resource.type_name);
69+
exit(EXIT_DSC_ERROR);
70+
}
71+
6272
if let Some(requires) = &resource.require_adapter {
6373
input = add_type_name_to_json(input, resource.type_name.clone());
6474
if let Some(pr) = get_resource(dsc, requires) {
@@ -106,6 +116,10 @@ pub fn set(dsc: &DscManager, resource_type: &str, mut input: String, format: &Op
106116
};
107117

108118
debug!("resource.type_name - {} implemented_as - {:?}", resource.type_name, resource.implemented_as);
119+
if resource.kind == Kind::Adapter {
120+
error!("Can not perform this operation on the adapter {} itself", resource.type_name);
121+
exit(EXIT_DSC_ERROR);
122+
}
109123

110124
if let Some(requires) = &resource.require_adapter {
111125
input = add_type_name_to_json(input, resource.type_name.clone());
@@ -148,6 +162,10 @@ pub fn test(dsc: &DscManager, resource_type: &str, mut input: String, format: &O
148162
};
149163

150164
debug!("resource.type_name - {} implemented_as - {:?}", resource.type_name, resource.implemented_as);
165+
if resource.kind == Kind::Adapter {
166+
error!("Can not perform this operation on the adapter {} itself", resource.type_name);
167+
exit(EXIT_DSC_ERROR);
168+
}
151169

152170
if let Some(requires) = &resource.require_adapter {
153171
input = add_type_name_to_json(input, resource.type_name.clone());
@@ -185,6 +203,10 @@ pub fn delete(dsc: &DscManager, resource_type: &str, mut input: String) {
185203
};
186204

187205
debug!("resource.type_name - {} implemented_as - {:?}", resource.type_name, resource.implemented_as);
206+
if resource.kind == Kind::Adapter {
207+
error!("Can not perform this operation on the adapter {} itself", resource.type_name);
208+
exit(EXIT_DSC_ERROR);
209+
}
188210

189211
if let Some(requires) = &resource.require_adapter {
190212
input = add_type_name_to_json(input, resource.type_name.clone());
@@ -210,6 +232,11 @@ pub fn schema(dsc: &DscManager, resource_type: &str, format: &Option<OutputForma
210232
error!("{}", DscError::ResourceNotFound(resource_type.to_string()).to_string());
211233
return
212234
};
235+
if resource.kind == Kind::Adapter {
236+
error!("Can not perform this operation on the adapter {} itself", resource.type_name);
237+
exit(EXIT_DSC_ERROR);
238+
}
239+
213240
match resource.schema() {
214241
Ok(json) => {
215242
// verify is json
@@ -236,6 +263,11 @@ pub fn export(dsc: &mut DscManager, resource_type: &str, format: &Option<OutputF
236263
return
237264
};
238265

266+
if dsc_resource.kind == Kind::Adapter {
267+
error!("Can not perform this operation on the adapter {} itself", dsc_resource.type_name);
268+
exit(EXIT_DSC_ERROR);
269+
}
270+
239271
let mut adapter_resource: Option<&DscResource> = None;
240272
if let Some(requires) = &dsc_resource.require_adapter {
241273
input = add_type_name_to_json(input, dsc_resource.type_name.clone());

dsc_lib/src/dscresources/dscresource.rs

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -188,11 +188,6 @@ pub trait Invoke {
188188

189189
impl Invoke for DscResource {
190190
fn get(&self, filter: &str) -> Result<GetResult, DscError> {
191-
192-
if self.kind == Kind::Adapter {
193-
return Err(DscError::NotSupported(format!("Can not perform this operation on the adapter {} itself", &self.type_name).to_string()));
194-
}
195-
196191
debug!("Invoking get for resource: {}", self.type_name);
197192
match &self.implemented_as {
198193
ImplementedAs::Custom(_custom) => {
@@ -209,11 +204,6 @@ impl Invoke for DscResource {
209204
}
210205

211206
fn set(&self, desired: &str, skip_test: bool, execution_type: &ExecutionKind) -> Result<SetResult, DscError> {
212-
213-
if self.kind == Kind::Adapter {
214-
return Err(DscError::NotSupported(format!("Can not perform this operation on the adapter {} itself", &self.type_name).to_string()));
215-
}
216-
217207
debug!("Invoking set for resource: {}", self.type_name);
218208
match &self.implemented_as {
219209
ImplementedAs::Custom(_custom) => {
@@ -230,11 +220,6 @@ impl Invoke for DscResource {
230220
}
231221

232222
fn test(&self, expected: &str) -> Result<TestResult, DscError> {
233-
234-
if self.kind == Kind::Adapter {
235-
return Err(DscError::NotSupported(format!("Can not perform this operation on the adapter {} itself", &self.type_name).to_string()));
236-
}
237-
238223
debug!("Invoking test for resource: {}", self.type_name);
239224
match &self.implemented_as {
240225
ImplementedAs::Custom(_custom) => {
@@ -279,11 +264,6 @@ impl Invoke for DscResource {
279264
}
280265

281266
fn delete(&self, filter: &str) -> Result<(), DscError> {
282-
283-
if self.kind == Kind::Adapter {
284-
return Err(DscError::NotSupported(format!("Can not perform this operation on the adapter {} itself", &self.type_name).to_string()));
285-
}
286-
287267
debug!("Invoking delete for resource: {}", self.type_name);
288268
match &self.implemented_as {
289269
ImplementedAs::Custom(_custom) => {
@@ -300,11 +280,6 @@ impl Invoke for DscResource {
300280
}
301281

302282
fn validate(&self, config: &str) -> Result<ValidateResult, DscError> {
303-
304-
if self.kind == Kind::Adapter {
305-
return Err(DscError::NotSupported(format!("Can not perform this operation on the adapter {} itself", &self.type_name).to_string()));
306-
}
307-
308283
debug!("Invoking validate for resource: {}", self.type_name);
309284
match &self.implemented_as {
310285
ImplementedAs::Custom(_custom) => {
@@ -321,11 +296,6 @@ impl Invoke for DscResource {
321296
}
322297

323298
fn schema(&self) -> Result<String, DscError> {
324-
325-
if self.kind == Kind::Adapter {
326-
return Err(DscError::NotSupported(format!("Can not perform this operation on the adapter {} itself", &self.type_name).to_string()));
327-
}
328-
329299
debug!("Invoking schema for resource: {}", self.type_name);
330300
match &self.implemented_as {
331301
ImplementedAs::Custom(_custom) => {
@@ -342,11 +312,6 @@ impl Invoke for DscResource {
342312
}
343313

344314
fn export(&self, input: &str) -> Result<ExportResult, DscError> {
345-
346-
if self.kind == Kind::Adapter {
347-
return Err(DscError::NotSupported(format!("Can not perform this operation on the adapter {} itself", &self.type_name).to_string()));
348-
}
349-
350315
debug!("Invoking export for resource: {}", self.type_name);
351316
let Some(manifest) = &self.manifest else {
352317
return Err(DscError::MissingManifest(self.type_name.clone()));
@@ -356,11 +321,6 @@ impl Invoke for DscResource {
356321
}
357322

358323
fn resolve(&self, input: &str) -> Result<ResolveResult, DscError> {
359-
360-
if self.kind == Kind::Adapter {
361-
return Err(DscError::NotSupported(format!("Can not perform this operation on the adapter {} itself", &self.type_name).to_string()));
362-
}
363-
364324
debug!("Invoking resolve for resource: {}", self.type_name);
365325
let Some(manifest) = &self.manifest else {
366326
return Err(DscError::MissingManifest(self.type_name.clone()));

0 commit comments

Comments
 (0)