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

Updating SQLDB module bind/unbind to use admin credentials from manif… #211

Merged
merged 2 commits into from
May 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 17 additions & 7 deletions lib/services/azuresqldb/cmd-bind.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ var log = common.getLogger(Config.name);
var sqldbBind = function (params) {

var reqParams = params.parameters || {};
var accountPool = params.accountPool.sqldb || {};

var provisioningResult = params.provisioning_result || {};
var sqlServerName = reqParams.sqlServerName || '';
var resourceGroupName = provisioningResult.resourceGroup || '';
var sqldbName = reqParams.sqldbName || '';
var sqlServerName = reqParams.sqlServerName || '';

log.info(util.format('sqldb cmd-bind: resourceGroupName: %s, sqldbName: %s, sqlServerName: %s', resourceGroupName, sqldbName, sqlServerName));

Expand All @@ -25,6 +27,14 @@ var sqldbBind = function (params) {
databaseLoginPassword: reqParams.userProvidedDatabaseLoginPassword
});
}
var administratorLogin, administratorLoginPassword;
if (sqlServerName in accountPool) {
administratorLogin = accountPool[sqlServerName]['administratorLogin'];
administratorLoginPassword = accountPool[sqlServerName]['administratorLoginPassword'];
} else {
var errorMessage = util.format('Can\'t find the server name %s in sqlServerPool.', sqlServerName);
next(Error(errorMessage));
}
sqldbOperations.setParameters(resourceGroupName, sqlServerName, sqldbName);
var databaseLogin, databaseLoginPassword;
async.waterfall([
Expand All @@ -35,8 +45,8 @@ var sqldbBind = function (params) {
// create the login
sqldbOperations.createDatabaseLogin(
provisioningResult.fullyQualifiedDomainName,
provisioningResult.administratorLogin,
provisioningResult.administratorLoginPassword,
administratorLogin,
administratorLoginPassword,
databaseLogin,
databaseLoginPassword,
false,
Expand All @@ -51,8 +61,8 @@ var sqldbBind = function (params) {
function (callback) {
sqldbOperations.createUserForDatabaseLogin(
provisioningResult.fullyQualifiedDomainName,
provisioningResult.administratorLogin,
provisioningResult.administratorLoginPassword,
administratorLogin,
administratorLoginPassword,
databaseLogin,
false,
function(err) {
Expand All @@ -66,8 +76,8 @@ var sqldbBind = function (params) {
function (callback) {
sqldbOperations.grantControlToUser(
provisioningResult.fullyQualifiedDomainName,
provisioningResult.administratorLogin,
provisioningResult.administratorLoginPassword,
administratorLogin,
administratorLoginPassword,
databaseLogin,
true,
function(err) {
Expand Down
17 changes: 13 additions & 4 deletions lib/services/azuresqldb/cmd-unbind.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ var log = common.getLogger(Config.name);
var sqldbUnbind = function (params) {

var reqParams = params.parameters || {};
var accountPool = params.accountPool.sqldb || {};
var provisioningResult = params.provisioning_result || {};
var bindingResult = params.binding_result || {};
var resourceGroupName = provisioningResult.resourceGroup || '';
Expand All @@ -22,14 +23,22 @@ var sqldbUnbind = function (params) {
if (reqParams.userProvidedDatabaseLogin) {
return next(null);
}
var administratorLogin, administratorLoginPassword;
if (sqlServerName in accountPool) {
administratorLogin = accountPool[sqlServerName]['administratorLogin'];
administratorLoginPassword = accountPool[sqlServerName]['administratorLoginPassword'];
} else {
var errorMessage = util.format('Can\'t find the sql server %s in sqlServerPool.', sqlServerName);
next(Error(errorMessage));
}
sqldbOperations.setParameters(resourceGroupName, sqlServerName, sqldbName);
async.waterfall([
function (callback) {
log.info('sqldb cmd-unbind: async.waterfall/dropUserOfDatabaseLogin');
sqldbOperations.dropUserOfDatabaseLogin(
provisioningResult.fullyQualifiedDomainName,
provisioningResult.administratorLogin,
provisioningResult.administratorLoginPassword,
administratorLogin,
administratorLoginPassword,
bindingResult.databaseLogin,
false,
function(err) {
Expand All @@ -44,8 +53,8 @@ var sqldbUnbind = function (params) {
log.info('sqldb cmd-unbind: async.waterfall/dropDatabaseLogin');
sqldbOperations.dropDatabaseLogin(
provisioningResult.fullyQualifiedDomainName,
provisioningResult.administratorLogin,
provisioningResult.administratorLoginPassword,
administratorLogin,
administratorLoginPassword,
bindingResult.databaseLogin,
true,
function(err) {
Expand Down
2 changes: 0 additions & 2 deletions test/integration/lifecycle.js
Original file line number Diff line number Diff line change
Expand Up @@ -324,5 +324,3 @@ runLifecycle(require('./test-matrix'));

// Rerun lifecycle tests without the ability to create SQL servers
process.env['AZURE_SQLDB_ALLOW_TO_CREATE_SQL_SERVER'] = 'false';

runLifecycle(require('./test-matrix2'));
212 changes: 198 additions & 14 deletions test/integration/submatrix/sqldb.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
/*jshint camelcase: false */
var uuid = require('uuid');
var async = require('async');

var supportedEnvironments = require('../../utils/supportedEnvironments');
var common = require('../../../lib/common/');
var sqldb = require('../../../lib/services/azuresqldb/');

var testMatrix = [];
var instanceId;
Expand All @@ -12,13 +16,29 @@ var environment = process.env['ENVIRONMENT'];
var location = supportedEnvironments[environment]['location'];
var sqlServerName;
var sqldbName;
var sqldbNamePre;
var azuresqldb;

instanceId = uuid.v4();
bindingId = uuid.v4();
resourceGroupName = 'cloud-foundry-' + instanceId;
sqlServerName = 'cf' + instanceId;
sqldbName = 'cf' + instanceId;
sqldbNamePre = sqldbName + 'pre';

var serverPool = [];

serverPool.push({
'resourceGroup': resourceGroupName,
'location': location,
'sqlServerName': sqlServerName,
'administratorLogin': 'azureuser',
'administratorLoginPassword': 'c1oudc0w!@#'
});
var envVars = {
'AZURE_SQLDB_SQL_SERVER_POOL': JSON.stringify(serverPool)
};

azuresqldb = {
serviceName: 'azure-sqldb',
serviceId: 'fb9bc99e-0aa9-11e6-8a8a-000d3a002ed5',
Expand Down Expand Up @@ -72,25 +92,115 @@ azuresqldb = {
'password': '<string>',
'uri': '<string>'
},
e2e: false
e2e: false,
envVars: envVars,
preProvision: function(callback) {
var opParams = {
'organization_guid': uuid.v4(),
'plan_id': '3819fdfa-0aaa-11e6-86f4-000d3a002ed5',
'service_id': 'fb9bc99e-0aa9-11e6-8a8a-000d3a002ed5',
'space_guid': uuid.v4(),
'privilege': {
'sqldb': {
'allowToCreateSqlServer': true
}
},
'accountPool': { 'sqldb': {} },
'parameters': {
'resourceGroup': resourceGroupName,
'location': location,
'sqlServerName': sqlServerName,
'sqlServerParameters': {
'allowSqlServerFirewallRules': [
{
'ruleName': 'test',
'startIpAddress': '0.0.0.0',
'endIpAddress': '255.255.255.255'
}
],
'properties': {
'administratorLogin': 'azureuser',
'administratorLoginPassword': 'c1oudc0w!@#'
}
},
'sqldbName': sqldbNamePre,
'sqldbParameters': {
'properties': {
'collation': 'SQL_Latin1_General_CP1_CI_AS'
}
}
},
'azure': common.getConfigurations().azure
};
sqldb.provision(opParams, function(err) {
if (err) return callback(err);

opParams.parameters.sqlServerName = sqlServerName;
opParams.parameters.sqldbName = 'cf' + uuid.v4();
opParams.parameters.location = location;
sqldb.provision(opParams, function(err) {
if (err) return callback(err);
opParams.parameters.sqlServerName = sqlServerName;
opParams.parameters.sqldbName = sqldbNamePre;
opParams.parameters.location = location;
opParams.last_operation = 'provision';
opParams.provisioning_result = {
'resourceGroup': resourceGroupName
};
opParams.defaultSettings = {sqldb: {transparentDataEncryption: false}};
var state;
async.whilst(
function() {
return (state !== 'succeeded');
},
function(cb) {
sqldb.poll(opParams, function(err, lastOp, result) {
if (err) return cb(err);
state = result.value.state;
cb(null);
});
},
function(err) {
callback(err);
}
);
});
});
}
};

testMatrix.push(azuresqldb);

instanceId = uuid.v4();
bindingId = uuid.v4();
resourceGroupName = 'cloud-foundry-' + instanceId;
sqlServerName = 'cf' + instanceId;
sqldbName = 'cf' + instanceId;
var instanceId2 = uuid.v4();
var bindingId2 = uuid.v4();
var resourceGroupName2 = 'cloud-foundry-' + instanceId2;
var sqlServerName2 = 'cf' + instanceId2;
var sqldbName2 = 'cf' + instanceId2;
var sqldbNamePre2 = sqldbName + 'pre';

var serverPool2 = [];

serverPool2.push({
'resourceGroup': resourceGroupName2,
'location': location,
'sqlServerName': sqlServerName2,
'administratorLogin': 'azureuser',
'administratorLoginPassword': 'c1oudc0w!@#'
});
var envVars2 = {
'AZURE_SQLDB_SQL_SERVER_POOL': JSON.stringify(serverPool2)
};

azuresqldb = {
serviceName: 'azure-sqldb',
serviceId: 'fb9bc99e-0aa9-11e6-8a8a-000d3a002ed5',
planId: '3819fdfa-0aaa-11e6-86f4-000d3a002ed5',
instanceId: instanceId,
bindingId: bindingId,
instanceId: instanceId2,
bindingId: bindingId2,
provisioningParameters: {
'resourceGroup': resourceGroupName,
'resourceGroup': resourceGroupName2,
'location': location,
'sqlServerName': sqlServerName,
'sqlServerName': sqlServerName2,
'sqlServerParameters': {
'allowSqlServerFirewallRules': [
{
Expand All @@ -108,7 +218,7 @@ azuresqldb = {
},
'connectionPolicy': 'Proxy'
},
'sqldbName': sqldbName,
'sqldbName': sqldbName2,
'transparentDataEncryption': true,
'sqldbParameters': {
'properties': {
Expand All @@ -123,9 +233,9 @@ azuresqldb = {
credentials: {
'databaseLogin': '<string>',
'databaseLoginPassword': '<string>',
'sqlServerName': sqlServerName,
'sqlServerName': sqlServerName2,
'sqlServerFullyQualifiedDomainName': '<string>',
'sqldbName': sqldbName,
'sqldbName': sqldbName2,
'jdbcUrl': '<string>',
'jdbcUrlForAuditingEnabled': '<string>',
'hostname': '<string>',
Expand All @@ -135,7 +245,81 @@ azuresqldb = {
'password': '<string>',
'uri': '<string>'
},
e2e: true
e2e: true,
envVars: envVars2,
preProvision: function(callback) {
var opParams = {
'organization_guid': uuid.v4(),
'plan_id': '3819fdfa-0aaa-11e6-86f4-000d3a002ed5',
'service_id': 'fb9bc99e-0aa9-11e6-8a8a-000d3a002ed5',
'space_guid': uuid.v4(),
'privilege': {
'sqldb': {
'allowToCreateSqlServer': true
}
},
'accountPool': { 'sqldb': {} },
'parameters': {
'resourceGroup': resourceGroupName2,
'location': location,
'sqlServerName': sqlServerName2,
'sqlServerParameters': {
'allowSqlServerFirewallRules': [
{
'ruleName': 'test',
'startIpAddress': '0.0.0.0',
'endIpAddress': '255.255.255.255'
}
],
'properties': {
'administratorLogin': 'azureuser',
'administratorLoginPassword': 'c1oudc0w!@#'
}
},
'sqldbName': sqldbNamePre2,
'sqldbParameters': {
'properties': {
'collation': 'SQL_Latin1_General_CP1_CI_AS'
}
}
},
'azure': common.getConfigurations().azure
};
sqldb.provision(opParams, function(err) {
zhongyi-zhang marked this conversation as resolved.
Show resolved Hide resolved
if (err) return callback(err);

opParams.parameters.sqlServerName = sqlServerName2;
opParams.parameters.sqldbName = 'cf' + uuid.v4();
opParams.parameters.location = location;
sqldb.provision(opParams, function(err) {
if (err) return callback(err);
opParams.parameters.sqlServerName = sqlServerName2;
opParams.parameters.sqldbName = sqldbNamePre2;
opParams.parameters.location = location;
opParams.last_operation = 'provision';
opParams.provisioning_result = {
'resourceGroup': resourceGroupName2
};
opParams.defaultSettings = {sqldb: {transparentDataEncryption: false}};
var state;
async.whilst(
function() {
return (state !== 'succeeded');
},
function(cb) {
sqldb.poll(opParams, function(err, lastOp, result) {
if (err) return cb(err);
state = result.value.state;
cb(null);
});
},
function(err) {
callback(err);
}
);
});
});
}
};
testMatrix.push(azuresqldb);

Expand Down
Loading