Skip to content
Snippets Groups Projects
Commit 57f44a52 authored by Cam Saul's avatar Cam Saul
Browse files

auto infer SSL support during setup

parent fd07a93f
No related branches found
No related tags found
No related merge requests found
......@@ -14,9 +14,11 @@
<span class="Form-charm"></span>
</div>
<!-- Database Connection Info - Varies by Engine (details.*) -->
<!-- Database Connection Info Fields - Varies by Engine (details.*) -->
<div class="FormInputGroup">
<div class="Form-field" ng-repeat="field in ENGINES[database.engine].fields" mb-form-field="{{field.fieldName}}">
<!-- If the controller defines a delegate function shouldHideField() then we'll query that to determine whether each field should be shown
Otherwise we'll default to showing every field. This way we can hide 'advanced options' like SSL during the setup process -->
<div class="Form-field" ng-repeat="field in ENGINES[database.engine].fields" mb-form-field="{{field.fieldName}}" ng-if="!shouldHideField(field)">
<mb-form-label display-name="{{field.displayName}}" field-name="{{field.fieldName}}"></mb-form-label>
<!-- Multiple-Choice Field -->
<div ng-if="field.choices" class="Form-input Form-offset full Button-group">
......
......@@ -87,8 +87,15 @@ SetupControllers.controller('SetupConnection', ['$scope', '$routeParams', '$loca
var newConnection = true;
$scope.breadcrumb = 'Add connection';
// hide the SSL field when creating a new DB until we auto-infer SSL support
var hideSSLField = true;
$scope.shouldHideField = function(field) {
return field.fieldName === 'ssl' ? hideSSLField : false;
};
if ($routeParams.dbId) {
newConnection = false;
hideSSLField = false;
Metabase.db_get({
'dbId': $routeParams.dbId
}, function(result) {
......@@ -114,44 +121,66 @@ SetupControllers.controller('SetupConnection', ['$scope', '$routeParams', '$loca
$scope.database.engine = engine;
};
// Call API to determine whether connection is valid. If so, save the DB.
$scope.submit = function() {
var engine = $scope.database.engine,
database = {
org: $scope.currentOrg.id,
name: $scope.database.name,
engine: engine,
details: $scope.ENGINES[engine].buildDetails($scope.details)
};
function success(result) {
$location.path('/setup/data');
}
function error(err) {
$scope.error = err;
console.log('error', err);
}
// api needs a int
// API expects 'port' to be an int
if ($scope.details.port) {
$scope.details.port = parseInt($scope.details.port);
}
// Validate the connection string. Add engine to the request body
// add engine to the request body
$scope.details.engine = $scope.database.engine;
Metabase.validate_connection($scope.details, function(result) {
if (newConnection) {
Metabase.db_create(database, success, error);
} else {
// add the id since we're updating
database.id = $scope.database.id;
Metabase.db_update(database, success, error);
}
}, function(error) {
function validateConnectionDetails(onConnectionValidationFailed) {
console.log('attempting to connect with SSL set to: ', $scope.details.ssl);
Metabase.validate_connection($scope.details, function() {
// Connection valid, save the DB
console.log('connection successful.');
var engine = $scope.database.engine,
database = {
org: $scope.currentOrg.id,
name: $scope.database.name,
engine: engine,
details: $scope.ENGINES[engine].buildDetails($scope.details)
};
function onCreateOrUpdateDBSuccess(result) {
$location.path('/setup/data');
}
function onCreateOrUpdateDBError(err) {
$scope.error = err;
console.log('error', err);
}
if (newConnection) {
Metabase.db_create(database, onCreateOrUpdateDBSuccess, onCreateOrUpdateDBError);
} else {
// add the id since we're updating
database.id = $scope.database.id;
Metabase.db_update(database, onCreateOrUpdateDBSuccess, onCreateOrUpdateDBError);
}
}, onConnectionValidationFailed);
}
function displayConnectionValidationError(error) {
console.log(error);
$scope.error = "Invalid Connection String - " + error.data.message;
});
};
// now perform the connection validation
if (newConnection) {
// if this is a new connection we'll try SSL first and if that fails we'll retry without it
$scope.details.ssl = true;
validateConnectionDetails(function(error) {
// try again without SSL
$scope.details.ssl = false;
validateConnectionDetails(displayConnectionValidationError);
});
} else {
validateConnectionDetails(displayConnectionValidationError);
}
};
}]);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment