| 
									
										
										
										
											2016-06-23 22:22:03 +02:00
										 |  |  | import "typings-global"; | 
					
						
							|  |  |  | import * as plugins from "./npmci.plugins"; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-25 18:53:35 +02:00
										 |  |  | let sshRegex = /^(.*)\|(.*)\|(.*)/ | 
					
						
							| 
									
										
										
										
											2016-06-24 02:54:55 +02:00
										 |  |  | let sshInstance:plugins.smartssh.SshInstance; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-23 22:22:03 +02:00
										 |  |  | export let ssh = () => { | 
					
						
							| 
									
										
										
										
											2016-06-25 16:29:06 +02:00
										 |  |  |     let done = plugins.q.defer(); | 
					
						
							| 
									
										
										
										
											2016-06-24 02:54:55 +02:00
										 |  |  |     sshInstance = new plugins.smartssh.SshInstance(); | 
					
						
							| 
									
										
										
										
											2016-06-25 16:29:06 +02:00
										 |  |  |     plugins.smartparam.forEachMinimatch(process.env,"NPMCI_SSHKEY_*",evaluateSshEnv); | 
					
						
							| 
									
										
										
										
											2016-06-26 02:17:17 +02:00
										 |  |  |     if(!process.env.NPMTS_TEST){ | 
					
						
							|  |  |  |         sshInstance.writeToDisk() | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |         plugins.beautylog.log("In test mode, so not storing SSH keys to disk!"); | 
					
						
							|  |  |  |     }; | 
					
						
							| 
									
										
										
										
											2016-06-25 16:29:06 +02:00
										 |  |  |     done.resolve(); | 
					
						
							|  |  |  |     return done.promise; | 
					
						
							| 
									
										
										
										
											2016-06-23 22:22:03 +02:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-25 16:29:06 +02:00
										 |  |  | let evaluateSshEnv = (sshkeyEnvVarArg) => { | 
					
						
							| 
									
										
										
										
											2016-06-24 02:54:55 +02:00
										 |  |  |     let resultArray = sshRegex.exec(sshkeyEnvVarArg); | 
					
						
							|  |  |  |     let sshKey = new plugins.smartssh.SshKey(); | 
					
						
							| 
									
										
										
										
											2016-06-26 02:17:17 +02:00
										 |  |  |     plugins.beautylog.info("Found SSH identity for " + resultArray[1]); | 
					
						
							|  |  |  |     if(notUndefined(resultArray[1])){ | 
					
						
							|  |  |  |         plugins.beautylog.log("---> host defined!") | 
					
						
							|  |  |  |         sshKey.host = resultArray[1]; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if(notUndefined(resultArray[2])){ | 
					
						
							|  |  |  |         plugins.beautylog.log("---> privKey defined!") | 
					
						
							|  |  |  |         sshKey.privKeyBase64 = resultArray[2]; | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  |     if(notUndefined(resultArray[3])){ | 
					
						
							|  |  |  |         "---> pubKey defined!" | 
					
						
							|  |  |  |         sshKey.pubKeyBase64 = resultArray[3]; | 
					
						
							|  |  |  |     }; | 
					
						
							| 
									
										
										
										
											2016-06-23 22:22:03 +02:00
										 |  |  |      | 
					
						
							| 
									
										
										
										
											2016-06-24 02:54:55 +02:00
										 |  |  |     sshInstance.addKey(sshKey); | 
					
						
							| 
									
										
										
										
											2016-06-25 18:53:35 +02:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | let notUndefined = (stringArg:string) => { | 
					
						
							| 
									
										
										
										
											2016-06-26 02:17:17 +02:00
										 |  |  |     return (stringArg && stringArg != "undefined" && stringArg != "##"); | 
					
						
							| 
									
										
										
										
											2016-06-25 18:53:35 +02:00
										 |  |  | } |