Skip to content

Commit

Permalink
Merge branch 'main' into issue_592
Browse files Browse the repository at this point in the history
  • Loading branch information
anmenaga authored Jan 16, 2025
2 parents 097b71b + ee86c76 commit 92ea9fb
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,11 @@ With DSCv3, you can:

### Differences from PowerShell DSC

This project is the next generation of DSC and leverages the
[PSDesiredStateConfiguration module][00] to maintain compatibility with existing PowerShell based
resources.

DSCv3 differs from PowerShell DSC in a few important ways:

- DSCv3 doesn't depend on PowerShell. You can use DSCv3 without PowerShell installed and manage
resources written in bash, python, C#, Go, or any other language.
- DSCv3 use of PowerShell based resources does not depend on PSDesiredStateConfiguration module
- DSCv3 doesn't include a local configuration manager. DSCv3 is invoked as a command. It doesn't
run as a service.
- Non-PowerShell resources define their schemas with JSON files, not MOF files.
Expand Down
3 changes: 2 additions & 1 deletion dsc_lib/src/discovery/command_discovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use tracing::{debug, info, trace, warn, warn_span};
use tracing_indicatif::span_ext::IndicatifSpanExt;

use crate::util::{get_setting, ProgressBar};
use crate::util::get_exe_path;

pub struct CommandDiscovery {
// use BTreeMap so that the results are sorted by the typename, the Vec is sorted by version
Expand Down Expand Up @@ -136,7 +137,7 @@ impl CommandDiscovery {

// if exe home is not already in PATH env var then add it to env var and list of searched paths
if !using_custom_path {
if let Some(exe_home) = env::current_exe()?.parent() {
if let Some(exe_home) = get_exe_path()?.parent() {
let exe_home_pb = exe_home.to_path_buf();
if paths.contains(&exe_home_pb) {
trace!("Exe home is already in path: {}", exe_home.to_string_lossy());
Expand Down
21 changes: 20 additions & 1 deletion dsc_lib/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::dscerror::DscError;
use clap::ValueEnum;
use serde_json::Value;
use serde::Serialize;
use std::fs;
use std::fs::File;
use std::io::BufReader;
use std::path::PathBuf;
Expand Down Expand Up @@ -179,7 +180,7 @@ pub fn get_setting(value_name: &str) -> Result<DscSettingValue, DscError> {
let mut result: DscSettingValue = DscSettingValue::default();
let mut settings_file_path : PathBuf;

if let Some(exe_home) = env::current_exe()?.parent() {
if let Some(exe_home) = get_exe_path()?.parent() {
// First, get setting from the default settings file
settings_file_path = exe_home.join(DEFAULT_SETTINGS_FILE_NAME);
if let Ok(v) = load_value_from_json(&settings_file_path, DEFAULT_SETTINGS_SCHEMA_VERSION) {
Expand Down Expand Up @@ -241,6 +242,24 @@ fn load_value_from_json(path: &PathBuf, value_name: &str) -> Result<serde_json::
Err(DscError::NotSupported(value_name.to_string()))
}

/// Gets path to the current dsc process.
/// If dsc is started using a symlink, this functon returns target of the symlink.
///
/// # Errors
///
/// Will return `Err` if path to the current exe can't be retrived.
pub fn get_exe_path() -> Result<PathBuf, DscError> {
if let Ok(exe) = env::current_exe() {
if let Ok(target_path) = fs::read_link(exe.clone()) {
return Ok(target_path);
};

return Ok(exe);
}

Err(DscError::NotSupported("Can't get the path to dsc executable".to_string()))
}

#[cfg(target_os = "windows")]
fn get_settings_policy_file_path() -> String
{
Expand Down

0 comments on commit 92ea9fb

Please sign in to comment.