mirror of
https://github.com/fleetdm/fleet
synced 2026-05-11 03:00:58 +00:00
* Skeleton UI * Rebase to main * Work towards config API request modification * Nest and unnest when formatting for server and frontend * Changelog * Add validation to UI, fix ? vertical spacing * Rebase e2e * 1 of 2 passing unit tests for config * Update REST-API.md to include webhook_settings * Destructure / flatten config webhook in unit test * Merge advance options e2e conflict * x and y example not x and x * Fix observer e2e * Add new data to read only example request Co-authored-by: Noah Talerman <[email protected]> Co-authored-by: Martavis Parker <[email protected]>
109 lines
2.7 KiB
JavaScript
109 lines
2.7 KiB
JavaScript
import { size } from "lodash";
|
|
import validateYaml from "components/forms/validators/validate_yaml";
|
|
import constructErrorString from "utilities/yaml";
|
|
|
|
export default (formData) => {
|
|
const errors = {};
|
|
const {
|
|
authentication_type: authType,
|
|
server_url: kolideServerUrl,
|
|
org_name: orgName,
|
|
enable_smtp: enableSMTP,
|
|
password: smtpPassword,
|
|
sender_address: smtpSenderAddress,
|
|
server: smtpServer,
|
|
port: smtpServerPort,
|
|
user_name: smtpUserName,
|
|
enable_sso: enableSSO,
|
|
metadata,
|
|
metadata_url: metadataURL,
|
|
entity_id: entityID,
|
|
idp_name: idpName,
|
|
host_expiry_enabled: hostExpiryEnabled,
|
|
host_expiry_window: hostExpiryWindow = 0,
|
|
agent_options: agentOptions,
|
|
enable_host_status_webhook: enableHostStatusWebhook,
|
|
destination_url: destinationUrl,
|
|
host_percentage: hostPercentage,
|
|
days_count: daysCount,
|
|
} = formData;
|
|
|
|
if (enableSSO) {
|
|
if (!metadata && !metadataURL) {
|
|
errors.metadata_url = "Metadata URL must be present";
|
|
}
|
|
if (!entityID) {
|
|
errors.entity_id = "Entity ID must be present";
|
|
}
|
|
if (!idpName) {
|
|
errors.idp_name = "Identity Provider Name must be present";
|
|
}
|
|
}
|
|
|
|
if (!kolideServerUrl) {
|
|
errors.server_url = "Fleet Server URL must be present";
|
|
}
|
|
|
|
if (!orgName) {
|
|
errors.org_name = "Organization Name must be present";
|
|
}
|
|
|
|
if (enableSMTP) {
|
|
if (!smtpSenderAddress) {
|
|
errors.sender_address = "SMTP Sender Address must be present";
|
|
}
|
|
|
|
if (!smtpServer) {
|
|
errors.server = "SMTP Server must be present";
|
|
}
|
|
|
|
if (!smtpServerPort) {
|
|
errors.server = "SMTP Server Port must be present";
|
|
}
|
|
|
|
if (authType !== "authtype_none") {
|
|
if (!smtpUserName) {
|
|
errors.user_name = "SMTP Username must be present";
|
|
}
|
|
|
|
if (!smtpPassword) {
|
|
errors.password = "SMTP Password must be present";
|
|
}
|
|
}
|
|
}
|
|
|
|
if (enableHostStatusWebhook) {
|
|
if (!destinationUrl) {
|
|
errors.destination_url = "Destination URL must be present";
|
|
}
|
|
|
|
if (!hostPercentage) {
|
|
errors.host_percentage = "Host percentage must be present";
|
|
}
|
|
|
|
if (!daysCount) {
|
|
errors.days_count = "Days count must be present";
|
|
}
|
|
}
|
|
|
|
if (hostExpiryEnabled) {
|
|
if (isNaN(hostExpiryWindow) || Number(hostExpiryWindow) <= 0) {
|
|
errors.host_expiry_window =
|
|
"Host Expiry Window must be a positive number";
|
|
}
|
|
}
|
|
|
|
if (agentOptions) {
|
|
const { error: yamlError, valid: yamlValid } = validateYaml(
|
|
formData.agent_options
|
|
);
|
|
|
|
if (!yamlValid) {
|
|
errors.agent_options = constructErrorString(yamlError);
|
|
}
|
|
}
|
|
|
|
const valid = !size(errors);
|
|
|
|
return { valid, errors };
|
|
};
|