Commit 8b30ace9 authored by Spiros Koulouzis's avatar Spiros Koulouzis

write cloudstorm credentials to file

parent c3f29fd7
...@@ -83,7 +83,7 @@ class CloudStormService { ...@@ -83,7 +83,7 @@ class CloudStormService {
if (!(credentialsTempInputDir.mkdirs())) { if (!(credentialsTempInputDir.mkdirs())) {
throw new FileNotFoundException("Could not create input directory: " + topologyTempInputDir.getAbsolutePath()); throw new FileNotFoundException("Could not create input directory: " + topologyTempInputDir.getAbsolutePath());
} }
writeCloudStormCredentialsFiles(toscaTemplate, credentialsTempInputDirPath); writeCloudStormCredentialsFiles(credentialsTempInputDirPath);
String infrasCodeTempInputDirPath = tempInputDirPath + File.separator + "infrasCodes"; String infrasCodeTempInputDirPath = tempInputDirPath + File.separator + "infrasCodes";
File infrasCodeTempInputDir = new File(infrasCodeTempInputDirPath); File infrasCodeTempInputDir = new File(infrasCodeTempInputDirPath);
if (!(infrasCodeTempInputDir.mkdirs())) { if (!(infrasCodeTempInputDir.mkdirs())) {
...@@ -99,7 +99,7 @@ class CloudStormService { ...@@ -99,7 +99,7 @@ class CloudStormService {
topTopology.setPublicKeyPath(publicKeyPath); topTopology.setPublicKeyPath(publicKeyPath);
topTopology.setUserName(getUserName()); topTopology.setUserName(getUserName());
Map<String, Object> subTopologiesAndVMs = getCloudsStormSubTopologiesAndVMs(toscaTemplate, tempInputDirPath); Map<String, Object> subTopologiesAndVMs = getCloudsStormSubTopologiesAndVMs(tempInputDirPath);
List<CloudsStormSubTopology> cloudsStormSubTopology = (List<CloudsStormSubTopology>) subTopologiesAndVMs.get("cloud_storm_subtopologies"); List<CloudsStormSubTopology> cloudsStormSubTopology = (List<CloudsStormSubTopology>) subTopologiesAndVMs.get("cloud_storm_subtopologies");
topTopology.setTopologies(cloudsStormSubTopology); topTopology.setTopologies(cloudsStormSubTopology);
...@@ -124,7 +124,7 @@ class CloudStormService { ...@@ -124,7 +124,7 @@ class CloudStormService {
return "vm_user"; return "vm_user";
} }
private Map<String, Object> getCloudsStormSubTopologiesAndVMs(ToscaTemplate toscaTemplate, String tempInputDirPath) throws ApiException, IOException, Exception { private Map<String, Object> getCloudsStormSubTopologiesAndVMs(String tempInputDirPath) throws ApiException, IOException, Exception {
List<NodeTemplateMap> vmTopologyTemplatesMap = helper.getVMTopologyTemplates(); List<NodeTemplateMap> vmTopologyTemplatesMap = helper.getVMTopologyTemplates();
List<CloudsStormSubTopology> cloudsStormSubTopologies = new ArrayList<>(); List<CloudsStormSubTopology> cloudsStormSubTopologies = new ArrayList<>();
Map<String, Object> cloudsStormMap = new HashMap<>(); Map<String, Object> cloudsStormMap = new HashMap<>();
...@@ -179,7 +179,7 @@ class CloudStormService { ...@@ -179,7 +179,7 @@ class CloudStormService {
return null; return null;
} }
private void writeCloudStormCredentialsFiles(ToscaTemplate toscaTemplate, String credentialsTempInputDirPath) throws ApiException, Exception { private void writeCloudStormCredentialsFiles(String credentialsTempInputDirPath) throws ApiException, Exception {
List<NodeTemplateMap> vmTopologiesMaps = helper.getVMTopologyTemplates(); List<NodeTemplateMap> vmTopologiesMaps = helper.getVMTopologyTemplates();
List<CloudCredential> cloudStormCredentialList = new ArrayList<>(); List<CloudCredential> cloudStormCredentialList = new ArrayList<>();
int i = 0; int i = 0;
...@@ -190,25 +190,25 @@ class CloudStormService { ...@@ -190,25 +190,25 @@ class CloudStormService {
cloudStormCredential.setCloudProvider(toscaCredentials.getCloudProviderName()); cloudStormCredential.setCloudProvider(toscaCredentials.getCloudProviderName());
String credInfoFile = credentialsTempInputDirPath + File.separator + toscaCredentials.getCloudProviderName() + i + ".yml"; String credInfoFile = credentialsTempInputDirPath + File.separator + toscaCredentials.getCloudProviderName() + i + ".yml";
cloudStormCredential.setCredInfoFile(credInfoFile); cloudStormCredential.setCredInfoFile(credInfoFile);
cloudStormCredentialList.add(cloudStormCredential);
CredentialInfo cloudStormCredentialInfo = getCloudStormCredentialInfo(toscaCredentials); CredentialInfo cloudStormCredentialInfo = getCloudStormCredentialInfo(toscaCredentials, credentialsTempInputDirPath);
objectMapper.writeValue(new File(credentialsTempInputDirPath + File.separator + toscaCredentials.getCloudProviderName() + i + ".yml"), cloudStormCredentialInfo);
objectMapper.writeValue(new File(credentialsTempInputDirPath + File.separator + "top.yml"), cloudStormCredentialInfo);
i++; i++;
} }
CloudCredentials cloudStormCredentials = new CloudCredentials(); CloudCredentials cloudStormCredentials = new CloudCredentials();
cloudStormCredentials.setCloudCredential(cloudStormCredentialList); cloudStormCredentials.setCloudCredential(cloudStormCredentialList);
objectMapper.writeValue(new File(credentialsTempInputDirPath + File.separator + "CloudStormCredentials.yml"), cloudStormCredentials);
} }
private CredentialInfo getCloudStormCredentialInfo(Credential toscaCredentials) throws FileNotFoundException { private CredentialInfo getCloudStormCredentialInfo(Credential toscaCredentials, String tmpPath) throws FileNotFoundException {
CredentialInfo cloudStormCredentialInfo = new CredentialInfo(); CredentialInfo cloudStormCredentialInfo = new CredentialInfo();
switch (toscaCredentials.getCloudProviderName().toLowerCase()) { switch (toscaCredentials.getCloudProviderName().toLowerCase()) {
case "exogeni": case "exogeni":
String base64Keystore = toscaCredentials.getKeys().get("keystore"); String base64Keystore = toscaCredentials.getKeys().get("keystore");
byte[] decoded = Base64.getDecoder().decode(base64Keystore); byte[] decoded = Base64.getDecoder().decode(base64Keystore);
try (PrintWriter out = new PrintWriter("user.jks")) { try (PrintWriter out = new PrintWriter(tmpPath + File.separator + "user.jks")) {
out.println(new String(decoded)); out.println(new String(decoded));
} }
cloudStormCredentialInfo.setUserKeyName("user.jks"); cloudStormCredentialInfo.setUserKeyName("user.jks");
......
...@@ -84,8 +84,6 @@ public class Consumer extends DefaultConsumer { ...@@ -84,8 +84,6 @@ public class Consumer extends DefaultConsumer {
String response = objectMapper.writeValueAsString(responceMessage); String response = objectMapper.writeValueAsString(responceMessage);
logger.log(Level.INFO, "Sending Response: '{'0'}'{0}", response); logger.log(Level.INFO, "Sending Response: '{'0'}'{0}", response);
// Logger.getLogger(Consumer.class.getName()).log(Level.INFO, "Sending Response: {0}", response);
//We send the response back. No need to change anything here
channel.basicPublish("", properties.getReplyTo(), replyProps, response.getBytes("UTF-8")); channel.basicPublish("", properties.getReplyTo(), replyProps, response.getBytes("UTF-8"));
channel.basicAck(envelope.getDeliveryTag(), false); channel.basicAck(envelope.getDeliveryTag(), false);
} catch (JSchException | ApiException ex) { } catch (JSchException | ApiException ex) {
......
CloudCredentials: cloudCreds:
type: "object" type: "object"
properties: properties:
CloudCredential: CloudCredential:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment