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

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 лет назад
Родитель
Сommit
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,
 } 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 => {
   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') {
       connectionInfo.custom_cloud_properties = {
         endpoints: {
-          ...fieldsToPayload(data, schema.properties.custom_cloud_properties.properties.endpoints),
+          ...fieldsToPayloadUseDefaults(data, schema.properties.custom_cloud_properties.properties.endpoints),
         },
         suffixes: {
-          ...fieldsToPayload(data, schema.properties.custom_cloud_properties.properties.suffixes),
+          ...fieldsToPayloadUseDefaults(data, schema.properties.custom_cloud_properties.properties.suffixes),
         },
       }
     }