Bläddra i källkod

Adds field validation for Azure

George Vrancianu 8 år sedan
förälder
incheckning
4d2d3376b9

+ 27 - 5
src/components/AddCloudConnection/AddCloudConnection.js

@@ -49,12 +49,12 @@ class AddCloudConnection extends Reflux.Component {
       type: props.type, // type of operation: new/edit
       connection: props.connection, // connection object (on edit)
       connectionName: "", // connection name field
-      description: null, // connection description field
+      description: "", // connection description field
       currentCloud: this.props.cloud, // chosen cloud - if adding a new endpoint
       currentCloudData: null, // endpoint field data
       validateEndpoint: false, // holds the endpoint object when validation
       requiredFields: [], // array that holds all the endpoint required fields - used for field validation
-      cloudFormsSubmitted: false // flag that indicates if the form has been submitte - used for field validation
+      cloudFormsSubmitted: false // flag that indicates if the form has been submitted - used for field validation
     }
   }
 
@@ -101,12 +101,30 @@ class AddCloudConnection extends Reflux.Component {
   handleSave() {
     let valid = true
     let requiredFields = this.state.requiredFields
+    // If Azure, validate fields manually
+    if (this.state.currentCloud.name == "azure") {
+      if (this.state.currentCloudData.login_type == "user_credentials") {
+        requiredFields = ["subscription_id", "username", "password"]
+      } else if (this.state.currentCloudData.login_type == "service_principal_credentials") {
+        requiredFields = ["subscription_id", "tenant_id", "client_id", "client_secret"]
+      } else {
+        valid = false
+        NotificationActions.notify("Please choose the login type", "error")
+      }
+      this.setState({ requiredFields: requiredFields })
+    }
 
     for (let i in this.state.currentCloudData) {
       if (requiredFields.indexOf(i) > -1 && !this.state.currentCloudData[i]) {
         valid = false
       }
     }
+    requiredFields.forEach((field) => {
+      if (!this.state.currentCloudData[field]) {
+        valid = false
+      }
+    })
+
     if (this.state.connectionName.trim().length == 0) {
       valid = false
     }
@@ -289,10 +307,14 @@ class AddCloudConnection extends Reflux.Component {
    */
   isValid(field) {
     if (field.required && this.state.cloudFormsSubmitted) {
-      if (this.state.currentCloudData[field.name].length == 0) {
-        return false
+      if (this.state.currentCloudData[field.name]) {
+        if (this.state.currentCloudData[field.name] && this.state.currentCloudData[field.name].length == 0) {
+          return false
+        } else {
+          return true
+        }
       } else {
-        return true
+        return false
       }
     } else {
       return true

+ 3 - 0
src/stores/ConnectionsStore/ConnectionsStore.js

@@ -304,6 +304,8 @@ class ConnectionsStore extends Reflux.Store
         required: cloudData.properties.user_credentials.required
       }
 
+      userCredentialFields.required.push("subscription_id")
+
       for (var i in cloudData.properties.user_credentials.properties) {
         userCredentialFields.properties[i] = cloudData.properties.user_credentials.properties[i]
       }
@@ -315,6 +317,7 @@ class ConnectionsStore extends Reflux.Store
       for (var i in cloudData.properties.service_principal_credentials.properties) {
         servicePrincipalCredentialFields.properties[i] = cloudData.properties.service_principal_credentials.properties[i]
       }
+      servicePrincipalCredentialFields.required.push("subscription_id")
 
       let newCloudData = {
         type: "switch-radio",