Search in sources :

Example 1 with UnsupportedSecretException

use of org.alien4cloud.tosca.editor.exception.UnsupportedSecretException in project alien4cloud by alien4cloud.

the class SetNodeCapabilityPropertyAsSecretProcessor method processNodeOperation.

@Override
protected void processNodeOperation(Csar csar, Topology topology, SetNodeCapabilityPropertyAsSecretOperation operation, NodeTemplate nodeTemplate) {
    Capability capabilityTemplate = getOrFail(nodeTemplate.getCapabilities(), operation.getCapabilityName(), "Capability {} does not exist for node {}", operation.getCapabilityName(), operation.getNodeName());
    CapabilityType capabilityType = ToscaContext.get(CapabilityType.class, capabilityTemplate.getType());
    getOrFail(capabilityType.getProperties(), operation.getPropertyName(), "Property {} do not exist for capability {} of node {}", operation.getPropertyName(), operation.getCapabilityName(), operation.getNodeName());
    if (operation.getCapabilityName().equals(FORBIDDEN_CAPABILITY)) {
        throw new UnsupportedSecretException("We cannot set a secret on the capability " + operation.getCapabilityName());
    }
    if ("".equals(operation.getSecretPath())) {
        throw new InvalidSecretPathException("The secret path to the property " + operation.getPropertyName() + "is null.");
    }
    FunctionPropertyValue getSecret = new FunctionPropertyValue();
    getSecret.setFunction(ToscaFunctionConstants.GET_SECRET);
    getSecret.setParameters(Arrays.asList(operation.getSecretPath()));
    nodeTemplate.getCapabilities().get(operation.getCapabilityName()).getProperties().put(operation.getPropertyName(), getSecret);
    log.debug("Set the property [ {} ] of capability template [ {} ] of node [ {} ] to the secret path [ {} ].", operation.getPropertyName(), operation.getCapabilityName(), operation.getNodeName(), topology.getId());
}
Also used : CapabilityType(org.alien4cloud.tosca.model.types.CapabilityType) UnsupportedSecretException(org.alien4cloud.tosca.editor.exception.UnsupportedSecretException) Capability(org.alien4cloud.tosca.model.templates.Capability) FunctionPropertyValue(org.alien4cloud.tosca.model.definitions.FunctionPropertyValue) InvalidSecretPathException(org.alien4cloud.tosca.editor.exception.InvalidSecretPathException)

Example 2 with UnsupportedSecretException

use of org.alien4cloud.tosca.editor.exception.UnsupportedSecretException in project alien4cloud by alien4cloud.

the class SetNodePropertyAsSecretProcessor method processNodeOperation.

@Override
protected void processNodeOperation(Csar csar, Topology topology, SetNodePropertyAsSecretOperation operation, NodeTemplate nodeTemplate) {
    NodeType indexedNodeType = ToscaContext.get(NodeType.class, nodeTemplate.getType());
    getOrFail(indexedNodeType.getProperties(), operation.getPropertyName(), "Property {} do not exist for node {}", operation.getPropertyName(), operation.getNodeName());
    if (operation.getPropertyName().equals(FORBIDDEN_PROPERTY)) {
        throw new UnsupportedSecretException("We cannot set a secret on the property " + operation.getPropertyName());
    }
    if ("".equals(operation.getSecretPath())) {
        throw new InvalidSecretPathException("The secret path to the property " + operation.getPropertyName() + " is null.");
    }
    FunctionPropertyValue getSecret = new FunctionPropertyValue();
    getSecret.setFunction(ToscaFunctionConstants.GET_SECRET);
    getSecret.setParameters(Arrays.asList(operation.getSecretPath()));
    nodeTemplate.getProperties().put(operation.getPropertyName(), getSecret);
    log.debug("Associate the property [ {} ] of the node template [ {} ] as secret [ {} ] of the topology [ {} ].", operation.getPropertyName(), operation.getNodeName(), operation.getSecretPath(), topology.getId());
}
Also used : UnsupportedSecretException(org.alien4cloud.tosca.editor.exception.UnsupportedSecretException) NodeType(org.alien4cloud.tosca.model.types.NodeType) FunctionPropertyValue(org.alien4cloud.tosca.model.definitions.FunctionPropertyValue) InvalidSecretPathException(org.alien4cloud.tosca.editor.exception.InvalidSecretPathException)

Aggregations

InvalidSecretPathException (org.alien4cloud.tosca.editor.exception.InvalidSecretPathException)2 UnsupportedSecretException (org.alien4cloud.tosca.editor.exception.UnsupportedSecretException)2 FunctionPropertyValue (org.alien4cloud.tosca.model.definitions.FunctionPropertyValue)2 Capability (org.alien4cloud.tosca.model.templates.Capability)1 CapabilityType (org.alien4cloud.tosca.model.types.CapabilityType)1 NodeType (org.alien4cloud.tosca.model.types.NodeType)1