Skip to content
This repository has been archived by the owner on Jun 13, 2024. It is now read-only.

Commit

Permalink
Fixes for v1.6.1 (#176)
Browse files Browse the repository at this point in the history
* fix how to fix sqldb provisioning parameters with default provisioning parameters

* fix sqldb-failover-group how to generate FQDN

* add sqldb plans for s4 - s12

* treat 200 as success in creation to mitigate 504 error (it actually succeeded)

* turn on failover group e2e test in lifecycle

* add a unit test case for sqldb fixing parameters

* fix indentation

* update broker version
  • Loading branch information
zhongyi-zhang authored Jun 6, 2018
1 parent 58c1455 commit 2be01bc
Show file tree
Hide file tree
Showing 10 changed files with 885 additions and 593 deletions.
14 changes: 7 additions & 7 deletions lib/services/azurerediscache/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ exports.provision = function(resourceGroupName, cacheName, parameters, callback)
if (err) {
return callback(err);
}

if (res.statusCode != HttpStatus.NOT_FOUND) {
var error = Error('The cache name is not available.');
error.statusCode = HttpStatus.CONFLICT;
return callback(error);
}

msRestRequest.PUT(
util.format(
redisUrlTemplate,
Expand All @@ -63,10 +63,10 @@ exports.provision = function(resourceGroupName, cacheName, parameters, callback)
if (err) {
return callback(err);
}
if (res.statusCode != HttpStatus.CREATED) {
if (res.statusCode != HttpStatus.CREATED && res.statusCode != HttpStatus.OK) {
return common.formatErrorFromRes(res, callback);
}

callback(null, body.properties);
}
);
Expand All @@ -86,7 +86,7 @@ exports.poll = function(resourceGroupName, cacheName, callback) {
e.statusCode = res.statusCode;
return callback(e);
}

callback(null, JSON.parse(body).properties);
}
);
Expand All @@ -110,7 +110,7 @@ exports.deprovision = function(resourceGroupName, cacheName, callback) {
if (res.statusCode != HttpStatus.OK && res.statusCode != HttpStatus.NO_CONTENT) {
return common.formatErrorFromRes(res, callback);
}

callback(null);
}
);
Expand All @@ -135,7 +135,7 @@ exports.bind = function(resourceGroupName, cacheName, callback) {
if (res.statusCode != HttpStatus.OK) {
return common.formatErrorFromRes(res, callback);
}

callback(null, JSON.parse(body));
}
);
Expand Down
93 changes: 41 additions & 52 deletions lib/services/azuresqldb/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,49 +11,36 @@ var log = common.getLogger(Config.name);
var cmdDeprovision = require('./cmd-deprovision');
var cmdProvision = require('./cmd-provision');
var cmdPoll = require('./cmd-poll');
var cmdBind = require('./cmd-bind.js');
var cmdUnbind = require('./cmd-unbind.js');
var cmdUpdate = require('./cmd-update.js');
var cmdBind = require('./cmd-bind');
var cmdUnbind = require('./cmd-unbind');
var cmdUpdate = require('./cmd-update');
var sqldbOperations = require('./client');
var deepExtend = require('deep-extend');

var Handlers = {};

