Skip to content
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
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions lib/dsc-lib-jsonschema/.versions.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
{
"latestMajor": "V3",
"latestMinor": "V3_1",
"latestPatch": "V3_1_3",
"latestMinor": "V3_2",
"latestPatch": "V3_2_0",
"all": [
"V3",
"V3_2",
"V3_2_0",
"V3_1",
"V3_1_3",
"V3_1_2",
Expand Down
2 changes: 1 addition & 1 deletion lib/dsc-lib-registry/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "dsc-lib-registry"
version = "0.1.0"
version = "1.1.0"
edition = "2024"

[package.metadata.i18n]
Expand Down
2 changes: 0 additions & 2 deletions lib/dsc-lib-registry/locales/en-us.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,3 @@ unsupportedValueDataType = "Unsupported registry value data type"
whatIfCreateKey = "Key '%{subkey}' not found, would create it"
whatIfDeleteValue = "Would delete value '%{value_name}'"
whatIfDeleteSubkey = "Would delete subkey '%{subkey_name}'"
removeErrorKeyNotExist = "Key already does not exist"
removeDeletingSubKey = "Deleting subkey '%{name}' using %{parent}"
30 changes: 25 additions & 5 deletions lib/dsc-lib-registry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ impl RegistryHelper {
///
/// # Arguments
///
/// * `config` - The string with registry configuration information.
/// * `registry_entry` - The string with registry configuration information.
///
/// # Errors
///
/// * `RegistryError` - The error that occurred.
pub fn new_from_json(config: &str) -> Result<Self, RegistryError> {
let registry: Registry = match serde_json::from_str(config) {
pub fn new_from_json(registry_entry: &str) -> Result<Self, RegistryError> {
let registry: Registry = match serde_json::from_str(registry_entry) {
Ok(config) => config,
Err(e) => return Err(RegistryError::Json(e)),
};
Expand All @@ -47,6 +47,28 @@ impl RegistryHelper {
)
}

/// Create a new `RegistryHelper` from registry configuration.
///
/// # Arguments
///
/// * `registry_entry` - The registry configuration struct.
///
/// # Errors
///
/// * `RegistryError` - The error that occurred.
pub fn new_from_registry(registry_entry: &Registry) -> Result<Self, RegistryError> {
let (hive, subkey) = get_hive_from_path(&registry_entry.key_path)?;

Ok(
Self {
config: registry_entry.clone(),
hive,
subkey: subkey.to_string(),
what_if: false
}
)
}

/// Create a new `RegistryHelper`.
///
/// # Arguments
Expand Down Expand Up @@ -266,7 +288,6 @@ impl RegistryHelper {
Ok(reg_key) => reg_key,
// handle NotFound error
Err(RegistryError::RegistryKeyNotFound(_)) => {
eprintln!("{}", t!("registry_helper.removeErrorKeyNotExist"));
return Ok(None);
},
Err(RegistryError::RegistryKey(key::Error::PermissionDenied(_, _))) => {
Expand Down Expand Up @@ -318,7 +339,6 @@ impl RegistryHelper {
..Default::default()
}));
}
eprintln!("{}", t!("registry_helper.removeDeletingSubKey", name = subkey_name, parent = parent_reg_key));
let Ok(subkey_name) = UCString::<u16>::from_str(subkey_name) else {
return self.handle_error_or_what_if(RegistryError::Utf16Conversion("subkey_name".to_string()));
};
Expand Down
2 changes: 1 addition & 1 deletion lib/dsc-lib/locales/en-us.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ valueCouldNotBeTransformedAsString = "Property value '%{value}' could not be tra
elevationRequired = "Elevated security context required"
restrictedRequired = "Restricted security context required"
desired = "Desired state: %{state}"
handlesExist = "Resource handles _exist or _exist is true"
handlesExist = "Resource set handles _exist"
implementsDelete = "Resource implements delete and _exist is false"
groupNotSupportedForDelete = "Group resources not supported for delete"
deleteNotSupported = "Resource '%{resource}' does not support `delete` and does not handle `_exist` as false"
Expand Down
2 changes: 1 addition & 1 deletion resources/registry/.project.data.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
],
"CopyFiles": {
"Windows": [
"registry.dsc.resource.json"
"registry.dsc.manifests.json"
]
}
}
1 change: 1 addition & 0 deletions resources/registry/locales/en-us.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ findArgsRecurseHelp = "Recursively find."
findArgsKeysOnlyHelp = "Only find keys."
findArgsValuesOnlyHelp = "Only find values."
schemaAbout = "Retrieve JSON schema."
schemaArgsListHelp = "Retrieve JSON schema for RegistryList."

[main]
tracingInitError = "Unable to set global default tracing subscriber. Tracing is disabled."
Expand Down
122 changes: 122 additions & 0 deletions resources/registry/registry.dsc.manifests.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
{
"resources": [
{
"$schema": "https://aka.ms/dsc/schemas/v3/bundled/resource/manifest.json",
"type": "Microsoft.Windows/Registry",
"description": "Manage Windows Registry keys and values",
"tags": [
"Windows"
],
"version": "1.0.0",
"get": {
"executable": "registry",
"args": [
"config",
"get",
{
"jsonInputArg": "--input",
"mandatory": true
}
]
},
"set": {
"executable": "registry",
"args": [
"config",
"set",
{
"jsonInputArg": "--input",
"mandatory": true
},
{
"whatIfArg": "-w"
}
],
"whatIfReturns": "state"
},
"delete": {
"executable": "registry",
"args": [
"config",
"delete",
{
"jsonInputArg": "--input",
"mandatory": true
},
{
"whatIfArg": "-w"
}
]
},
"exitCodes": {
"0": "Success",
"1": "Invalid parameter",
"2": "Invalid input",
"3": "Registry error",
"4": "JSON serialization failed"
},
"schema": {
"command": {
"executable": "registry",
"args": [
"schema"
]
}
}
},
{
"$schema": "https://aka.ms/dsc/schemas/v3/bundled/resource/manifest.json",
"type": "Microsoft.Windows/RegistryList",
"description": "Manage multiple Windows Registry keys and values",
"tags": [
"Windows"
],
"version": "1.0.0",
"get": {
"executable": "registry",
"args": [
"config",
"get",
"--list",
{
"jsonInputArg": "--input",
"mandatory": true
}
]
},
"set": {
"executable": "registry",
"args": [
"config",
"set",
"--list",
{
"jsonInputArg": "--input",
"mandatory": true
},
{
"whatIfArg": "-w"
}
],
"whatIfReturns": "state",
"handlesExist": true
},
"exitCodes": {
"0": "Success",
"1": "Invalid parameter",
"2": "Invalid input",
"3": "Registry error",
"4": "JSON serialization failed"
},
"schema": {
"command": {
"executable": "registry",
"args": [
"schema",
"--list"
]
}
}
}
]
}
64 changes: 0 additions & 64 deletions resources/registry/registry.dsc.resource.json

This file was deleted.

9 changes: 8 additions & 1 deletion resources/registry/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,15 @@ pub enum ConfigSubCommand {
Get {
#[clap(short, long, required = true, help = t!("args.configArgsInputHelp").to_string())]
input: String,
#[clap(short, long, hide = true)]
list: bool,
},
#[clap(name = "set", about = t!("args.configSetAbout").to_string())]
Set {
#[clap(short, long, required = true, help = t!("args.configArgsInputHelp").to_string())]
input: String,
#[clap(short, long, hide = true)]
list: bool,
#[clap(short = 'w', long, help = t!("args.configArgsWhatIfHelp").to_string())]
what_if: bool,
},
Expand Down Expand Up @@ -81,5 +85,8 @@ pub enum SubCommand {
subcommand: ConfigSubCommand,
},
#[clap(name = "schema", about = t!("args.schemaAbout").to_string())]
Schema,
Schema {
#[clap(short, long, help = t!("args.schemaArgsListHelp").to_string())]
list: bool,
}
}
Loading
Loading