RIFT-14723: Allow for keypair instead of password for user at instantiation 07/507/1
authorLaurence Maultsby <laurence.maultsby@riftio.com>
Wed, 5 Oct 2016 13:13:02 +0000 (09:13 -0400)
committerLaurence Maultsby <laurence.maultsby@riftio.com>
Wed, 5 Oct 2016 13:13:02 +0000 (09:13 -0400)
Signed-off-by: Laurence Maultsby <laurence.maultsby@riftio.com>
skyquake/plugins/launchpad/src/instantiate/instantiateInputParams.jsx
skyquake/plugins/launchpad/src/instantiate/instantiateInputParams.scss
skyquake/plugins/launchpad/src/instantiate/instantiateStore.js

index 8ccebcb..c9c0f2c 100644 (file)
@@ -471,14 +471,61 @@ export default class InstantiateInputParams extends Component {
   }
   usersHTML = (props) => {
     let usersFn = props.usersFn;
+    let sshKeysList = props.sshKeysList;
     let usersList = props.usersList && props.usersList.map(function(u, i) {
+      let sshKeysRef = u['ssh-authorized-key'];
       return (
         <div className="input_group input_group-users" key={i}>
           <div className="inputControls">
           <div style={{fontWeight: 'bold', display: 'flex'}}>USER <span onClick={usersFn.remove(i)} className="removeInput"><img src={imgRemove} />Remove</span></div>
             <TextInput onChange={usersFn.update(i, 'name')} label="USERNAME" value={i.name} />
-            <TextInput onChange={usersFn.update(i, 'gecos')} label="REAL NAME" value={i.gecos} />
-            <TextInput onChange={usersFn.update(i, 'passwd')} type="password" label="PASSWORD" value={i.passwd} />
+            <TextInput onChange={usersFn.update(i, 'user-info')} label="REAL NAME" value={i.gecos} />
+            {
+              sshKeysRef.map(function(ref, j) {
+                let keyref = JSON.stringify(ref)
+                return (
+                  <div key={keyref.name + '-' + i + '-' + j} className="inputControls inputControls-sshkeys">
+                    <label>
+                      <div>
+                      <SelectOption
+                        label="Key Pair"
+                        options={sshKeysList && sshKeysList.map(function(k) {
+                          return {
+                            label: k.name,
+                            value: k
+                          }
+                        })}
+                        ref="keyPairSelection"
+                        initial={false}
+                        defaultValue={ref}
+                        onChange={usersFn.updateSSHkeyRef(i, j)}>
+                      </SelectOption>
+                      </div>
+                    </label>
+                    {
+                      sshKeysRef.length > 0 ?
+                        <label>
+                          <span onClick={usersFn.updateSSHkeyRef(i, j, true)} className="removeInput">
+                            <img src={imgRemove} />
+                            Remove
+                          </span>
+                        </label>
+                      : null
+                    }
+
+                  </div>
+                )
+              })
+            }
+              <div className="inputControls inputControls-sshkeys ">
+                <label style={{display: 'flex', 'flexDirection': 'row', 'alignItems': 'center'}}>
+                SSH KEY PAIR
+                  <span onClick={usersFn.updateSSHkeyRef(i).bind(null, {target:{value: JSON.stringify(sshKeysList[0])}})} className="addInput">
+                    <img src={imgAdd} />
+                    ADD
+                  </span>
+                </label>
+              </div>
           </div>
         </div>
       )
@@ -487,9 +534,9 @@ export default class InstantiateInputParams extends Component {
       <div className="configure-nsd_section">
         <h3 className="launchpadCard_title">USERS</h3>
         {usersList}
-        <div className="inputControls inputControls-sshkeys ">
-            <span onClick={usersFn.add} className="addInput">
-              <img src={imgAdd} onClick={usersFn.add} />
+        <div className="inputControls inputControls-sshkeys inputControls-addUser ">
+            <span onClick={usersFn.add(sshKeysList)} className="addInput">
+              <img src={imgAdd} />
               ADD USER
             </span>
         </div>
index 3494316..ba96660 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * 
+ *
  *   Copyright 2016 RIFT.IO Inc
  *
  *   Licensed under the Apache License, Version 2.0 (the "License");
               -ms-flex: 0 1;
                   flex: 0 1;
             }
+            .inputControls-sshkeys {
+              margin-bottom:1rem;
+              padding-top:0;
+              -ms-flex-align: end;
+              align-items: flex-end;
+              > label {
+                width:auto;
+                &:nth-child(2) {
+                    margin-bottom: 1.25rem;
+                }
+              }
+            }
           }
           button {
             /*remove button*/
         display:-ms-flexbox;
         display:flex;
       }
+      &-addUser {
+        margin-top:1rem;
+        .addInput {
+          margin-left:0;
+          font-size:1rem;
+          >span {
+            color: #5b5b5b;
+          }
+        }
+      }
     }
      .addInput, .removeInput {
           display:-ms-flexbox;
index 96c134d..2e27246 100644 (file)
@@ -582,18 +582,19 @@ class LaunchNetworkServiceStore {
     usersFn = () => {
         let self = this;
         return {
-            add: function() {
-                console.log('adding user')
-                let newUser = {
-                    name: '',
-                    gecos: '',
-                    passwd: ''
+            add: function(sshKeysList) {
+                return function(e) {
+                    let newUser = {
+                        name: '',
+                        'user-info': '',
+                        'ssh-authorized-key': [sshKeysList[0].name]
+                    }
+                    let usersList = self.usersList;
+                    usersList.push(newUser);
+                    self.setState({
+                        usersList:  usersList
+                    })
                 }
-                let usersList = self.usersList;
-                usersList.push(newUser);
-                self.setState({
-                    usersList:  usersList
-                })
             },
             remove: function(i) {
                 return function() {
@@ -611,6 +612,25 @@ class LaunchNetworkServiceStore {
                         usersList: self.usersList
                     })
                 }
+            },
+            updateSSHkeyRef: function(i, j, remove){
+                return function(e) {
+                    let usersList = _.cloneDeep(self.usersList)
+                    let keys = usersList[i]['ssh-authorized-key'];
+                    if(!remove) {
+                        let keyRef = JSON.parse(e.target.value).name;
+                        if(!isNaN(j)) {
+                            keys.splice(j, 1);
+                        }
+                        keys.push(keyRef);
+                    } else {
+                        keys.splice(j, 1);
+                    }
+                    usersList[i]['ssh-authorized-key'] = keys;
+                    self.setState({
+                        usersList: usersList
+                    })
+                }
             }
         }
     }
@@ -658,7 +678,7 @@ class LaunchNetworkServiceStore {
             "nsd": nsdPayload
         }
 
-        if (this.state.ro['account-type'] == 'openmano') {
+        if (this.state.ro && this.state.ro['account-type'] == 'openmano') {
             payload['om-datacenter'] = this.state.dataCenterID;
         } else {
             payload["cloud-account"] = this.state.selectedCloudAccount.name;
@@ -768,7 +788,7 @@ class LaunchNetworkServiceStore {
             return {'key-pair-ref': JSON.parse(k).name};
         });
         //Add Users
-        payload['user'] = this.state.usersList;
+        payload['user'] = addKeyPairRefToUsers(this.state.usersList);
         // console.log(payload)
         this.launchNSR({
             'nsr': [payload]
@@ -777,6 +797,19 @@ class LaunchNetworkServiceStore {
 }
 
 
+function addKeyPairRefToUsers(list) {
+    return list.map(function(u) {
+        return {
+            name: u.name,
+            'user-info': u['user-info'],
+            'ssh-authorized-key': u['ssh-authorized-key'].map(function(k) {
+                return {
+                    'key-pair-ref' : k
+                }
+            })
+        }
+    })
+}
 
 function getMockSLA(id) {
     console.log('Getting mock SLA Data for id: ' + id);