File tree 4 files changed +34
-38
lines changed
AppSettingsPage/cards/Agents
TeamManagementPage/TeamDetailsWrapper/AgentOptionsPage
4 files changed +34
-38
lines changed Original file line number Diff line number Diff line change 1
1
import React , { useState , useEffect } from "react" ;
2
2
3
3
// @ts -ignore
4
- import constructErrorString from "utilities/yaml" ;
4
+ import { constructErrorString , agentOptionsToYaml } from "utilities/yaml" ;
5
5
import yaml from "js-yaml" ;
6
6
import paths from "router/paths" ;
7
7
@@ -26,7 +26,7 @@ const Agents = ({
26
26
const { ADMIN_TEAMS } = paths ;
27
27
28
28
const [ formData , setFormData ] = useState < any > ( {
29
- agentOptions : yaml . dump ( appConfig . agent_options ) || { } ,
29
+ agentOptions : agentOptionsToYaml ( appConfig . agent_options ) ,
30
30
} ) ;
31
31
32
32
const { agentOptions } = formData ;
Original file line number Diff line number Diff line change 1
1
import React , { useContext , useState } from "react" ;
2
2
import { useQuery } from "react-query" ;
3
3
import { useErrorHandler } from "react-error-boundary" ;
4
- import yaml from "js- yaml" ;
4
+ import { agentOptionsToYaml } from "utilities/ yaml" ;
5
5
6
6
import { NotificationContext } from "context/notification" ;
7
7
import { IApiError } from "interfaces/errors" ;
@@ -45,7 +45,7 @@ const AgentOptionsPage = ({
45
45
46
46
if ( selected ) {
47
47
setFormData ( {
48
- osquery_options : yaml . dump ( selected . agent_options ) ,
48
+ osquery_options : agentOptionsToYaml ( selected . agent_options ) ,
49
49
} ) ;
50
50
setTeamName ( selected . name ) ;
51
51
} else {
Original file line number Diff line number Diff line change @@ -199,38 +199,6 @@ export const formatConfigDataForServer = (config: any): any => {
199
199
} ;
200
200
} ;
201
201
202
- // TODO: Finalize interface for config - see frontend\interfaces\config.ts
203
- export const frontendFormattedConfig = ( config : IConfig ) => {
204
- const {
205
- org_info : orgInfo ,
206
- server_settings : serverSettings ,
207
- smtp_settings : smtpSettings ,
208
- sso_settings : ssoSettings ,
209
- host_expiry_settings : hostExpirySettings ,
210
- webhook_settings : { host_status_webhook : webhookSettings } , // unnested to frontend
211
- update_interval : updateInterval ,
212
- license,
213
- logging,
214
- } = config ;
215
-
216
- if ( config . agent_options ) {
217
- config . agent_options = yaml . dump ( config . agent_options ) ;
218
- }
219
-
220
- return {
221
- ...orgInfo ,
222
- ...serverSettings ,
223
- ...smtpSettings ,
224
- ...ssoSettings ,
225
- ...hostExpirySettings ,
226
- ...webhookSettings ,
227
- ...updateInterval ,
228
- ...license ,
229
- ...logging ,
230
- agent_options : config . agent_options ,
231
- } ;
232
- } ;
233
-
234
202
export const formatFloatAsPercentage = ( float : number ) : string => {
235
203
const formatter = Intl . NumberFormat ( "en-US" , {
236
204
maximumSignificantDigits : 2 ,
@@ -844,7 +812,6 @@ export default {
844
812
secondsToDhms,
845
813
labelSlug,
846
814
setupData,
847
- frontendFormattedConfig,
848
815
syntaxHighlight,
849
816
getValidatedTeamId,
850
817
normalizeEmptyValues,
Original file line number Diff line number Diff line change
1
+ import yaml from "js-yaml" ;
2
+
1
3
interface IYAMLError {
2
4
name : string ;
3
5
reason : string ;
4
6
line : string ;
5
7
}
6
8
7
- const constructErrorString = ( yamlError : IYAMLError ) => {
9
+ export const constructErrorString = ( yamlError : IYAMLError ) => {
8
10
return `${ yamlError . name } : ${ yamlError . reason } at line ${ yamlError . line } ` ;
9
11
} ;
10
12
13
+ export const agentOptionsToYaml = ( agentOpts : any ) => {
14
+ agentOpts ||= { } ;
15
+
16
+ // hide the "overrides" key if it is empty
17
+ if ( ! agentOpts . overrides || Object . keys ( agentOpts . overrides ) . length === 0 ) {
18
+ delete agentOpts . overrides ;
19
+ }
20
+
21
+ // add a comment besides the "command_line_flags" if it is empty
22
+ let addFlagsComment = false ;
23
+ if (
24
+ ! agentOpts . command_line_flags ||
25
+ Object . keys ( agentOpts . command_line_flags ) . length === 0
26
+ ) {
27
+ // delete it so it does not render, and will add it explicitly after (along with the comment)
28
+ delete agentOpts . command_line_flags ;
29
+ addFlagsComment = true ;
30
+ }
31
+
32
+ let yamlString = yaml . dump ( agentOpts ) ;
33
+ if ( addFlagsComment ) {
34
+ yamlString += "command_line_flags: {} # requires Orbit\n" ;
35
+ }
36
+
37
+ return yamlString ;
38
+ } ;
39
+
11
40
export default constructErrorString ;
You can’t perform that action at this time.
0 commit comments