Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue/1192 garden connection buttons #4

Draft
wants to merge 7 commits into
base: garden_connection_config_feature
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
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
14 changes: 5 additions & 9 deletions src/app/beer_garden/db/schemas/garden_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,13 @@ class GardenBaseSchema(Schema):
def validate_all_keys(self, post_load_data, original_data, **kwargs):
# do not allow extraneous keys when operating on a dictionary
if isinstance(original_data, dict):
extra_args = original_data.keys() - post_load_data.keys()

extra_args = post_load_data.keys() - original_data.keys()
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes made here in this commit are not actually related to any work in adding the buttons. But because this line was backwards, this code was firing and it revealed that the error messages were uninterpretable.

if len(extra_args) > 0:
formatted_good_keys = ", ".join(
map(lambda x: "'" + str(x) + "'", self.fields.keys())
)
formatted_bad_keys = ", ".join(
map(lambda x: "'" + str(x) + "'", extra_args)
)
formatted_good_keys = ", ".join(self.fields.keys())
formatted_bad_keys = ", ".join(extra_args)

raise ValidationError(
f"Only {formatted_good_keys} allowed as keys; "
f"Only {formatted_good_keys} allowed as keys - "
f"these are not allowed: {formatted_bad_keys}"
)

Expand Down
2 changes: 1 addition & 1 deletion src/ui/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"es6": true
},
"parserOptions": {
"ecmaVersion": 6,
"ecmaVersion": 2018,
Copy link
Owner Author

@jlrpnbbngtn jlrpnbbngtn Jan 18, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't really matter what this is set to, as long as it's set to something sensible. ecmaVersion 2018 is very nearly ecmaVersion 6. It just adds a few constructs that are more modern. In any case, babel compiles to the same version of JavaScript regardless of this setting. This is only to tell eslint which version to try to parse.

"sourceType": "module"
}
}
10 changes: 5 additions & 5 deletions src/ui/src/js/configs/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default function routeConfig(
$stateProvider,
$urlRouterProvider,
$urlMatcherFactoryProvider,
$locationProvider
$locationProvider,
) {
$urlRouterProvider.otherwise('/');
$urlMatcherFactoryProvider.strictMode(false);
Expand Down Expand Up @@ -60,7 +60,7 @@ export default function routeConfig(
(response) => {
$rootScope.sysResponse = response;
$rootScope.systems = [];
}
},
);
},
],
Expand Down Expand Up @@ -93,7 +93,7 @@ export default function routeConfig(
SystemService.findSystem(
$stateParams.namespace,
$stateParams.systemName,
$stateParams.systemVersion
$stateParams.systemVersion,
) || {}
);
},
Expand Down Expand Up @@ -126,7 +126,7 @@ export default function routeConfig(
return (
SystemService.findSystem(
$stateParams.namespace,
$stateParams.systemName
$stateParams.systemName,
) || {}
);
},
Expand Down Expand Up @@ -157,7 +157,7 @@ export default function routeConfig(
return SystemService.findSystem(
$stateParams.namespace,
$stateParams.systemName,
$stateParams.systemVersion
$stateParams.systemVersion,
);
},
],
Expand Down
4 changes: 2 additions & 2 deletions src/ui/src/js/controllers/admin_garden.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default function adminGardenController(
$scope,
$state,
GardenService,
EventService
EventService,
) {
$scope.setWindowTitle('gardens');
$scope.gardenCreateSchema = GardenService.CreateSCHEMA;
Expand All @@ -43,7 +43,7 @@ export default function adminGardenController(
const loadGardens = function() {
GardenService.getGardens().then(
$scope.successCallback,
$scope.failureCallback
$scope.failureCallback,
);
};

Expand Down
142 changes: 122 additions & 20 deletions src/ui/src/js/controllers/admin_garden_view.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// eslint-disable-next-line no-unused-vars
import angular from 'angular';
import _ from 'lodash';

adminGardenViewController.$inject = [
Expand All @@ -9,19 +11,20 @@ adminGardenViewController.$inject = [

/**
* adminGardenController - Garden management controller.
* @param {Object} $scope Angular's $scope object.
* @param {Object} GardenService Beer-Garden's garden service object.
* @param {Object} EventService Beer-Garden's event service object.
* @param {$stateParams} $stateParams State params
* @param {Object} $scope Angular's $scope object.
* @param {Object} GardenService Beer-Garden's garden service object.
* @param {Object} EventService Beer-Garden's event service object.
* @param {$stateParams} $stateParams Router state params
*/
export default function adminGardenViewController(
$scope,
GardenService,
EventService,
$stateParams
$stateParams,
) {
$scope.setWindowTitle('Configure Garden');
$scope.alerts = [];
$scope.formErrors = [];

$scope.isLocal = false;
$scope.gardenSchema = null;
Expand All @@ -41,14 +44,16 @@ export default function adminGardenViewController(
};

$scope.successCallback = function(response) {
console.log('response', response);
$scope.response = response;
$scope.data = response.data;

if ($scope.data.id == null || $scope.data.connection_type == 'LOCAL') {
$scope.isLocal = true;
$scope.alerts.push({
type: 'info',
msg: 'Since this is the local Garden it\'s not possible to modify connection information',
msg: 'Since this is the local Garden it\'s not possible to modify ' +
'connection information',
});
}

Expand All @@ -63,7 +68,7 @@ export default function adminGardenViewController(
const loadGarden = function() {
GardenService.getGarden($stateParams.name).then(
$scope.successCallback,
$scope.failureCallback
$scope.failureCallback,
);
};

Expand All @@ -74,28 +79,125 @@ export default function adminGardenViewController(
loadGarden();
};

const errorPlaceholder = 'errorPlaceholder';

const resetAllValidationErrors = () => {
const updater = (field) => {
$scope.$broadcast(
`schemaForm.error.${field}`,
errorPlaceholder,
true,
);
};

// this is brittle because it's a copy/paste from the form code,
// but will suffice for now because we expect the form won't
// ever be updated in this version of the UI
const httpFlds = [
'http.host',
'http.port',
'http.url_prefix',
'http.ssl',
'http.ca_cert',
'http.ca_verify',
'http.client_cert',
];
const stompFlds = [
'stomp.host',
'stomp.port',
'stomp.send_destination',
'stomp.subscribe_destination',
'stomp.username',
'stomp.password',
'stomp.ssl',
'stomp.headers',
];

httpFlds.map(updater);
stompFlds.map(updater);
};

const fieldErrorName =
(entryPoint, fieldName) => `schemaForm.error.${entryPoint}.${fieldName}`;

const fieldErrorMessage =
(errorObject) =>
typeof errorObject === 'string' ? Array(errorObject) : errorObject;

const updateValidationMessages = (entryPoint, errorsObject) => {
for (const fieldName in errorsObject) {
if (errorsObject.hasOwnProperty(fieldName)) {
$scope.$broadcast(
fieldErrorName(entryPoint, fieldName),
errorPlaceholder,
fieldErrorMessage(errorsObject[fieldName]),
);
}
}
};

$scope.addErrorAlert = function(response) {
$scope.alerts.push({
type: 'danger',
msg:
'Something went wrong on the backend: ' +
_.get(response, 'data.message', 'Please check the server logs'),
});
/* If we have an error response that indicates that the connection
* parameters are incorrect, display a warning alert specifying which of the
* entry points are wrong. Then update the validation of the individual
* schema fields.
*/
if (response['data'] && response['data']['message']) {
const messageData = String(response['data']['message']);
console.log('MESSG', messageData, 'TYPE', typeof messageData);
const cleanedMessages = messageData.replace(/'/g, '"');
const messages = JSON.parse(cleanedMessages);

if ('connection_params' in messages) {
const connParamErrors = messages['connection_params'];

for (const entryPoint in connParamErrors) {
if (connParamErrors.hasOwnProperty(entryPoint)) {
updateValidationMessages(entryPoint, connParamErrors[entryPoint]);

$scope.alerts.push({
type: 'warning',
msg: `Errors found in ${entryPoint} connection`,
});
}
}
}
} else {
$scope.alerts.push({
type: 'danger',
msg: 'Something went wrong on the backend: ' +
_.get(response, 'data.message', 'Please check the server logs'),
});
}
};

$scope.submitGardenForm = function(form, model) {
$scope.alerts = [];
resetAllValidationErrors();
$scope.$broadcast('schemaFormValidate');

if (form.$valid) {
const updatedGarden = GardenService.formToServerModel($scope.data, model);

GardenService.updateGardenConfig(updatedGarden).then(
_.noop,
$scope.addErrorAlert
);
let updatedGarden = undefined;

try {
updatedGarden =
GardenService.formToServerModel($scope.data, model);
} catch (e) {
$scope.alerts.push({
type: 'warning',
msg: e,
});
}

if (updatedGarden) {
GardenService.updateGardenConfig(updatedGarden).then(
_.noop,
$scope.addErrorAlert,
);
}
} else {
$scope.alerts.push(
'Looks like there was an error validating the Garden.'
'There was an error validating the Garden.',
);
}
};
Expand Down
Loading