FunctionEvaluator { public static AbstractPropertyValue tryResolveValue(FunctionEvaluatorContext evaluatorContext, AbstractInstantiableTemplate template, Map<String, AbstractPropertyValue> properties, AbstractPropertyValue evaluatedProperty) { if (evaluatedProperty == null) { return null; } if (evaluatedProperty instanceof PropertyValue) { return evaluatedProperty; } if (containGetSecretFunction(evaluatedProperty)) { return evaluatedProperty; } if (evaluatedProperty instanceof FunctionPropertyValue) { FunctionPropertyValue evaluatedFunction = (FunctionPropertyValue) evaluatedProperty; switch (evaluatedFunction.getFunction()) { case ToscaFunctionConstants.GET_INPUT: String inputName = evaluatedFunction.getParameters().get(0); return evaluatorContext.getInputs().get(inputName); case ToscaFunctionConstants.GET_PROPERTY: return getProperty(evaluatorContext, template, properties, evaluatedFunction); default: throw new IllegalArgumentException("GET_ATTRIBUTE or GET_OPERATION_OUTPUT cannot be defined on a property."); } } if (evaluatedProperty instanceof ConcatPropertyValue) { return concat(evaluatorContext, template, properties, (ConcatPropertyValue) evaluatedProperty); } throw new IllegalArgumentException("AbstractPropertyValue must be one of null, a secret, PropertyValue, FunctionPropertyValue or ConcatPropertyValue"); }  static AbstractPropertyValue tryResolveValue(FunctionEvaluatorContext evaluatorContext, AbstractInstantiableTemplate template,
            Map<String, AbstractPropertyValue> properties, AbstractPropertyValue evaluatedProperty); static boolean containGetSecretFunction(AbstractPropertyValue propertyValue);  }
@Test public void nodeGetSecretProp() { FunctionEvaluatorContext context = getEvaluationContext(); NodeTemplate template = context.getTopology().getNodeTemplates().get("my_node"); AbstractPropertyValue resolved = FunctionEvaluator.tryResolveValue(context, template, template.getProperties(), template.getProperties().get("get_secret_prop")); Assert.assertNotNull(resolved); Assert.assertEquals(FunctionPropertyValue.class, resolved.getClass()); Assert.assertEquals("get_secret", ((FunctionPropertyValue) resolved).getFunction()); Assert.assertEquals("my/path", ((FunctionPropertyValue) resolved).getParameters().get(0)); }
@Test public void concatOfAnGetSecretShouldFailed() { FunctionEvaluatorContext context = getEvaluationContext(); NodeTemplate template = context.getTopology().getNodeTemplates().get("my_node"); AbstractPropertyValue resolved = FunctionEvaluator.tryResolveValue(context, template, template.getProperties(), template.getProperties().get("concat_prop_and_get_secret")); Assert.assertNotNull(resolved); Assert.assertEquals(ConcatPropertyValue.class, resolved.getClass()); ConcatPropertyValue resolvedConcat = (ConcatPropertyValue) resolved; Assert.assertEquals(ScalarPropertyValue.class, resolvedConcat.getParameters().get(0).getClass()); Assert.assertEquals(FunctionPropertyValue.class, resolvedConcat.getParameters().get(1).getClass()); }