Invoke the expression. # Arguments `function_dispatcher` - The function dispatcher to use. `context` - The context to use. # Returns The result of the expression. # Errors This function will return an error if the expression fails to execute.
(&self, function_dispatcher: &FunctionDispatcher, context: &Context)
| 127 | /// |
| 128 | /// This function will return an error if the expression fails to execute. |
| 129 | pub fn invoke(&self, function_dispatcher: &FunctionDispatcher, context: &Context) -> Result<Value, DscError> { |
| 130 | let result = self.function.invoke(function_dispatcher, context)?; |
| 131 | if self.function.name() != "secret" && !is_secure_value(&result) { |
| 132 | let result_json = serde_json::to_string(&result)?; |
| 133 | trace!("{}", t!("parser.expression.functionResult", results = result_json)); |
| 134 | } else { |
| 135 | trace!("{}", t!("parser.expression.functionResultSecure")); |
| 136 | } |
| 137 | if self.accessors.is_empty() { |
| 138 | Ok(result) |
| 139 | } |
| 140 | else { |
| 141 | debug!("{}", t!("parser.expression.evalAccessors")); |
| 142 | let mut value = result; |
| 143 | let is_secure = is_secure_value(&value); |
| 144 | if is_secure { |
| 145 | // if a SecureString, extract the string value |
| 146 | if let Some(string) = value.get("secureString") { |
| 147 | if let Some(s) = string.as_str() { |
| 148 | value = Value::String(s.to_string()); |
| 149 | } |
| 150 | } else if let Some(obj) = value.get("secureObject") { |
| 151 | // if a SecureObject, extract the object value |
| 152 | value = obj.clone(); |
| 153 | } |
| 154 | } |
| 155 | for accessor in &self.accessors { |
| 156 | let mut index = Value::Null; |
| 157 | match accessor { |
| 158 | Accessor::Member(member) => { |
| 159 | debug!("{}", t!("parser.expression.evaluatingMemberAccessor", name = member : {:?})); |
| 160 | if let Some(object) = value.as_object() { |
| 161 | if !object.contains_key(member) { |
| 162 | warn!("{}", t!("parser.expression.memberNameNotFound", member = member)); |
| 163 | return Err(DscError::Parser(t!("parser.expression.memberNameNotFound", member = member).to_string())); |
| 164 | } |
| 165 | if is_secure { |
| 166 | value = convert_to_secure(&object[member]); |
| 167 | } else { |
| 168 | value = object[member].clone(); |
| 169 | } |
| 170 | } else { |
| 171 | warn!("{}", t!("parser.expression.accessOnNonObject")); |
| 172 | return Err(DscError::Parser(t!("parser.expression.accessOnNonObject").to_string())); |
| 173 | } |
| 174 | }, |
| 175 | Accessor::Index(index_value) => { |
| 176 | debug!("{}", t!("parser.expression.evaluatingIndexAccessor", index = index_value : {:?})); |
| 177 | if is_secure { |
| 178 | index = convert_to_secure(index_value); |
| 179 | } else { |
| 180 | index = index_value.clone(); |
| 181 | } |
| 182 | }, |
| 183 | Accessor::IndexExpression(expression) => { |
| 184 | debug!("{}", t!("parser.expression.evaluatingIndexExpression", expression = expression : {:?})); |
| 185 | index = expression.invoke(function_dispatcher, context)?; |
| 186 | trace!("{}", t!("parser.expression.expressionResult", index = index : {:?})); |
nothing calls this directly
no test coverage detected