mirror of
https://github.com/fleetdm/fleet
synced 2026-05-08 09:40:49 +00:00
* #511 refactored update options - new params & ts * updated server to include agent_options for read and update * added agent options form to org settings * #511 finished connecting agent form to server * #511 fixing api to save/read agent options * #511 linted * #511 fixed reading & updating agent options * #511 api fixes to support agent options * #511 removed log * Fix json.RawMessage pointers in tests Co-authored-by: Zach Wasserman <[email protected]>
91 lines
2.2 KiB
JavaScript
91 lines
2.2 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,
|
|
} = 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 (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 };
|
|
};
|