mirror of
https://github.com/fleetdm/fleet
synced 2026-05-23 08:58:41 +00:00
Hide overrides key if empty, display comment for flags if empty (#7986)
This commit is contained in:
parent
812d3c85de
commit
f5b6523359
4 changed files with 34 additions and 38 deletions
|
|
@ -1,7 +1,7 @@
|
|||
import React, { useState, useEffect } from "react";
|
||||
|
||||
// @ts-ignore
|
||||
import constructErrorString from "utilities/yaml";
|
||||
import { constructErrorString, agentOptionsToYaml } from "utilities/yaml";
|
||||
import yaml from "js-yaml";
|
||||
import paths from "router/paths";
|
||||
|
||||
|
|
@ -26,7 +26,7 @@ const Agents = ({
|
|||
const { ADMIN_TEAMS } = paths;
|
||||
|
||||
const [formData, setFormData] = useState<any>({
|
||||
agentOptions: yaml.dump(appConfig.agent_options) || {},
|
||||
agentOptions: agentOptionsToYaml(appConfig.agent_options),
|
||||
});
|
||||
|
||||
const { agentOptions } = formData;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import React, { useContext, useState } from "react";
|
||||
import { useQuery } from "react-query";
|
||||
import { useErrorHandler } from "react-error-boundary";
|
||||
import yaml from "js-yaml";
|
||||
import { agentOptionsToYaml } from "utilities/yaml";
|
||||
|
||||
import { NotificationContext } from "context/notification";
|
||||
import { IApiError } from "interfaces/errors";
|
||||
|
|
@ -45,7 +45,7 @@ const AgentOptionsPage = ({
|
|||
|
||||
if (selected) {
|
||||
setFormData({
|
||||
osquery_options: yaml.dump(selected.agent_options),
|
||||
osquery_options: agentOptionsToYaml(selected.agent_options),
|
||||
});
|
||||
setTeamName(selected.name);
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -199,38 +199,6 @@ export const formatConfigDataForServer = (config: any): any => {
|
|||
};
|
||||
};
|
||||
|
||||
// TODO: Finalize interface for config - see frontend\interfaces\config.ts
|
||||
export const frontendFormattedConfig = (config: IConfig) => {
|
||||
const {
|
||||
org_info: orgInfo,
|
||||
server_settings: serverSettings,
|
||||
smtp_settings: smtpSettings,
|
||||
sso_settings: ssoSettings,
|
||||
host_expiry_settings: hostExpirySettings,
|
||||
webhook_settings: { host_status_webhook: webhookSettings }, // unnested to frontend
|
||||
update_interval: updateInterval,
|
||||
license,
|
||||
logging,
|
||||
} = config;
|
||||
|
||||
if (config.agent_options) {
|
||||
config.agent_options = yaml.dump(config.agent_options);
|
||||
}
|
||||
|
||||
return {
|
||||
...orgInfo,
|
||||
...serverSettings,
|
||||
...smtpSettings,
|
||||
...ssoSettings,
|
||||
...hostExpirySettings,
|
||||
...webhookSettings,
|
||||
...updateInterval,
|
||||
...license,
|
||||
...logging,
|
||||
agent_options: config.agent_options,
|
||||
};
|
||||
};
|
||||
|
||||
export const formatFloatAsPercentage = (float: number): string => {
|
||||
const formatter = Intl.NumberFormat("en-US", {
|
||||
maximumSignificantDigits: 2,
|
||||
|
|
@ -844,7 +812,6 @@ export default {
|
|||
secondsToDhms,
|
||||
labelSlug,
|
||||
setupData,
|
||||
frontendFormattedConfig,
|
||||
syntaxHighlight,
|
||||
getValidatedTeamId,
|
||||
normalizeEmptyValues,
|
||||
|
|
|
|||
|
|
@ -1,11 +1,40 @@
|
|||
import yaml from "js-yaml";
|
||||
|
||||
interface IYAMLError {
|
||||
name: string;
|
||||
reason: string;
|
||||
line: string;
|
||||
}
|
||||
|
||||
const constructErrorString = (yamlError: IYAMLError) => {
|
||||
export const constructErrorString = (yamlError: IYAMLError) => {
|
||||
return `${yamlError.name}: ${yamlError.reason} at line ${yamlError.line}`;
|
||||
};
|
||||
|
||||
export const agentOptionsToYaml = (agentOpts: any) => {
|
||||
agentOpts ||= {};
|
||||
|
||||
// hide the "overrides" key if it is empty
|
||||
if (!agentOpts.overrides || Object.keys(agentOpts.overrides).length === 0) {
|
||||
delete agentOpts.overrides;
|
||||
}
|
||||
|
||||
// add a comment besides the "command_line_flags" if it is empty
|
||||
let addFlagsComment = false;
|
||||
if (
|
||||
!agentOpts.command_line_flags ||
|
||||
Object.keys(agentOpts.command_line_flags).length === 0
|
||||
) {
|
||||
// delete it so it does not render, and will add it explicitly after (along with the comment)
|
||||
delete agentOpts.command_line_flags;
|
||||
addFlagsComment = true;
|
||||
}
|
||||
|
||||
let yamlString = yaml.dump(agentOpts);
|
||||
if (addFlagsComment) {
|
||||
yamlString += "command_line_flags: {} # requires Orbit\n";
|
||||
}
|
||||
|
||||
return yamlString;
|
||||
};
|
||||
|
||||
export default constructErrorString;
|
||||
|
|
|
|||
Loading…
Reference in a new issue