Handlers.fixParameters = function(parameters, accountPool) {

parameters = common.fixParametersWithDefaults('DEFAULT_PARAMETERS_AZURE_SQLDB', parameters);
if (parameters.sqlServerName && parameters.sqlServerName in accountPool.sqldb) { // assume user wants to create db on an existing server
if (process.env['DEFAULT_PARAMETERS_AZURE_SQLDB']) {
var defaultParams = JSON.parse(process.env['DEFAULT_PARAMETERS_AZURE_SQLDB']);
// For creating db on an existing server, following default parameters should be deleted. The broker gets these info in provision.
delete defaultParams.resourceGroup;
delete defaultParams.location;
delete defaultParams.sqlServerName;
delete defaultParams.sqlServerParameters;

// The right overwrites the left if conflict
parameters = deepExtend(defaultParams, parameters);
}

// For creating db on an existing server, the following parameters should be ignored. The broker gets these info in provision.
delete parameters.resourceGroup;
delete parameters.location;
delete parameters.sqlServerParameters;
if (process.env['ALLOW_TO_GENERATE_NAMES_AND_PASSWORDS_FOR_THE_MISSING'] === 'true') {
if (!parameters.sqldbName) parameters.sqldbName = common.generateName();
}

return parameters;

} else {
parameters = common.fixParametersWithDefaults('DEFAULT_PARAMETERS_AZURE_SQLDB', parameters);
if (process.env['ALLOW_TO_GENERATE_NAMES_AND_PASSWORDS_FOR_THE_MISSING'] === 'true') {
if (!parameters.sqlServerName) parameters.sqlServerName = common.generateName();
if (!parameters.sqldbName) parameters.sqldbName = common.generateName();

if (!parameters.sqlServerParameters) parameters.sqlServerParameters = {};
var serverParams = parameters.sqlServerParameters;
if (!serverParams.properties) serverParams.properties = {};
var serverProps = serverParams.properties;
if (!serverProps.administratorLogin) serverProps.administratorLogin = common.generateName();
if (!serverProps.administratorLoginPassword) serverProps.administratorLoginPassword = common.generateStrongPassword();
}

return parameters;
}
};
Expand All @@ -67,7 +54,7 @@ Handlers.catalog = function (params, next) {
if (availableEnvironments.indexOf(params.azure.environment) === -1) {
return next(null);
}

var reply = Config;
next(null, reply);
};
Expand Down Expand Up @@ -159,42 +146,44 @@ Handlers.bind = function (params, next) {
var databaseLogin = result.databaseLogin;
var databaseLoginPassword = result.databaseLoginPassword;
// encode the URI components that can contain reserved "delimiter" characters
// see: https://tools.ietf.org/html/rfc3986#section-2.2
// see: https://tools.ietf.org/html/rfc3986#section-2.2
var encodedLogin = encodeURIComponent(databaseLogin);
var encodedLoginPassword = encodeURIComponent(databaseLoginPassword);
var fqdn = provisioningResult.fullyQualifiedDomainName;

// Spring Cloud Connector Support
var jdbcUrlTemplate = 'jdbc:sqlserver://%s:1433;' +
'database=%s;' +
'user=%s;' +
'password=%s;' +
'Encrypt=true;' +
'TrustServerCertificate=false;' +
'HostNameInCertificate=%s;' +
'loginTimeout=30;';
'database=%s;' +
'user=%s;' +
'password=%s;' +
'Encrypt=true;' +
'TrustServerCertificate=false;' +
'HostNameInCertificate=%s;' +
'loginTimeout=30;';

var jdbcUrl = util.format(jdbcUrlTemplate,
fqdn,
sqldbName,
databaseLogin,
databaseLoginPassword,
fqdn.replace(/.+\.database/, '*.database'));
fqdn,
sqldbName,
databaseLogin,
databaseLoginPassword,
fqdn.replace(/.+\.database/, '*.database')
);

// Differences between auditing enabled and disabled: https://docs.microsoft.com/en-us/azure/sql-database/sql-database-auditing-and-dynamic-data-masking-downlevel-clients
var jdbcUrlForAuditingEnabled = util.format(jdbcUrlTemplate,
fqdn.replace(/\.database/, '.database.secure'),
sqldbName,
databaseLogin,
databaseLoginPassword,
fqdn.replace(/.+\.database/, '*.database.secure'));

var uri = util.format('mssql://%s:%s@%s:1433/%s?encrypt=true&TrustServerCertificate=false&HostNameInCertificate=%s',
encodedLogin,
encodedLoginPassword,
fqdn,
sqldbName,
fqdn.replace(/.+\.database/, '%2A.database'));
fqdn.replace(/\.database/, '.database.secure'),
sqldbName,
databaseLogin,
databaseLoginPassword,
fqdn.replace(/.+\.database/, '*.database.secure'));

var uri = util.format('mssql://%s:%s@%s:1433/%s?encrypt=true&TrustServerCertificate=false&HostNameInCertificate=%s',
encodedLogin,
encodedLoginPassword,
fqdn,
sqldbName,
fqdn.replace(/.+\.database/, '%2A.database')
);

// contents of reply.value winds up in VCAP_SERVICES
var reply = {
Expand All @@ -210,11 +199,11 @@ Handlers.bind = function (params, next) {
jdbcUrl: jdbcUrl,
jdbcUrlForAuditingEnabled: jdbcUrlForAuditingEnabled,
hostname: fqdn,
  port: 1433,
  name: sqldbName,
  username: databaseLogin,
  password: databaseLoginPassword,
  uri: uri
port: 1433,
name: sqldbName,
username: databaseLogin,
password: databaseLoginPassword,
uri: uri
}
}
};
Expand Down
Loading

0 comments on commit 2be01bc

Please sign in to comment.