Skip to content

Commit

Permalink
fix #29: Failure to connect to an AEM instance listening to HTTPS con…
Browse files Browse the repository at this point in the history
…nections only

* added option in project settings to allow the use of self-signed certificates if needed
  • Loading branch information
raducotescu committed Dec 8, 2014
1 parent 500074a commit 458d851
Show file tree
Hide file tree
Showing 8 changed files with 130 additions and 79 deletions.
3 changes: 2 additions & 1 deletion sly/nls/en-gb/strings.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ define({
PROJECT_SETTING_SERVER_URL_ERROR_INVALID_CHAR : 'Special characters like \'{0}\' must be %-encoded.',
PROJECT_SETTING_REMOTE_USER_ERROR_EMPTY : 'Please provide a username.',
PROJECT_SETTING_REMOTE_USER_PASSWORD_ERROR_EMPTY : 'Please provide a password.',
PROJECT_SETTING_ACCEPT_SELF_SIGNED_CERTIFICATES : 'Accept self-signed certificates for HTTPS',

// Synchronisation indicator tooltip
SYNC_FULL : 'All selected files were synced successfully.',
Expand All @@ -53,4 +54,4 @@ define({
SYNC_STATUS_EXCLUDED_VLT : 'vlt file or file excluded by .vltignore pattern',
SYNC_STATUS_DELETED_FROM_REMOTE : 'removed - the file was deleted on the server'

});
});
3 changes: 2 additions & 1 deletion sly/nls/ro/strings.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ define({
PROJECT_SETTING_SERVER_URL_ERROR_INVALID_CHAR : 'Caracterele speciale precum \'{0}\' trebuie să fie %-codificate.',
PROJECT_SETTING_REMOTE_USER_ERROR_EMPTY : 'Vă rugăm să introduceți utilizatorul.',
PROJECT_SETTING_REMOTE_USER_PASSWORD_ERROR_EMPTY : 'Vă rugăm să introduceți parola.',
PROJECT_SETTING_ACCEPT_SELF_SIGNED_CERTIFICATES : 'Acceptați certificate care nu sunt semnate de CA',

// Synchronisation indicator tooltip
SYNC_FULL : 'Toate fișierele selectate au fost sincronizate cu succes.',
Expand All @@ -53,4 +54,4 @@ define({
SYNC_STATUS_EXCLUDED_VLT : 'fișier vlt sau fișier exclus de către .vltignore',
SYNC_STATUS_DELETED_FROM_REMOTE : 'șters - fișierul a fost șters pe server'

});
});
3 changes: 2 additions & 1 deletion sly/nls/root/strings.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ define({
PROJECT_SETTING_SERVER_URL_ERROR_INVALID_CHAR : 'Special characters like \'{0}\' must be %-encoded.',
PROJECT_SETTING_REMOTE_USER_ERROR_EMPTY : 'Please provide a username.',
PROJECT_SETTING_REMOTE_USER_PASSWORD_ERROR_EMPTY : 'Please provide a password.',
PROJECT_SETTING_ACCEPT_SELF_SIGNED_CERTIFICATES : 'Accept self-signed certificates for HTTPS',

// Synchronisation indicator tooltip
SYNC_FULL : 'All selected files were synced successfully.',
Expand All @@ -53,4 +54,4 @@ define({
SYNC_STATUS_EXCLUDED_VLT : 'vlt file or file excluded by .vltignore pattern',
SYNC_STATUS_DELETED_FROM_REMOTE : 'removed - the file was deleted on the server'

});
});
64 changes: 28 additions & 36 deletions sly/node/PackMgr.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,19 @@ node:true, eqeqeq:true, strict:true, undef:true, bitwise:true, immed:true, maxle
/**
* Uploads the ZIP content package from <code>packageFilePath</code> to the AEM instance from <code>serverURL</code>.
* @param {String} serverURL the server's URL (e.g. http://localhost:4502)
* @param {boolean} acceptSelfSigned boolean flag to indicate if self-signed certificates should be acceppted for HTTPs connections
* @param {String} user a user allowed to manage content packages
* @param {String} password the user's password
* @param {String} packageFilePath the path to the content package on the file system
* @returns {promise|Q.promise} a promise
*/
function uploadPackage(serverURL, user, password, packageFilePath) {
function uploadPackage(serverURL, acceptSelfSigned, user, password, packageFilePath) {
var deferred = Q.defer(),
packageStream = Fs.createReadStream(packageFilePath),
uri = serverURL + URL + '?cmd=upload';
var r = Request.post(
uri,
{
auth: {
user: user,
pass: password
}
},
_createRequestOptions(user, password, acceptSelfSigned),
function(err, httpResponse, body) {
if (!_errorDetected(err, httpResponse, serverURL, 200, deferred)) {
var response = JSON.parse(body);
Expand All @@ -61,22 +57,18 @@ node:true, eqeqeq:true, strict:true, undef:true, bitwise:true, immed:true, maxle
/**
* Installs a previously uploaded content package on the AEM instance from <code>serverURL</code>.
* @param {String} serverURL the server's URL (e.g. http://localhost:4502)
* @oaram {boolean} acceptSelfSigned boolean flag to indicate if self-signed certificates should be acceppted for HTTPs connections
* @param {String} user a user allowed to manage content packages
* @param {String} password the user's password
* @param {String} packageName the full content package name (e.g. 'group/name-version.zip')
* @returns {promise|Q.promise} a promise
*/
function installPackage(serverURL, user, password, packageName) {
function installPackage(serverURL, acceptSelfSigned, user, password, packageName) {
var deferred = Q.defer(),
uri = serverURL + URL + '/etc/packages/' + packageName + '?cmd=install';
Request.post(
uri,
{
auth: {
user: user,
pass: password
}
},
_createRequestOptions(user, password, acceptSelfSigned),
function (err, httpResponse, body) {
if (!_errorDetected(err, httpResponse, serverURL, 200, deferred)) {
var response = JSON.parse(body);
Expand All @@ -94,22 +86,18 @@ node:true, eqeqeq:true, strict:true, undef:true, bitwise:true, immed:true, maxle
/**
* Builds a previously uploaded content package on the AEM instance from <code>serverURL</code>.
* @param {String} serverURL the server's URL (e.g. http://localhost:4502)
* @oaram {boolean} acceptSelfSigned boolean flag to indicate if self-signed certificates should be acceppted for HTTPs connections
* @param {String} user a user allowed to manage content packages
* @param {String} password the user's password
* @param {String} packageName the full content package name (e.g. 'group/name-version.zip
* @returns {promise|Q.promise} a promise
*/
function buildPackage(serverURL, user, password, packageName) {
function buildPackage(serverURL, acceptSelfSigned, user, password, packageName) {
var deferred = Q.defer(),
uri = serverURL + URL + '/etc/packages/' + packageName + '?cmd=build';
Request.post(
uri,
{
auth: {
user: user,
pass: password
}
},
_createRequestOptions(user, password, acceptSelfSigned),
function(err, httpResponse, body) {
if (!_errorDetected(err, httpResponse, serverURL, 200, deferred)) {
var response = JSON.parse(body);
Expand All @@ -127,22 +115,18 @@ node:true, eqeqeq:true, strict:true, undef:true, bitwise:true, immed:true, maxle
/**
* Deletes a previously uploaded content package on the AEM instance from <code>serverURL</code>.
* @param {String} serverURL the server's URL (e.g. http://localhost:4502)
* @oaram {boolean} acceptSelfSigned boolean flag to indicate if self-signed certificates should be acceppted for HTTPs connections
* @param {String} user a user allowed to manage content packages
* @param {String} password the user's password
* @param {String} packageName the full content package name (e.g. 'group/name-version.zip)
* @returns {promise|Q.promise} a promise
*/
function deletePackage(serverURL, user, password, packageName) {
function deletePackage(serverURL, acceptSelfSigned, user, password, packageName) {
var deferred = Q.defer(),
uri = serverURL + URL + '/etc/packages/' + packageName + '?cmd=delete';
Request.post(
uri,
{
auth: {
user: user,
pass: password
}
},
_createRequestOptions(user, password, acceptSelfSigned),
function(err, httpResponse, body) {
if (!_errorDetected(err, httpResponse, serverURL, 200, deferred)) {
var response = JSON.parse(body);
Expand All @@ -161,14 +145,15 @@ node:true, eqeqeq:true, strict:true, undef:true, bitwise:true, immed:true, maxle
* Downloads package <code>packageName</code> from the AEM instance available at <code>serverURL</code> to the <code>outputFolder</code>
* folder.
* @param {String} serverURL the server's URL (e.g. http://localhost:4502)
* @oaram {boolean} acceptSelfSigned boolean flag to indicate if self-signed certificates should be acceppted for HTTPs connections
* @param {String} user a user allowed to manage content packages
* @param {String} password the user's password
* @param {String} packageName the full content package name (e.g. 'group/name-version.zip)
* @param {String} outputFolder the folder where the content package will be downloaded
* @param {String} [outputFileName] the file name under which to save the downloaded package
* @returns {promise|Q.promise} a promise
*/
function downloadPackage(serverURL, user, password, packageName, outputFolder, outputFileName) {
function downloadPackage(serverURL, acceptSelfSigned, user, password, packageName, outputFolder, outputFileName) {
var deferred = Q.defer(),
uri = serverURL + '/etc/packages/' + packageName,
mkdirp = Q.denodeify(Fs.mkdirp);
Expand All @@ -180,12 +165,7 @@ node:true, eqeqeq:true, strict:true, undef:true, bitwise:true, immed:true, maxle
function() {
var r = Request.get(
uri,
{
auth: {
user: user,
pass: password
}
},
_createRequestOptions(user, password, acceptSelfSigned),
function(err, httpResponse) {
_errorDetected(err, httpResponse, serverURL, 200, deferred);
}
Expand Down Expand Up @@ -223,9 +203,21 @@ node:true, eqeqeq:true, strict:true, undef:true, bitwise:true, immed:true, maxle
return false;
}

function _createRequestOptions(user, password, acceptSelfSigned) {
return {
auth: {
user: user,
pass: password
},
agentOptions: {
rejectUnauthorized: !acceptSelfSigned
}
}
}

exports.uploadPackage = uploadPackage;
exports.installPackage = installPackage;
exports.buildPackage = buildPackage;
exports.deletePackage = deletePackage;
exports.downloadPackage = downloadPackage;
}());
}());
63 changes: 36 additions & 27 deletions sly/node/SlyDomain.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@
******************************************************************************/
(function () {
'use strict';
var Fs = require('fs'),
Path = require('path'),
Request = require('request'),
var Fs = require('fs'),
Path = require('path'),
Request = require('request'),
VaultSyncManager = require('./VaultSyncManager'),
_remote,
_acceptSelfSignedCertificates = false,
_remoteUser,
_remotePassword,
JCR_ROOT = 'jcr_root',
VAULT_ROOT = Path.sep + JCR_ROOT + Path.sep;

function _extractRemotePath(path) {
var index = path.indexOf(VAULT_ROOT);
if (index > 0) {
Expand All @@ -24,12 +25,13 @@
return null;
}

function setRemote(remote, remoteUser, remotePassword) {
_remote = remote;
_remoteUser = remoteUser;
function setRemote(remote, remoteUser, remotePassword, acceptSelfSignedCertificates) {
_remote = remote;
_remoteUser = remoteUser;
_remotePassword = remotePassword;
_acceptSelfSignedCertificates = acceptSelfSignedCertificates || false;
}

function _internPost(path, formData, callback) {
var r = Request.post(
_remote + path,
Expand All @@ -39,7 +41,7 @@
pass: _remotePassword
}
},
function(err, httpResponse) {
function (err, httpResponse) {
if (err) {
if (err.code === 'ECONNREFUSED') {
callback('Connection to server ' + _remote + ' was refused.');
Expand Down Expand Up @@ -73,8 +75,8 @@

function postFile(parentPath, filePath, callback) {
var formData = {
'_charset_' : 'utf-8',
'*' : Fs.createReadStream(filePath)
'_charset_': 'utf-8',
'*': Fs.createReadStream(filePath)
};
if (parentPath.indexOf('/install', parentPath.length - '/install'.length) !== -1) {
// in that case we ensure node type is fulfilled in case the folder needs to be created
Expand All @@ -98,50 +100,57 @@
}

function pushVault(path, filterFile, callback) {
return VaultSyncManager.sync(_remote, _remoteUser, _remotePassword, path, filterFile, VaultSyncManager.PUSH).then(
function(fileSyncStatus) {
return VaultSyncManager.sync(_remote, _acceptSelfSignedCertificates, _remoteUser, _remotePassword, path, filterFile, VaultSyncManager.PUSH).then(
function (fileSyncStatus) {
callback(null, fileSyncStatus);
},
function(err) {
function (err) {
callback(err.message);
}
);
}

function pullVault(path, filterFile, callback) {
return VaultSyncManager.sync(_remote, _remoteUser, _remotePassword, path, filterFile, VaultSyncManager.PULL).then(
function(fileSyncStatus) {
return VaultSyncManager.sync(_remote, _acceptSelfSignedCertificates, _remoteUser, _remotePassword, path, filterFile, VaultSyncManager.PULL).then(
function (fileSyncStatus) {
callback(null, fileSyncStatus);
},
function(err) {
function (err) {
callback(err.message);
}
);
}

/**
* Initializes the test domain with several test commands.
* Initializes the domain.
* @param {DomainManager} domainManager The DomainManager for the server
*/
function init(domainManager) {
if (!domainManager.hasDomain('sly')) {
domainManager.registerDomain('sly', { major: 0, minor: 1});
domainManager.registerDomain('sly', {major: 0, minor: 1});
}

domainManager.registerCommand('sly', 'setRemote', setRemote, true, 'set remote server configuration',
[{name: 'remote', type: 'string', description: 'scheme, host & port string, e.g. http://localhost:4502'},
[
{name: 'remote', type: 'string', description: 'scheme, host & port string, e.g. http://localhost:4502'},
{name: 'remoteUser', type: 'string', description: 'remote username'},
{name: 'remotePassword', type: 'string', description: 'remote user password'}],
{name: 'remotePassword', type: 'string', description: 'remote user password'},
{
name: 'acceptSelfSignedCertificates',
type: 'boolean',
description: 'indicate whether to accept self-signed certificates for HTTPS connections'
}
],
[]);

domainManager.registerCommand('sly', 'postFile', postFile, true, 'post a file to the remote',
[{name: 'parentPath', type: 'string', description: 'path of the remote parent'},
{name: 'filePath', type: 'string', description: 'path of the file'}],
[]);
domainManager.registerCommand('sly', 'syncChildProcess', syncChildProcess, true, 'execute a child process',
[ {name: 'command', type: 'string', description: 'execute an alternative command for synchronizing files'},
[{name: 'command', type: 'string', description: 'execute an alternative command for synchronizing files'},
{name: 'path', type: 'string', description: 'path of the document/folder'}
],
],
[]);
domainManager.registerCommand(
'sly',
Expand Down Expand Up @@ -171,4 +180,4 @@

exports.init = init;

}());
}());
Loading

0 comments on commit 458d851

Please sign in to comment.