Просмотр исходного кода

Dynamically generate credentials for Azure endpoint connection CORWEB-25

Removed Azure credentials explicit code from AddCloudConnection.js

Merge branch 'master' of https://github.com/smiclea/coriolis-web into CORWEB-25
smiclea 8 лет назад
Родитель
Сommit
42bf11bb92
2 измененных файлов с 21 добавлено и 26 удалено
  1. 18 26
      src/components/AddCloudConnection/AddCloudConnection.js
  2. 3 0
      src/constants/CloudLabels.js

+ 18 - 26
src/components/AddCloudConnection/AddCloudConnection.js

@@ -162,28 +162,20 @@ class AddCloudConnection extends Reflux.Component {
         return;
       }
 
-      // If Azure, explicitly setting the fields right
-      if (this.state.currentCloud.name == "azure") {
-        credentials = {}
-        credentials["subscription_id"] = this.state.currentCloudData["subscription_id"]
-        if (this.state.currentCloudData["login_type"] == "user_credentials") {
-          credentials["user_credentials"] = {
-            username: this.state.currentCloudData["username"],
-            password: this.state.currentCloudData["password"]
-          }
-        } else {
-          credentials["service_principal_credentials"] = {
-            tenant_id: this.state.currentCloudData["tenant_id"],
-            client_id: this.state.currentCloudData["client_id"],
-            client_secret: this.state.currentCloudData["client_secret"]
-          }
+      // If there's a switch radio, create a hierarchical structure with the selected radio as the root.
+      this.state.currentCloud.endpoint.fields.forEach(field => {
+        if (field.type === 'switch-radio') {
+          credentials[credentials[field.name]] = {}
+
+          field.options.forEach(fieldOptions => {
+            if (fieldOptions.value === credentials[field.name]) {
+              fieldOptions.fields.forEach(fieldOptionField => {
+                credentials[credentials[field.name]][fieldOptionField.name] = credentials[fieldOptionField.name]
+              })
+            }
+          })
         }
-      }
-
-      // Remove the login_type since it is not needed
-      if (this.state.currentCloud.name == "azure") {
-        delete credentials.login_type
-      }
+      })
 
       // If endpoint is new
       if (this.state.type == "new") {
@@ -304,7 +296,7 @@ class AddCloudConnection extends Reflux.Component {
           break
         case 'switch-radio':
           field.options.forEach(option => {
-            if (option.default && !currentCloudData[field.name]){
+            if (option.default && !currentCloudData[field.name]) {
               currentCloudData[field.name] = option.value
               this.setRadioRequiredFields(field, option.value)
               this.setState({ currentCloudData: currentCloudData })
@@ -342,16 +334,16 @@ class AddCloudConnection extends Reflux.Component {
 
   /**
    * Dinamically change the required fields affected by the current radio selection
-   * @param field 
-   * @param currentValue 
+   * @param field
+   * @param currentValue
    */
   setRadioRequiredFields(field, currentValue) {
     let requiredFields = this.state.requiredFields || [];
 
     // Remove fields set by previous radio change
     field.options.forEach(option => {
-      option.fields.forEach(field => {
-        requiredFields = requiredFields.filter(rf => rf !== field.name)
+      option.fields.forEach(f => {
+        requiredFields = requiredFields.filter(rf => rf !== f.name)
       })
     })
 

+ 3 - 0
src/constants/CloudLabels.js

@@ -38,6 +38,9 @@ export const defaultLabels = {
   migr_image: "Migration Image Name or Id",
   migr_image_map: "Migration Image Map",
   migr_network_name: "Migration Network Name",
+  migr_image_name: "Migration Image Name",
+  migr_image_name_map: "Migration Image Name Map",
+  migr_image_id: "Migration Image ID",
   migr_worker_use_config_drive: "Migration Worker use ConfigDrive",
   migr_worker_use_fip: "Migration Worker use FIP",
   delete_disks_on_vm_termination: "Delete Disks on VM termination",