Pārlūkot izejas kodu

Use default values for Azure Stack

Even though usually we don't send the default values in the connection
info payload, for Azure Stack we do this so the backend doesn't have to
do lots of 'ifs'.
Sergiu Miclea 8 gadi atpakaļ
vecāks
revīzija
d7549d6bd8
1 mainītis faili ar 19 papildinājumiem un 2 dzēšanām
  1. 19 2
      src/plugins/endpoint/azure/SchemaPlugin.js

+ 19 - 2
src/plugins/endpoint/azure/SchemaPlugin.js

@@ -19,6 +19,23 @@ import {
   fieldsToPayload,
   fieldsToPayload,
 } from '../default/SchemaPlugin'
 } from '../default/SchemaPlugin'
 
 
+const fieldsToPayloadUseDefaults = (data, schema) => {
+  let info = {}
+
+  Object.keys(schema.properties).forEach(fieldName => {
+    if (typeof data[fieldName] === 'object') {
+      return
+    }
+    if (data[fieldName]) {
+      info[fieldName] = data[fieldName]
+    } else if (schema.properties[fieldName].default) {
+      info[fieldName] = schema.properties[fieldName].default
+    }
+  })
+
+  return info
+}
+
 const azureConnectionParse = schema => {
 const azureConnectionParse = schema => {
   let commonFields = connectionSchemaToFields(schema).filter(f => f.type !== 'object' && f.name !== 'secret_ref' && Object.keys(f).findIndex(k => k === 'enum') === -1)
   let commonFields = connectionSchemaToFields(schema).filter(f => f.type !== 'object' && f.name !== 'secret_ref' && Object.keys(f).findIndex(k => k === 'enum') === -1)
 
 
@@ -79,10 +96,10 @@ export default class ConnectionSchemaParser {
     if (data.cloud_profile === 'CustomCloud') {
     if (data.cloud_profile === 'CustomCloud') {
       connectionInfo.custom_cloud_properties = {
       connectionInfo.custom_cloud_properties = {
         endpoints: {
         endpoints: {
-          ...fieldsToPayload(data, schema.properties.custom_cloud_properties.properties.endpoints),
+          ...fieldsToPayloadUseDefaults(data, schema.properties.custom_cloud_properties.properties.endpoints),
         },
         },
         suffixes: {
         suffixes: {
-          ...fieldsToPayload(data, schema.properties.custom_cloud_properties.properties.suffixes),
+          ...fieldsToPayloadUseDefaults(data, schema.properties.custom_cloud_properties.properties.suffixes),
         },
         },
       }
       }
     }
     }