Example #1
0
exports.deploy = function(pm, options) {

    ASSERT(typeof options.username !== "undefined", "`config.username` is required!");
    ASSERT(typeof options.hostname !== "undefined", "`config.hostname` is required!");
    ASSERT(typeof options.targetPath !== "undefined", "`config.targetPath` is required!");
    ASSERT(typeof options.sshPrivateKeyPath !== "undefined", "`config.sshPrivateKeyPath` is required!");

    var privateKey = new CREDENTIALS_SSH.PrivateKey(pm.context.credentials, options.sshPrivateKeyPath);

    return privateKey.ensureInAuthenticationAgent().then(function() {

        var sshOptions = [
            "-avz",
            "--compress",
            "--copy-links",
            "-e", "ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o IdentityFile=" + privateKey.path
        ];
        // TODO: Don't sync `.deoloyignore`ed files.

        return call("rsync", pm.context.package.path, sshOptions.concat([
            options.sourcePath || ".",
            options.username + "@" + options.hostname + ":" + options.targetPath
        ]));
    });
}
Example #2
0
				}, function(err, result) {

					if (result.Errors && result.Errors.Error && result.Errors.Error.Code === "InvalidKeyPair.NotFound") {

						var privateKey = new CREDENTIALS_SSH.PrivateKey(pm.context.credentials, PrivateKeyPath || "aws-" + KeyName.replace(/[\/:]/g, "+") + "-rsa");

						Q.when(privateKey.getPublicKey(), function(publicKey) {
							PrivateKeyPath = privateKey.path;

							TERM.stdout.writenl("Uploading new AWS key '" + KeyName + "' stored at '" + privateKey.path + "'.");

							ec2.call("ImportKeyPair", {
								"KeyName": KeyName,
								"PublicKeyMaterial": new Buffer(publicKey).toString("base64")
							}, function(err, result) {
								if (err) {
									return deferred.reject(err);
								}
								deferred.resolve();
							});
						}).fail(deferred.reject);

					} else if (err) {
						return deferred.reject(err);
					} else {

						// The key was found on AWS. It should be at `PrivateKeyPath`. If it is not we ask
						// user to locate it.

						Q.call(function() {
							if (!PATH.existsSync(PrivateKeyPath)) {
								return pm.context.credentials.remove("github.com/sourcemint/sdk-aws/-meta/ec2-PrivateKeyPath/0", KeyName).then(function() {
									return pm.context.credentials.requestFor("github.com/sourcemint/sdk-aws/-meta/ec2-PrivateKeyPath/0", KeyName).then(function(keyPath) {
										keyPath = pm.context.credentials.makeAbsolutePath(keyPath);
										if (!PATH.existsSync(keyPath)) {
											return pm.context.credentials.remove("github.com/sourcemint/sdk-aws/-meta/ec2-PrivateKeyPath/0", KeyName).then(function() {
												throw new Error("Private key not found at: " + keyPath);
											});
										}
										PrivateKeyPath = keyPath;
									});
								});
							}
						}).then(function() {

							// TODO: Use `privateKey.getFingerprint()` to compare against fingerprint from AWS.

							deferred.resolve();

						}).fail(deferred.reject);
					}
				});