Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rename provider to adapter #334

Merged
merged 4 commits into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions dsc/src/resource_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub fn get(dsc: &DscManager, resource_type: &str, mut input: String, format: &Op
if let Some(pr) = get_resource(dsc, requires) {
resource = pr;
} else {
error!("Provider {} not found", requires);
error!("Adapter {} not found", requires);
return;
};
}
Expand Down Expand Up @@ -64,7 +64,7 @@ pub fn get_all(dsc: &DscManager, resource_type: &str, format: &Option<OutputForm
if let Some(pr) = get_resource(dsc, requires) {
resource = pr;
} else {
error!("Provider '{}' not found", requires);
error!("Adapter '{}' not found", requires);
return;
};
}
Expand Down Expand Up @@ -98,7 +98,7 @@ pub fn get_all(dsc: &DscManager, resource_type: &str, format: &Option<OutputForm
///
/// # Panics
///
/// Will panic if provider-based resource is not found.
/// Will panic if adapter-based resource is not found.
///
pub fn set(dsc: &DscManager, resource_type: &str, mut input: String, format: &Option<OutputFormat>) {
if input.is_empty() {
Expand All @@ -118,7 +118,7 @@ pub fn set(dsc: &DscManager, resource_type: &str, mut input: String, format: &Op
if let Some(pr) = get_resource(dsc, requires) {
resource = pr;
} else {
error!("Provider {} not found", requires);
error!("Adapter {} not found", requires);
return;
};
}
Expand Down Expand Up @@ -146,7 +146,7 @@ pub fn set(dsc: &DscManager, resource_type: &str, mut input: String, format: &Op
///
/// # Panics
///
/// Will panic if provider-based resource is not found.
/// Will panic if adapter-based resource is not found.
///
pub fn test(dsc: &DscManager, resource_type: &str, mut input: String, format: &Option<OutputFormat>) {
let Some(mut resource) = get_resource(dsc, resource_type) else {
Expand All @@ -161,7 +161,7 @@ pub fn test(dsc: &DscManager, resource_type: &str, mut input: String, format: &O
if let Some(pr) = get_resource(dsc, requires) {
resource = pr;
} else {
error!("Provider {} not found", requires);
error!("Adapter {} not found", requires);
return;
};
}
Expand Down Expand Up @@ -216,20 +216,20 @@ pub fn export(dsc: &mut DscManager, resource_type: &str, format: &Option<OutputF
return
};

let mut provider_resource: Option<&DscResource> = None;
let mut adapter_resource: Option<&DscResource> = None;
if let Some(requires) = &dsc_resource.requires {
input = add_type_name_to_json(input, dsc_resource.type_name.clone());
if let Some(pr) = get_resource(dsc, requires) {
provider_resource = Some(pr);
adapter_resource = Some(pr);
} else {
error!("Provider '{}' not found", requires);
error!("Adapter '{}' not found", requires);
return;
};
}

let mut conf = Configuration::new();

if let Err(err) = add_resource_export_results_to_configuration(dsc_resource, provider_resource, &mut conf, &input) {
if let Err(err) = add_resource_export_results_to_configuration(dsc_resource, adapter_resource, &mut conf, &input) {
error!("Error: {err}");
exit(EXIT_DSC_ERROR);
}
Expand Down
6 changes: 3 additions & 3 deletions dsc_lib/src/configure/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ pub enum ErrorAction {
/// # Errors
///
/// This function will return an error if the underlying resource fails.
pub fn add_resource_export_results_to_configuration(resource: &DscResource, provider_resource: Option<&DscResource>, conf: &mut Configuration, input: &str) -> Result<(), DscError> {
pub fn add_resource_export_results_to_configuration(resource: &DscResource, adapter_resource: Option<&DscResource>, conf: &mut Configuration, input: &str) -> Result<(), DscError> {

let export_result = match provider_resource {
Some(_) => provider_resource.unwrap().export(input)?,
let export_result = match adapter_resource {
Some(_) => adapter_resource.unwrap().export(input)?,
_ => resource.export(input)?
};

Expand Down
50 changes: 25 additions & 25 deletions dsc_lib/src/discovery/command_discovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ impl CommandDiscovery {
pb.set_message("Searching for resources");

let mut resources: BTreeMap<String, DscResource> = BTreeMap::new();
let mut provider_resources: Vec<String> = Vec::new();
let mut adapter_resources: Vec<String> = Vec::new();
let mut remaining_required_resource_types = required_resource_types.to_owned();
// try DSC_RESOURCE_PATH env var first otherwise use PATH
let path_env = match env::var_os("DSC_RESOURCE_PATH") {
Expand Down Expand Up @@ -97,8 +97,8 @@ impl CommandDiscovery {

if resource.manifest.is_some() {
let manifest = import_manifest(resource.manifest.clone().unwrap())?;
if manifest.provider.is_some() {
provider_resources.push(resource.type_name.to_lowercase());
if manifest.adapter.is_some() {
adapter_resources.push(resource.type_name.to_lowercase());
resources.insert(resource.type_name.to_lowercase(), resource.clone());
}
}
Expand All @@ -123,30 +123,30 @@ impl CommandDiscovery {
}
}

debug!("Found {} matching non-provider resources", resources.len() - provider_resources.len());
debug!("Found {} matching non-adapter resources", resources.len() - adapter_resources.len());

// now go through the provider resources and add them to the list of resources
for provider in provider_resources {
debug!("Enumerating resources for provider {}", provider);
// now go through the adapter resources and add them to the list of resources
for adapter in adapter_resources {
debug!("Enumerating resources for adapter {}", adapter);
let pb_adapter = multi_progress_bar.add(ProgressBar::new(1));
pb_adapter.enable_steady_tick(Duration::from_millis(120));
pb_adapter.set_style(ProgressStyle::with_template(
"{spinner:.green} [{elapsed_precise:.cyan}] {msg:.white}"
)?);
pb_adapter.set_message(format!("Enumerating resources for adapter {provider}"));
let provider_resource = resources.get(&provider).unwrap();
let provider_type_name = provider_resource.type_name.clone();
let manifest = import_manifest(provider_resource.manifest.clone().unwrap())?;
let mut provider_resources_count = 0;
pb_adapter.set_message(format!("Enumerating resources for adapter {adapter}"));
let adapter_resource = resources.get(&adapter).unwrap();
let adapter_type_name = adapter_resource.type_name.clone();
let manifest = import_manifest(adapter_resource.manifest.clone().unwrap())?;
let mut adapter_resources_count = 0;
// invoke the list command
let list_command = manifest.provider.unwrap().list;
let (exit_code, stdout, stderr) = match invoke_command(&list_command.executable, list_command.args, None, Some(&provider_resource.directory), None)
let list_command = manifest.adapter.unwrap().list;
let (exit_code, stdout, stderr) = match invoke_command(&list_command.executable, list_command.args, None, Some(&adapter_resource.directory), None)
{
Ok((exit_code, stdout, stderr)) => (exit_code, stdout, stderr),
Err(e) => {
/* In case of "resource list" operation - print failure from provider as warning
/* In case of "resource list" operation - print failure from adapter as warning
In case of other resource/config operations:
print failure from provider as error because this provider was specifically requested by current resource/config operation*/
print failure from adapter as error because this adapter was specifically requested by current resource/config operation*/
if return_all_resources {
warn!("Could not start {}: {}", list_command.executable, e);
} else {
Expand All @@ -157,13 +157,13 @@ impl CommandDiscovery {
};

if exit_code != 0 {
/* In case of "resource list" operation - print failure from provider as warning
/* In case of "resource list" operation - print failure from adapter as warning
In case of other resource/config operations:
print failure from provider as error because this provider was specifically requested by current resource/config operation*/
print failure from adapter as error because this adapter was specifically requested by current resource/config operation*/
if return_all_resources {
warn!("Provider failed to list resources with exit code {exit_code}: {stderr}");
warn!("Adapter failed to list resources with exit code {exit_code}: {stderr}");
} else {
error!("Provider failed to list resources with exit code {exit_code}: {stderr}");
error!("Adapter failed to list resources with exit code {exit_code}: {stderr}");
}
}

Expand All @@ -172,16 +172,16 @@ impl CommandDiscovery {
Result::Ok(resource) => {
if resource.requires.is_none() {
if return_all_resources {
warn!("{}", DscError::MissingRequires(provider.clone(), resource.type_name.clone()).to_string());
warn!("{}", DscError::MissingRequires(adapter.clone(), resource.type_name.clone()).to_string());
} else {
error!("{}", DscError::MissingRequires(provider.clone(), resource.type_name.clone()).to_string());
error!("{}", DscError::MissingRequires(adapter.clone(), resource.type_name.clone()).to_string());
}
continue;
}
if return_all_resources
{
resources.insert(resource.type_name.to_lowercase(), resource);
provider_resources_count += 1;
adapter_resources_count += 1;
}
else if remaining_required_resource_types.contains(&resource.type_name.to_lowercase())
{
Expand All @@ -204,9 +204,9 @@ impl CommandDiscovery {
}
};
}
pb_adapter.finish_with_message(format!("Done with {provider}"));
pb_adapter.finish_with_message(format!("Done with {adapter}"));

debug!("Provider {} listed {} matching resources", provider_type_name, provider_resources_count);
debug!("Adapter '{}' listed {} matching resources", adapter_type_name, adapter_resources_count);
}

pb.finish_with_message("Discovery complete");
Expand Down
2 changes: 1 addition & 1 deletion dsc_lib/src/dscerror.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ pub enum DscError {
#[error("Missing manifest: {0}")]
MissingManifest(String),

#[error("Provider source '{0}' missing 'requires' property for resource '{1}'")]
#[error("Adapter-based resource '{0}' missing 'requires' property for resource '{1}'")]
MissingRequires(String, String),

#[error("Schema missing from manifest: {0}")]
Expand Down
2 changes: 1 addition & 1 deletion dsc_lib/src/dscresources/dscresource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub struct DscResource {
pub author: Option<String>,
/// The properties of the resource.
pub properties: Vec<String>,
/// The required resource provider for the resource.
/// The required resource adapter for the resource.
pub requires: Option<String>,
/// The manifest of the resource.
pub manifest: Option<Value>,
Expand Down
14 changes: 7 additions & 7 deletions dsc_lib/src/dscresources/resource_manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ pub struct ResourceManifest {
/// Details how to call the Validate method of the resource.
#[serde(skip_serializing_if = "Option::is_none")]
pub validate: Option<ValidateMethod>,
/// Indicates the resource is a provider of other resources.
/// Indicates the resource is a adapter of other resources.
#[serde(skip_serializing_if = "Option::is_none")]
pub provider: Option<Provider>,
pub adapter: Option<Adapter>,
/// Mapping of exit codes to descriptions. Zero is always success and non-zero is always failure.
#[serde(rename = "exitCodes", skip_serializing_if = "Option::is_none")]
pub exit_codes: Option<HashMap<i32, String>>,
Expand Down Expand Up @@ -167,19 +167,19 @@ pub struct ExportMethod {
}

#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema)]
pub struct Provider {
/// The way to list provider supported resources.
pub struct Adapter {
/// The way to list adapter supported resources.
pub list: ListMethod,
/// Defines how the provider supports accepting configuraiton.
/// Defines how the adapter supports accepting configuraiton.
pub config: ConfigKind,
}

#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema)]
pub enum ConfigKind {
/// The provider accepts full unprocessed configuration.
/// The adapter accepts full unprocessed configuration.
#[serde(rename = "full")]
Full,
/// The provider accepts configuration as a sequence.
/// The adapter accepts configuration as a sequence.
#[serde(rename = "sequence")]
Sequence,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ function Test-TargetResource {
[System.String]
$PackageManagementProvider
)

if (($Name -eq "TestPSRepository1") -and ($PackageManagementProvider -eq 'NuGet'))
{
return $true
Expand Down
6 changes: 3 additions & 3 deletions powershellgroup/powershellgroup.dsc.resource.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
"$schema": "https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2023/08/bundled/resource/manifest.json",
"type": "DSC/PowerShellGroup",
"version": "0.1.0",
"description": "Resource provider to classic DSC Powershell resources.",
"description": "Resource adapter to classic DSC Powershell resources.",
"tags": [
"PowerShell"
],
"provider": {
"adapter": {
"list": {
"executable": "pwsh",
"args": [
Expand Down Expand Up @@ -76,7 +76,7 @@
"-Command",
"$Input | ./powershellgroup.resource.ps1 Validate"
]
},
},
"exitCodes": {
"0": "Success",
"1": "Error"
Expand Down
5 changes: 2 additions & 3 deletions powershellgroup/windowspowershellgroup.resource.json_todo
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"manifestVersion": "1.0",
"type": "DSC/WindowsPowerShellGroup",
"version": "0.1.0",
"description": "Resource provider to classic DSC Powershell resources in Windows PowerShell.",
"provider": {
"description": "Resource adapter to classic DSC Powershell resources in Windows PowerShell.",
"adapter": {
"list": {
"executable": "powershell",
"args": [
Expand Down Expand Up @@ -56,4 +56,3 @@
"1": "Error"
}
}

2 changes: 1 addition & 1 deletion registry/registry.dsc.resource.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2023/08/bundled/resource/manifest.json",
"type": "Microsoft.Windows/Registry",
"description": "Registry configuration provider for the Windows Registry",
"description": "Manage Windows Registry keys and values",
"tags": [
"Windows",
"NT"
Expand Down
4 changes: 2 additions & 2 deletions tools/test_group_resource/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ fn main() {
test: None,
export: None,
validate: None,
provider: None,
adapter: None,
exit_codes: None,
schema: None,
}).unwrap()),
Expand Down Expand Up @@ -67,7 +67,7 @@ fn main() {
test: None,
export: None,
validate: None,
provider: None,
adapter: None,
exit_codes: None,
schema: None,
}).unwrap()),
Expand Down
2 changes: 1 addition & 1 deletion tools/test_group_resource/testGroup.dsc.resource.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
]
}
},
"provider": {
"adapter": {
"list": {
"executable": "test_group_resource",
"args": [
Expand Down
8 changes: 4 additions & 4 deletions tools/test_group_resource/tests/provider.tests.ps1
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.

Describe 'Resource provider tests' {
Describe 'Resource adapter tests' {

It 'Can list provider resources' {
It 'Can list adapter resources' {

$out = dsc resource list *testresource* | ConvertFrom-Json | Sort-Object -Property type
$out.Count | Should -Be 2
Expand All @@ -19,7 +19,7 @@ Describe 'Resource provider tests' {
$out[1].requires | Should -BeExactly 'Test/TestGroup'
}

It 'Error if provider resource is missing "requires" member' {
It 'Error if adapter resource is missing "requires" member' {
$invalid_manifest = @'
{
"$schema": "https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2023/08/bundled/resource/manifest.json",
Expand All @@ -39,7 +39,7 @@ Describe 'Resource provider tests' {
]
}
},
"provider": {
"adapter": {
"list": {
"executable": "test_group_resource",
"args": [
Expand Down
6 changes: 3 additions & 3 deletions wmigroup/wmigroup.dsc.resource.json.optout
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
"$schema": "https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2023/08/bundled/resource/manifest.json",
"type": "DSC/WMIGroup",
"version": "0.1.0",
"description": "Resource provider to WMI resources.",
"description": "Resource adapter to WMI resources.",
"tags": [
"PowerShell"
],
"provider": {
"adapter": {
"list": {
"executable": "powershell",
"args": [
Expand Down Expand Up @@ -39,7 +39,7 @@
"-Command",
"$Input | ./wmigroup.resource.ps1 Validate"
]
},
},
"exitCodes": {
"0": "Success",
"1": "Error"
Expand Down
Loading