瀏覽代碼

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 年之前
父節點
當前提交
d7549d6bd8
共有 1 個文件被更改,包括 19 次插入2 次删除
  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),
         },
         },
       }
       }
     }
     }