|
| 1 | +// Copyright (c) Microsoft Corporation. |
| 2 | +// Licensed under the MIT License. |
| 3 | + |
| 4 | +use crate::DscError; |
| 5 | +use crate::configure::{context::Context as ConfigContext, config_doc::SecurityContextKind}; |
| 6 | +use crate::functions::{FunctionArgKind, Function, FunctionCategory, FunctionMetadata}; |
| 7 | +use osinfo_lib::OsInfo; |
| 8 | +use rust_i18n::t; |
| 9 | +use serde::Serialize; |
| 10 | +use serde_json::Value; |
| 11 | +use tracing::debug; |
| 12 | + |
| 13 | +#[derive(Debug, Serialize)] |
| 14 | +pub struct ContextInfo { |
| 15 | + os: OsInfo, |
| 16 | + security: SecurityContextKind, |
| 17 | +} |
| 18 | + |
| 19 | +pub struct Context {} |
| 20 | + |
| 21 | +impl Function for Context { |
| 22 | + fn get_metadata(&self) -> FunctionMetadata { |
| 23 | + FunctionMetadata { |
| 24 | + name: "context".to_string(), |
| 25 | + description: t!("functions.context.description").to_string(), |
| 26 | + category: FunctionCategory::System, |
| 27 | + min_args: 0, |
| 28 | + max_args: 0, |
| 29 | + accepted_arg_ordered_types: vec![], |
| 30 | + remaining_arg_accepted_types: None, |
| 31 | + return_types: vec![FunctionArgKind::Object], |
| 32 | + } |
| 33 | + } |
| 34 | + |
| 35 | + fn invoke(&self, _args: &[Value], config_context: &ConfigContext) -> Result<Value, DscError> { |
| 36 | + debug!("{}", t!("functions.context.invoked")); |
| 37 | + let context = ContextInfo { |
| 38 | + os: OsInfo::new(false), |
| 39 | + security: config_context.security_context.clone(), |
| 40 | + }; |
| 41 | + Ok(serde_json::to_value(context)?) |
| 42 | + } |
| 43 | +} |
0 commit comments