diff --git a/build.ps1 b/build.ps1 index 3ed5d959e..d681bf94c 100755 --- a/build.ps1 +++ b/build.ps1 @@ -339,6 +339,7 @@ if (!$SkipBuild) { "tree-sitter-dscexpression", "tree-sitter-ssh-server-config", "security_context_lib", + "lib/osinfo_lib", "dsc_lib", "dsc", "dscecho", diff --git a/dsc/Cargo.lock b/dsc/Cargo.lock index b0fe1384d..3356f639e 100644 --- a/dsc/Cargo.lock +++ b/dsc/Cargo.lock @@ -675,6 +675,7 @@ dependencies = [ "linked-hash-map", "murmurhash64", "num-traits", + "osinfo_lib", "path-absolutize", "regex", "rt-format", @@ -1657,6 +1658,27 @@ version = "1.70.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a4895175b425cb1f87721b59f0f286c2092bd4af812243672510e1ac53e2e0ad" +[[package]] +name = "os_info" +version = "3.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d0e1ac5fde8d43c34139135df8ea9ee9465394b2d8d20f032d38998f64afffc3" +dependencies = [ + "log", + "plist", + "serde", + "windows-sys 0.52.0", +] + +[[package]] +name = "osinfo_lib" +version = "1.0.0" +dependencies = [ + "os_info", + "serde", + "serde_json", +] + [[package]] name = "outref" version = "0.5.2" diff --git a/dsc/tests/dsc_config_test.tests.ps1 b/dsc/tests/dsc_config_test.tests.ps1 index f80b416c5..7f365268d 100644 --- a/dsc/tests/dsc_config_test.tests.ps1 +++ b/dsc/tests/dsc_config_test.tests.ps1 @@ -14,8 +14,8 @@ Describe 'dsc config test tests' { - name: Is64BitOS type: Microsoft/OSInfo properties: - bitness: '64' - - name: 64bit test 2 + bitness: 64 + - name: Family Test type: Microsoft/OSInfo properties: family: Windows diff --git a/dsc/tests/dsc_functions.tests.ps1 b/dsc/tests/dsc_functions.tests.ps1 index 9b8d4cb8f..6538c9c7e 100644 --- a/dsc/tests/dsc_functions.tests.ps1 +++ b/dsc/tests/dsc_functions.tests.ps1 @@ -483,4 +483,24 @@ Describe 'tests for function expressions' { $LASTEXITCODE | Should -Be 0 -Because (Get-Content $TestDrive/error.log -Raw) ($out.results[0].result.actualState.output | Out-String) | Should -BeExactly ($expected | Out-String) } + + It 'context function works' { + $config_yaml = @" + `$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json + resources: + - name: Echo + type: Microsoft.DSC.Debug/Echo + properties: + output: "[context()]" +"@ + $out = dsc -l trace config get -i $config_yaml 2>$TestDrive/error.log | ConvertFrom-Json + $LASTEXITCODE | Should -Be 0 -Because (Get-Content $TestDrive/error.log -Raw) + $context = $out.results[0].result.actualState.output + $os = osinfo | ConvertFrom-Json + $context.os.family | Should -BeExactly $os.family + $context.os.version | Should -BeExactly $os.version + $context.os.bitness | Should -BeExactly $os.bitness + $context.os.architecture | Should -BeExactly $os.architecture + $context.security | Should -BeExactly $out.metadata.'Microsoft.DSC'.securityContext + } } diff --git a/dsc_lib/Cargo.lock b/dsc_lib/Cargo.lock index 363f5df58..9a4257f19 100644 --- a/dsc_lib/Cargo.lock +++ b/dsc_lib/Cargo.lock @@ -374,6 +374,15 @@ dependencies = [ "syn", ] +[[package]] +name = "deranged" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d630bccd429a5bb5a64b5e94f693bfc48c9f8566418fda4c494cc94f911f87cc" +dependencies = [ + "powerfmt", +] + [[package]] name = "derive_builder" version = "0.20.2" @@ -431,6 +440,7 @@ dependencies = [ "linked-hash-map", "murmurhash64", "num-traits", + "osinfo_lib", "path-absolutize", "regex", "rt-format", @@ -1015,6 +1025,12 @@ dependencies = [ "num-traits", ] +[[package]] +name = "num-conv" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9" + [[package]] name = "num-integer" version = "0.1.46" @@ -1076,6 +1092,27 @@ version = "1.70.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a4895175b425cb1f87721b59f0f286c2092bd4af812243672510e1ac53e2e0ad" +[[package]] +name = "os_info" +version = "3.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d0e1ac5fde8d43c34139135df8ea9ee9465394b2d8d20f032d38998f64afffc3" +dependencies = [ + "log", + "plist", + "serde", + "windows-sys 0.52.0", +] + +[[package]] +name = "osinfo_lib" +version = "1.0.0" +dependencies = [ + "os_info", + "serde", + "serde_json", +] + [[package]] name = "outref" version = "0.5.2" @@ -1135,6 +1172,19 @@ version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3b3cff922bd51709b605d9ead9aa71031d81447142d828eb4a6eba76fe619f9b" +[[package]] +name = "plist" +version = "1.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3af6b589e163c5a788fab00ce0c0366f6efbb9959c2f9874b224936af7fce7e1" +dependencies = [ + "base64", + "indexmap", + "quick-xml", + "serde", + "time", +] + [[package]] name = "portable-atomic" version = "1.11.1" @@ -1150,6 +1200,12 @@ dependencies = [ "zerovec", ] +[[package]] +name = "powerfmt" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" + [[package]] name = "proc-macro2" version = "1.0.101" @@ -1159,6 +1215,15 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "quick-xml" +version = "0.38.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42a232e7487fc2ef313d96dde7948e7a3c05101870d8985e4fd8d26aedd27b89" +dependencies = [ + "memchr", +] + [[package]] name = "quote" version = "1.0.40" @@ -1619,6 +1684,36 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "time" +version = "0.3.43" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "83bde6f1ec10e72d583d91623c939f623002284ef622b87de38cfd546cbf2031" +dependencies = [ + "deranged", + "num-conv", + "powerfmt", + "serde", + "time-core", + "time-macros", +] + +[[package]] +name = "time-core" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "40868e7c1d2f0b8d73e4a8c7f0ff63af4f6d19be117e90bd73eb1d62cf831c6b" + +[[package]] +name = "time-macros" +version = "0.2.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "30cfb0125f12d9c277f35663a0a33f8c30190f4e4574868a330595412d34ebf3" +dependencies = [ + "num-conv", + "time-core", +] + [[package]] name = "tinystr" version = "0.8.1" diff --git a/dsc_lib/Cargo.toml b/dsc_lib/Cargo.toml index b19412058..9c75bcb52 100644 --- a/dsc_lib/Cargo.toml +++ b/dsc_lib/Cargo.toml @@ -23,6 +23,7 @@ jsonschema = { version = "0.33", default-features = false } linked-hash-map = "0.5" murmurhash64 = "0.3" num-traits = "0.2" +osinfo_lib = { path = "../lib/osinfo_lib" } path-absolutize = { version = "3.1" } regex = "1.11" rt-format = "0.3" diff --git a/dsc_lib/locales/en-us.toml b/dsc_lib/locales/en-us.toml index fecfc48d2..9e301148c 100644 --- a/dsc_lib/locales/en-us.toml +++ b/dsc_lib/locales/en-us.toml @@ -266,6 +266,10 @@ invoked = "contains function" invalidItemToFind = "Invalid item to find, must be a string or number" invalidArgType = "Invalid argument type, first argument must be an array, object, or string" +[functions.context] +description = "Retrieves context information about the current execution environment" +invoked = "context function" + [functions.copyIndex] description = "Returns the current copy index" invoked = "copyIndex function" diff --git a/dsc_lib/src/functions/context.rs b/dsc_lib/src/functions/context.rs new file mode 100644 index 000000000..c6531816e --- /dev/null +++ b/dsc_lib/src/functions/context.rs @@ -0,0 +1,43 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +use crate::DscError; +use crate::configure::{context::Context as ConfigContext, config_doc::SecurityContextKind}; +use crate::functions::{FunctionArgKind, Function, FunctionCategory, FunctionMetadata}; +use osinfo_lib::OsInfo; +use rust_i18n::t; +use serde::Serialize; +use serde_json::Value; +use tracing::debug; + +#[derive(Debug, Serialize)] +pub struct ContextInfo { + os: OsInfo, + security: SecurityContextKind, +} + +pub struct Context {} + +impl Function for Context { + fn get_metadata(&self) -> FunctionMetadata { + FunctionMetadata { + name: "context".to_string(), + description: t!("functions.context.description").to_string(), + category: FunctionCategory::System, + min_args: 0, + max_args: 0, + accepted_arg_ordered_types: vec![], + remaining_arg_accepted_types: None, + return_types: vec![FunctionArgKind::Object], + } + } + + fn invoke(&self, _args: &[Value], config_context: &ConfigContext) -> Result { + debug!("{}", t!("functions.context.invoked")); + let context = ContextInfo { + os: OsInfo::new(false), + security: config_context.security_context.clone(), + }; + Ok(serde_json::to_value(context)?) + } +} diff --git a/dsc_lib/src/functions/mod.rs b/dsc_lib/src/functions/mod.rs index 5dc404eee..e881acc3e 100644 --- a/dsc_lib/src/functions/mod.rs +++ b/dsc_lib/src/functions/mod.rs @@ -20,6 +20,7 @@ pub mod bool; pub mod coalesce; pub mod concat; pub mod contains; +pub mod context; pub mod copy_index; pub mod create_array; pub mod create_object; @@ -134,6 +135,7 @@ impl FunctionDispatcher { Box::new(coalesce::Coalesce{}), Box::new(concat::Concat{}), Box::new(contains::Contains{}), + Box::new(context::Context{}), Box::new(copy_index::CopyIndex{}), Box::new(create_array::CreateArray{}), Box::new(create_object::CreateObject{}), diff --git a/lib/osinfo_lib/Cargo.lock b/lib/osinfo_lib/Cargo.lock new file mode 100644 index 000000000..3cba7f530 --- /dev/null +++ b/lib/osinfo_lib/Cargo.lock @@ -0,0 +1,290 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + +[[package]] +name = "deranged" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d630bccd429a5bb5a64b5e94f693bfc48c9f8566418fda4c494cc94f911f87cc" +dependencies = [ + "powerfmt", +] + +[[package]] +name = "equivalent" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" + +[[package]] +name = "hashbrown" +version = "0.15.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9229cfe53dfd69f0609a49f65461bd93001ea1ef889cd5529dd176593f5338a1" + +[[package]] +name = "indexmap" +version = "2.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "206a8042aec68fa4a62e8d3f7aa4ceb508177d9324faf261e1959e495b7a1921" +dependencies = [ + "equivalent", + "hashbrown", +] + +[[package]] +name = "itoa" +version = "1.0.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c" + +[[package]] +name = "log" +version = "0.4.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34080505efa8e45a4b816c349525ebe327ceaa8559756f0356cba97ef3bf7432" + +[[package]] +name = "memchr" +version = "2.7.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a282da65faaf38286cf3be983213fcf1d2e2a58700e808f83f4ea9a4804bc0" + +[[package]] +name = "num-conv" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9" + +[[package]] +name = "os_info" +version = "3.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d0e1ac5fde8d43c34139135df8ea9ee9465394b2d8d20f032d38998f64afffc3" +dependencies = [ + "log", + "plist", + "serde", + "windows-sys", +] + +[[package]] +name = "osinfo_lib" +version = "1.0.0" +dependencies = [ + "os_info", + "serde", + "serde_json", +] + +[[package]] +name = "plist" +version = "1.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3af6b589e163c5a788fab00ce0c0366f6efbb9959c2f9874b224936af7fce7e1" +dependencies = [ + "base64", + "indexmap", + "quick-xml", + "serde", + "time", +] + +[[package]] +name = "powerfmt" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" + +[[package]] +name = "proc-macro2" +version = "1.0.101" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "89ae43fd86e4158d6db51ad8e2b80f313af9cc74f5c0e03ccb87de09998732de" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quick-xml" +version = "0.38.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42a232e7487fc2ef313d96dde7948e7a3c05101870d8985e4fd8d26aedd27b89" +dependencies = [ + "memchr", +] + +[[package]] +name = "quote" +version = "1.0.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1885c039570dc00dcb4ff087a89e185fd56bae234ddc7f056a945bf36467248d" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "ryu" +version = "1.0.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "28d3b2b1366ec20994f1fd18c3c594f05c5dd4bc44d8bb0c1c632c8d6829481f" + +[[package]] +name = "serde" +version = "1.0.219" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f0e2c6ed6606019b4e29e69dbaba95b11854410e5347d525002456dbbb786b6" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.219" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b0276cf7f2c73365f7157c8123c21cd9a50fbbd844757af28ca1f5925fc2a00" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.143" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d401abef1d108fbd9cbaebc3e46611f4b1021f714a0597a71f41ee463f5f4a5a" +dependencies = [ + "indexmap", + "itoa", + "memchr", + "ryu", + "serde", +] + +[[package]] +name = "syn" +version = "2.0.106" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ede7c438028d4436d71104916910f5bb611972c5cfd7f89b8300a8186e6fada6" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "time" +version = "0.3.43" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "83bde6f1ec10e72d583d91623c939f623002284ef622b87de38cfd546cbf2031" +dependencies = [ + "deranged", + "num-conv", + "powerfmt", + "serde", + "time-core", + "time-macros", +] + +[[package]] +name = "time-core" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "40868e7c1d2f0b8d73e4a8c7f0ff63af4f6d19be117e90bd73eb1d62cf831c6b" + +[[package]] +name = "time-macros" +version = "0.2.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "30cfb0125f12d9c277f35663a0a33f8c30190f4e4574868a330595412d34ebf3" +dependencies = [ + "num-conv", + "time-core", +] + +[[package]] +name = "unicode-ident" +version = "1.0.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f63a545481291138910575129486daeaf8ac54aee4387fe7906919f7830c7d9d" + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_gnullvm", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" diff --git a/lib/osinfo_lib/Cargo.toml b/lib/osinfo_lib/Cargo.toml new file mode 100644 index 000000000..771c0be29 --- /dev/null +++ b/lib/osinfo_lib/Cargo.toml @@ -0,0 +1,18 @@ +[package] +name = "osinfo_lib" +version = "1.0.0" +edition = "2021" + +[profile.release] +codegen-units = 1 # reduces binary size by ~2% +debug = "full" # No one needs an undebuggable release binary +lto = true # reduces binary size by ~14% +opt-level = "s" # reduces binary size by ~25% +panic = "abort" # reduces binary size by ~50% in combination with -Zbuild-std-features=panic_immediate_abort +split-debuginfo = "packed" # generates a seperate *.dwp/*.dSYM so the binary can get stripped +strip = "symbols" # See split-debuginfo - allows us to drop the size by ~65% + +[dependencies] +os_info = { version = "3.11" } +serde = { version = "1.0", features = ["derive"] } +serde_json = { version = "1.0", features = ["preserve_order"] } diff --git a/osinfo/src/config.rs b/lib/osinfo_lib/src/lib.rs similarity index 77% rename from osinfo/src/config.rs rename to lib/osinfo_lib/src/lib.rs index a6ebf6aae..c20c63f6a 100644 --- a/osinfo/src/config.rs +++ b/lib/osinfo_lib/src/lib.rs @@ -9,9 +9,6 @@ use std::string::ToString; #[derive(Debug, Clone, PartialEq, Serialize)] #[serde(deny_unknown_fields)] pub struct OsInfo { - /// Returns the unique ID for the `OSInfo` instance data type. - #[serde(rename = "$id")] - pub id: String, family: Family, /// Defines the version of the operating system as a string. version: String, @@ -21,7 +18,7 @@ pub struct OsInfo { /// Defines the codename for the operating system as returned from `lsb_release --codename`. #[serde(skip_serializing_if = "Option::is_none")] codename: Option, - bitness: Bitness, + bitness: Option, /// Defines the processor architecture as reported by `uname -m` on the operating system. #[serde(skip_serializing_if = "Option::is_none")] architecture: Option, @@ -29,17 +26,6 @@ pub struct OsInfo { name: Option, } -/// Defines whether the operating system is a 32-bit or 64-bit operating system. -#[derive(Debug, Clone, PartialEq, Serialize)] -pub enum Bitness { - #[serde(rename = "32")] - Bit32, - #[serde(rename = "64")] - Bit64, - #[serde(rename = "unknown")] - Unknown, -} - /// Defines whether the operating system is Linux, macOS, or Windows. #[derive(Debug, Clone, PartialEq, Serialize)] pub enum Family { @@ -59,8 +45,6 @@ impl Display for Family { } } -const ID: &str = "https://developer.microsoft.com/json-schemas/dsc/os_info/20230303/Microsoft.Dsc.OS_Info.schema.json"; - impl OsInfo { pub fn new(include_name: bool) -> Self { let os_info = os_info::get(); @@ -72,10 +56,10 @@ impl OsInfo { os_info::Type::Windows => Family::Windows, _ => Family::Linux, }; - let bits: Bitness = match os_info.bitness() { - os_info::Bitness::X32 => Bitness::Bit32, - os_info::Bitness::X64 => Bitness::Bit64, - _ => Bitness::Unknown, + let bits = match os_info.bitness() { + os_info::Bitness::X32 => Some(32), + os_info::Bitness::X64 => Some(64), + _ => None, }; let version = os_info.version().to_string(); let name = if include_name { @@ -89,7 +73,6 @@ impl OsInfo { None }; Self { - id: ID.to_string(), family, version, edition, diff --git a/osinfo/Cargo.lock b/osinfo/Cargo.lock index 250fc22eb..c9a3fbf29 100644 --- a/osinfo/Cargo.lock +++ b/osinfo/Cargo.lock @@ -77,7 +77,15 @@ dependencies = [ [[package]] name = "osinfo" -version = "0.1.0" +version = "1.0.0" +dependencies = [ + "osinfo_lib", + "serde_json", +] + +[[package]] +name = "osinfo_lib" +version = "1.0.0" dependencies = [ "os_info", "serde", diff --git a/osinfo/Cargo.toml b/osinfo/Cargo.toml index c79ee3bc6..698a8ad58 100644 --- a/osinfo/Cargo.toml +++ b/osinfo/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "osinfo" -version = "0.1.0" +version = "1.0.0" edition = "2021" [profile.release] @@ -13,6 +13,5 @@ split-debuginfo = "packed" # generates a seperate *.dwp/*.dSYM so the binary ca strip = "symbols" # See split-debuginfo - allows us to drop the size by ~65% [dependencies] -os_info = { version = "3.11" } -serde = { version = "1.0", features = ["derive"] } +osinfo_lib = { path = "../lib/osinfo_lib" } serde_json = { version = "1.0", features = ["preserve_order"] } diff --git a/osinfo/osinfo.dsc.resource.json b/osinfo/osinfo.dsc.resource.json index cabf70518..b38aabc16 100644 --- a/osinfo/osinfo.dsc.resource.json +++ b/osinfo/osinfo.dsc.resource.json @@ -43,12 +43,7 @@ "markdownDescription": "Defines the processor architecture as reported by `uname -m` on the operating system.\n\n[Online documentation][01]\n\n[01]: https://learn.microsoft.com/powershell/dsc/reference/microsoft/osinfo/resource#architecture\n" }, "bitness": { - "type": "string", - "enum": [ - "32", - "64", - "unknown" - ], + "type": "number", "title": "Operating system bitness", "description": "Defines whether the operating system is a 32-bit or 64-bit operating system.\n\nhttps://learn.microsoft.com/powershell/dsc/reference/microsoft/osinfo/resource#bitness\n", "markdownDescription": "Defines whether the operating system is a 32-bit or 64-bit operating system.\n\n[Online documentation][01]\n\n[01]: https://learn.microsoft.com/powershell/dsc/reference/microsoft/osinfo/resource#bitness\n" diff --git a/osinfo/src/main.rs b/osinfo/src/main.rs index 1963f3ab5..b7d6fb6e5 100644 --- a/osinfo/src/main.rs +++ b/osinfo/src/main.rs @@ -1,11 +1,11 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -mod config; +use osinfo_lib::OsInfo; fn main() { let args: Vec = std::env::args().collect(); let include_name = args.len() > 1 && args[1] == "export"; - let json = serde_json::to_string(&config::OsInfo::new(include_name)).unwrap(); + let json = serde_json::to_string(&OsInfo::new(include_name)).unwrap(); println!("{json}"); } diff --git a/tools/test_group_resource/Cargo.lock b/tools/test_group_resource/Cargo.lock index b5c6bf815..a1c75e90a 100644 --- a/tools/test_group_resource/Cargo.lock +++ b/tools/test_group_resource/Cargo.lock @@ -374,6 +374,15 @@ dependencies = [ "syn", ] +[[package]] +name = "deranged" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d630bccd429a5bb5a64b5e94f693bfc48c9f8566418fda4c494cc94f911f87cc" +dependencies = [ + "powerfmt", +] + [[package]] name = "derive_builder" version = "0.20.2" @@ -431,6 +440,7 @@ dependencies = [ "linked-hash-map", "murmurhash64", "num-traits", + "osinfo_lib", "path-absolutize", "regex", "rt-format", @@ -1015,6 +1025,12 @@ dependencies = [ "num-traits", ] +[[package]] +name = "num-conv" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9" + [[package]] name = "num-integer" version = "0.1.46" @@ -1076,6 +1092,27 @@ version = "1.70.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a4895175b425cb1f87721b59f0f286c2092bd4af812243672510e1ac53e2e0ad" +[[package]] +name = "os_info" +version = "3.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d0e1ac5fde8d43c34139135df8ea9ee9465394b2d8d20f032d38998f64afffc3" +dependencies = [ + "log", + "plist", + "serde", + "windows-sys 0.52.0", +] + +[[package]] +name = "osinfo_lib" +version = "1.0.0" +dependencies = [ + "os_info", + "serde", + "serde_json", +] + [[package]] name = "outref" version = "0.5.2" @@ -1135,6 +1172,19 @@ version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3b3cff922bd51709b605d9ead9aa71031d81447142d828eb4a6eba76fe619f9b" +[[package]] +name = "plist" +version = "1.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3af6b589e163c5a788fab00ce0c0366f6efbb9959c2f9874b224936af7fce7e1" +dependencies = [ + "base64", + "indexmap", + "quick-xml", + "serde", + "time", +] + [[package]] name = "portable-atomic" version = "1.11.1" @@ -1150,6 +1200,12 @@ dependencies = [ "zerovec", ] +[[package]] +name = "powerfmt" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" + [[package]] name = "proc-macro2" version = "1.0.101" @@ -1159,6 +1215,15 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "quick-xml" +version = "0.38.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42a232e7487fc2ef313d96dde7948e7a3c05101870d8985e4fd8d26aedd27b89" +dependencies = [ + "memchr", +] + [[package]] name = "quote" version = "1.0.40" @@ -1630,6 +1695,36 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "time" +version = "0.3.43" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "83bde6f1ec10e72d583d91623c939f623002284ef622b87de38cfd546cbf2031" +dependencies = [ + "deranged", + "num-conv", + "powerfmt", + "serde", + "time-core", + "time-macros", +] + +[[package]] +name = "time-core" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "40868e7c1d2f0b8d73e4a8c7f0ff63af4f6d19be117e90bd73eb1d62cf831c6b" + +[[package]] +name = "time-macros" +version = "0.2.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "30cfb0125f12d9c277f35663a0a33f8c30190f4e4574868a330595412d34ebf3" +dependencies = [ + "num-conv", + "time-core", +] + [[package]] name = "tinystr" version = "0.8.1"