| 
									
										
										
										
											2016-11-24 23:21:40 +01:00
										 |  |  | import * as plugins from './npmci.plugins' | 
					
						
							| 
									
										
										
										
											2016-06-23 22:22:03 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-25 18:53:35 +02:00
										 |  |  | let sshRegex = /^(.*)\|(.*)\|(.*)/ | 
					
						
							| 
									
										
										
										
											2016-11-24 23:21:40 +01:00
										 |  |  | let sshInstance: plugins.smartssh.SshInstance | 
					
						
							| 
									
										
										
										
											2016-06-24 02:54:55 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-04 13:42:22 +02:00
										 |  |  | /** | 
					
						
							|  |  |  |  * checks for ENV vars in form of NPMCI_SSHKEY_* and deploys any found ones | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2017-03-08 14:50:41 +01:00
										 |  |  | export let ssh = async () => { | 
					
						
							|  |  |  |   sshInstance = new plugins.smartssh.SshInstance() // init ssh instance
 | 
					
						
							|  |  |  |   plugins.smartparam.forEachMinimatch(process.env, 'NPMCI_SSHKEY_*', evaluateSshEnv) | 
					
						
							|  |  |  |   if (!process.env.NPMTS_TEST) { | 
					
						
							|  |  |  |     sshInstance.writeToDisk() | 
					
						
							|  |  |  |   } else { | 
					
						
							|  |  |  |     plugins.beautylog.log('In test mode, so not storing SSH keys to disk!') | 
					
						
							|  |  |  |   }; | 
					
						
							| 
									
										
										
										
											2016-11-24 23:21:40 +01:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2016-06-23 22:22:03 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-04 13:42:22 +02:00
										 |  |  | /** | 
					
						
							|  |  |  |  * gets called for each found SSH ENV Var and deploys it  | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2017-03-08 14:50:41 +01:00
										 |  |  | let evaluateSshEnv = async (sshkeyEnvVarArg) => { | 
					
						
							|  |  |  |   let resultArray = sshRegex.exec(sshkeyEnvVarArg) | 
					
						
							|  |  |  |   let sshKey = new plugins.smartssh.SshKey() | 
					
						
							|  |  |  |   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-11-24 23:21:40 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-08 14:50:41 +01:00
										 |  |  |   sshInstance.addKey(sshKey) | 
					
						
							|  |  |  |   return | 
					
						
							| 
									
										
										
										
											2016-11-24 23:21:40 +01:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2016-06-25 18:53:35 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-04 13:42:22 +02:00
										 |  |  | /** | 
					
						
							|  |  |  |  * checks if not undefined | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2016-11-24 23:21:40 +01:00
										 |  |  | let notUndefined = (stringArg: string) => { | 
					
						
							| 
									
										
										
										
											2017-03-08 14:50:41 +01:00
										 |  |  |   return (stringArg && stringArg !== 'undefined' && stringArg !== '##') | 
					
						
							| 
									
										
										
										
											2016-11-24 23:21:40 +01:00
										 |  |  | } |