Skip to content

Commit 3713d14

Browse files
author
Andrew
committed
Revert "feedback 6"
This reverts commit dc9f6b7.
1 parent dc9f6b7 commit 3713d14

File tree

2 files changed

+41
-33
lines changed

2 files changed

+41
-33
lines changed

dsc/src/resource_command.rs

Lines changed: 1 addition & 33 deletions
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::{resource_manifest::Kind, invoke_result::{GetResult, ResourceGetResponse}};
8+
use dsc_lib::dscresources::invoke_result::{GetResult, ResourceGetResponse};
99
use dsc_lib::dscerror::DscError;
1010
use tracing::{error, debug};
1111

@@ -22,11 +22,6 @@ 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-
3025
if let Some(requires) = &resource.require_adapter {
3126
input = add_type_name_to_json(input, resource.type_name.clone());
3227
if let Some(pr) = get_resource(dsc, requires) {
@@ -64,11 +59,6 @@ pub fn get_all(dsc: &DscManager, resource_type: &str, format: &Option<OutputForm
6459
};
6560

6661
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-
7262
if let Some(requires) = &resource.require_adapter {
7363
input = add_type_name_to_json(input, resource.type_name.clone());
7464
if let Some(pr) = get_resource(dsc, requires) {
@@ -116,10 +106,6 @@ pub fn set(dsc: &DscManager, resource_type: &str, mut input: String, format: &Op
116106
};
117107

118108
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-
}
123109

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

164150
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-
}
169151

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

205187
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-
}
210188

211189
if let Some(requires) = &resource.require_adapter {
212190
input = add_type_name_to_json(input, resource.type_name.clone());
@@ -232,11 +210,6 @@ pub fn schema(dsc: &DscManager, resource_type: &str, format: &Option<OutputForma
232210
error!("{}", DscError::ResourceNotFound(resource_type.to_string()).to_string());
233211
return
234212
};
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-
240213
match resource.schema() {
241214
Ok(json) => {
242215
// verify is json
@@ -263,11 +236,6 @@ pub fn export(dsc: &mut DscManager, resource_type: &str, format: &Option<OutputF
263236
return
264237
};
265238

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-
271239
let mut adapter_resource: Option<&DscResource> = None;
272240
if let Some(requires) = &dsc_resource.require_adapter {
273241
input = add_type_name_to_json(input, dsc_resource.type_name.clone());

dsc_lib/src/dscresources/dscresource.rs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,11 @@ 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+
191196
debug!("Invoking get for resource: {}", self.type_name);
192197
match &self.implemented_as {
193198
ImplementedAs::Custom(_custom) => {
@@ -204,6 +209,11 @@ impl Invoke for DscResource {
204209
}
205210

206211
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+
207217
debug!("Invoking set for resource: {}", self.type_name);
208218
match &self.implemented_as {
209219
ImplementedAs::Custom(_custom) => {
@@ -220,6 +230,11 @@ impl Invoke for DscResource {
220230
}
221231

222232
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+
223238
debug!("Invoking test for resource: {}", self.type_name);
224239
match &self.implemented_as {
225240
ImplementedAs::Custom(_custom) => {
@@ -264,6 +279,11 @@ impl Invoke for DscResource {
264279
}
265280

266281
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+
267287
debug!("Invoking delete for resource: {}", self.type_name);
268288
match &self.implemented_as {
269289
ImplementedAs::Custom(_custom) => {
@@ -280,6 +300,11 @@ impl Invoke for DscResource {
280300
}
281301

282302
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+
283308
debug!("Invoking validate for resource: {}", self.type_name);
284309
match &self.implemented_as {
285310
ImplementedAs::Custom(_custom) => {
@@ -296,6 +321,11 @@ impl Invoke for DscResource {
296321
}
297322

298323
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+
299329
debug!("Invoking schema for resource: {}", self.type_name);
300330
match &self.implemented_as {
301331
ImplementedAs::Custom(_custom) => {
@@ -312,6 +342,11 @@ impl Invoke for DscResource {
312342
}
313343

314344
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+
315350
debug!("Invoking export for resource: {}", self.type_name);
316351
let Some(manifest) = &self.manifest else {
317352
return Err(DscError::MissingManifest(self.type_name.clone()));
@@ -321,6 +356,11 @@ impl Invoke for DscResource {
321356
}
322357

323358
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+
324364
debug!("Invoking resolve for resource: {}", self.type_name);
325365
let Some(manifest) = &self.manifest else {
326366
return Err(DscError::MissingManifest(self.type_name.clone()));

0 commit comments

Comments
 (0)