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
1 change: 1 addition & 0 deletions dsc/locales/en-us.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ listFunctionAbout = "List or find functions"
version = "The version of the resource to invoke in semver format"
mcpAbout = "Use DSC as a MCP server"
bicepAbout = "Use DSC as a Bicep server over gRPC"
ignoreSettingsFile = "Ignore the settings file when running the command"

[main]
ctrlCReceived = "Ctrl-C received"
Expand Down
2 changes: 2 additions & 0 deletions dsc/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ pub struct Args {
pub trace_format: Option<TraceFormat>,
#[clap(short = 'p', long, help = t!("args.progressFormat").to_string(), value_enum)]
pub progress_format: Option<ProgressFormat>,
#[clap(short = 'i', long, help = t!("args.ignoreSettingsFile").to_string())]
pub ignore_settings_file: bool,
}

#[derive(Debug, PartialEq, Eq, Subcommand)]
Expand Down
11 changes: 9 additions & 2 deletions dsc/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
use args::{Args, SubCommand};
use clap::{CommandFactory, Parser};
use clap_complete::generate;
use dsc_lib::progress::ProgressFormat;
use mcp::start_mcp_server;
use dsc_lib::{progress::ProgressFormat, util::DSC_IGNORE_SETTINGS_FILE};
use rust_i18n::{i18n, t};
use std::{io, process::exit};
use std::{env::set_var, io, process::exit};
use sysinfo::{Process, RefreshKind, System, get_current_pid, ProcessRefreshKind};
use tracing::{error, info, warn, debug};

Expand Down Expand Up @@ -41,6 +41,13 @@ fn main() {

let args = Args::parse();

// if args.ignore_settings_file is set, we create an env var called `DSC_IGNORE_SETTINGS_FILE` set to value 1
if args.ignore_settings_file {
unsafe {
set_var(DSC_IGNORE_SETTINGS_FILE, "1");
}
}

util::enable_tracing(args.trace_level.as_ref(), args.trace_format.as_ref());

debug!("{}: {}", t!("main.usingDscVersion"), env!("CARGO_PKG_VERSION"));
Expand Down
19 changes: 19 additions & 0 deletions dsc/tests/dsc_settings.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,23 @@ Describe 'tests for dsc settings' {
"$TestDrive/tracing.txt" | Should -FileContentMatchExactly "Trace-level is Trace"
"$TestDrive/tracing.txt" | Should -FileContentMatchExactly 'Using Resource Path: Defaultv1SettingsDir'
}

It 'DSC_IGNORE_SETTINGS_FILE environment variable disables settings file' {
$oldEnv = $env:DSC_IGNORE_SETTINGS_FILE
try {
$env:DSC_IGNORE_SETTINGS_FILE = "1"
$null = dsc -l warn resource list 2> $TestDrive/tracing.txt
$errorLog = Get-Content "$TestDrive/tracing.txt" -Raw
$errorLog | Should -BeLike "*WARN*Ignoring settings file due to environment variable 'DSC_IGNORE_SETTINGS_FILE' being set or '--ignore-settings-file' flag being used*"
}
finally {
$env:DSC_IGNORE_SETTINGS_FILE = $oldEnv
}
}

It '--ignore-settings-file command-line argument disables settings file' {
$null = dsc --ignore-settings-file resource list 2> $TestDrive/tracing.txt
$errorLog = Get-Content "$TestDrive/tracing.txt" -Raw
$errorLog | Should -BeLike "*WARN*Ignoring settings file due to environment variable 'DSC_IGNORE_SETTINGS_FILE' being set or '--ignore-settings-file' flag being used*"
}
}
8 changes: 6 additions & 2 deletions lib/dsc-lib-jsonschema/.versions.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
{
"latestMajor": "V3",
"latestMinor": "V3_1",
"latestPatch": "V3_1_3",
"latestMinor": "V3_2",
"latestPatch": "V3_2_2",
"all": [
"V3",
"V3_2",
"V3_2_2",
"V3_2_1",
"V3_2_0",
"V3_1",
"V3_1_3",
"V3_1_2",
Expand Down
1 change: 1 addition & 0 deletions lib/dsc-lib/locales/en-us.toml
Original file line number Diff line number Diff line change
Expand Up @@ -821,6 +821,7 @@ executableNotFound = "Executable '%{executable}' not found"
policyFolderNotSecure = "Policy folder '%{path}' is not secure, settings file will not be used. Required permissions: %{required}"
policyFolderNotSecureLinux = "Only root should have write access (no group/other write bits)"
policyFolderNotSecureWindows = "Only SYSTEM and Administrators should have write access"
ignoreSettingsFile = "Ignoring settings file due to environment variable 'DSC_IGNORE_SETTINGS_FILE' being set or '--ignore-settings-file' flag being used"

[types.date_version]
invalidDay = "day `%{day}` for month `%{month}` is invalid - must be between `01` and `%{max_days}`"
Expand Down
7 changes: 7 additions & 0 deletions lib/dsc-lib/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ use std::{
use tracing::{debug, warn};
use which::which;

pub const DSC_IGNORE_SETTINGS_FILE: &str = "DSC_IGNORE_SETTINGS_FILE";

pub struct DscSettingValue {
pub setting: Value,
pub policy: Value,
Expand Down Expand Up @@ -172,6 +174,11 @@ pub fn get_setting(value_name: &str) -> Result<DscSettingValue, DscError> {
let mut result: DscSettingValue = DscSettingValue::default();
let mut settings_file_path : PathBuf;

if env::var(DSC_IGNORE_SETTINGS_FILE).is_ok() {
warn!("{}", t!("util.ignoreSettingsFile"));
return Ok(result);
}

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);
Expand Down
Loading