Skip to content

Commit

Permalink
Revert "Blocked non-list operations on adapters"
Browse files Browse the repository at this point in the history
This reverts commit 6505b11.
  • Loading branch information
anmenaga committed Aug 28, 2024
1 parent ede4ace commit 19c940e
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 69 deletions.
34 changes: 1 addition & 33 deletions dsc/src/resource_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::args::OutputFormat;
use crate::util::{EXIT_DSC_ERROR, EXIT_INVALID_ARGS, EXIT_JSON_ERROR, add_type_name_to_json, write_output};
use dsc_lib::configure::config_doc::{Configuration, ExecutionKind};
use dsc_lib::configure::add_resource_export_results_to_configuration;
use dsc_lib::dscresources::{resource_manifest::Kind, invoke_result::{GetResult, ResourceGetResponse}};
use dsc_lib::dscresources::invoke_result::{GetResult, ResourceGetResponse};
use dsc_lib::dscerror::DscError;
use tracing::{error, debug};

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

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

if let Some(requires) = &resource.require_adapter {
input = add_type_name_to_json(input, resource.type_name.clone());
if let Some(pr) = get_resource(dsc, requires) {
Expand Down Expand Up @@ -64,11 +59,6 @@ pub fn get_all(dsc: &DscManager, resource_type: &str, format: &Option<OutputForm
};

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

if let Some(requires) = &resource.require_adapter {
input = add_type_name_to_json(input, resource.type_name.clone());
if let Some(pr) = get_resource(dsc, requires) {
Expand Down Expand Up @@ -116,10 +106,6 @@ pub fn set(dsc: &DscManager, resource_type: &str, mut input: String, format: &Op
};

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

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

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

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

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

if let Some(requires) = &resource.require_adapter {
input = add_type_name_to_json(input, resource.type_name.clone());
Expand All @@ -232,11 +210,6 @@ pub fn schema(dsc: &DscManager, resource_type: &str, format: &Option<OutputForma
error!("{}", DscError::ResourceNotFound(resource_type.to_string()).to_string());
return
};
if resource.kind == Kind::Adapter {
error!("Can not perform this operation on the adapter {} itself", resource.type_name);
exit(EXIT_DSC_ERROR);
}

match resource.schema() {
Ok(json) => {
// verify is json
Expand All @@ -263,11 +236,6 @@ pub fn export(dsc: &mut DscManager, resource_type: &str, format: &Option<OutputF
return
};

if dsc_resource.kind == Kind::Adapter {
error!("Can not perform this operation on the adapter {} itself", dsc_resource.type_name);
exit(EXIT_DSC_ERROR);
}

let mut adapter_resource: Option<&DscResource> = None;
if let Some(requires) = &dsc_resource.require_adapter {
input = add_type_name_to_json(input, dsc_resource.type_name.clone());
Expand Down
36 changes: 0 additions & 36 deletions dsc/tests/dsc_args.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -272,40 +272,4 @@ resources:
$stderr = dsc config get -d $configFile 2>&1
$stderr | Should -Match '.*?--path.*?'
}

It 'Get operation on the adapter itself should fail' -Tag 'z1' {
dsc resource get -r Microsoft.DSC/PowerShell 2> $TestDrive/tracing.txt
$LASTEXITCODE | Should -Be 2
"$TestDrive/tracing.txt" | Should -FileContentMatchExactly 'Can not perform this operation on the adapter'
}

It 'Get-all operation on the adapter itself should fail' -Tag 'z1' {
dsc resource get --all -r Microsoft.DSC/PowerShell 2> $TestDrive/tracing.txt
$LASTEXITCODE | Should -Be 2
"$TestDrive/tracing.txt" | Should -FileContentMatchExactly 'Can not perform this operation on the adapter'
}

It 'Set operation on the adapter itself should fail' -Tag 'z1' {
'abc' | dsc resource set -r Microsoft.DSC/PowerShell 2> $TestDrive/tracing.txt
$LASTEXITCODE | Should -Be 2
"$TestDrive/tracing.txt" | Should -FileContentMatchExactly 'Can not perform this operation on the adapter'
}

It 'Test operation on the adapter itself should fail' -Tag 'z1' {
dsc resource test -r Microsoft.DSC/PowerShell 2> $TestDrive/tracing.txt
$LASTEXITCODE | Should -Be 2
"$TestDrive/tracing.txt" | Should -FileContentMatchExactly 'Can not perform this operation on the adapter'
}

It 'Export operation on the adapter itself should fail' -Tag 'z1' {
dsc resource export -r Microsoft.DSC/PowerShell 2> $TestDrive/tracing.txt
$LASTEXITCODE | Should -Be 2
"$TestDrive/tracing.txt" | Should -FileContentMatchExactly 'Can not perform this operation on the adapter'
}

It 'Delete operation on the adapter itself should fail' -Tag 'z1' {
dsc resource delete -r Microsoft.DSC/PowerShell 2> $TestDrive/tracing.txt
$LASTEXITCODE | Should -Be 2
"$TestDrive/tracing.txt" | Should -FileContentMatchExactly 'Can not perform this operation on the adapter'
}
}

0 comments on commit 19c940e

Please sign in to comment.