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

ADDON-34273: globalConfig.json parsing and validation #111

Merged
Show file tree
Hide file tree
Changes from 4 commits
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
4 changes: 3 additions & 1 deletion splunk_add_on_ucc_framework/ucc_ui_lib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@
"stylelint": "^13.0.0",
"webpack": "^4.16.2",
"webpack-cli": "^3.1.0",
"webpack-merge": "^4.1.3"
"webpack-merge": "^4.1.3",
"jsonschema": "^1.4.0",
"underscore": "^1.12.0"
},
"engines": {
"node": ">=6"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import React, { useState } from 'react';
import Button from '@splunk/react-ui/Button';
import Modal from '@splunk/react-ui/Modal';
import Message from '@splunk/react-ui/Message';

import {getFormattedMessage} from '../util/messageUtil';

function ErrorModal(props) {

const [open, setOpen] = useState(props.open);

const handleRequestClose = () => {
setOpen(false);
};

return (
<Modal
onRequestClose={handleRequestClose}
open={open}
style={{ width: '600px' }}
>
<Modal.Header
onRequestClose={handleRequestClose}
title={getFormattedMessage(104)}
/>
<Modal.Body>
<Message appearance="fill" type="error">
{props.message}
</Message>
</Modal.Body>
<Modal.Footer>
<Button appearance="primary" onClick={handleRequestClose} label="OK" />
</Modal.Footer>
</Modal>
);
}

export default ErrorModal;
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, { Component } from 'react';
import PropTypes from 'prop-types';
import Button from '@splunk/react-ui/Button';
import { StyledContainer, StyledGreeting } from './TestComponentStyles';
import { getUnifiedConfigs } from '../util/util';

class TestComponent extends Component {
static propTypes = {
Expand All @@ -17,6 +18,10 @@ class TestComponent extends Component {
this.state = { counter: 0 };
}

componentDidMount() {
console.log("getUnifiedConfigs: ", getUnifiedConfigs());
}

render() {
const { name } = this.props;
const { counter } = this.state;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
export default {
/* validation messages, range [0, 99] */
0: 'Field {{args[0]}} is required',
1: 'Field {{args[0]}} must be a string',
2: '{{args[0]}} {{args[1]}} is already in use',
3: '"default", ".", "..", string started with "_" and string including any one of ["*", "\\", "[", "]", "(", ")", "?", ":"] are reserved value which cannot be used for field {{args[0]}}',
5: 'Field {{args[0]}} should be a positive number',
6: 'Field {{args[0]}} is required',
7: 'Field {{args[0]}} is not a valid regular expression',
8: 'Field {{args[0]}} should be within the range of [{{args[1]}} and {{args[2]}}]',
9: 'Field {{args[0]}} should be greater than or equal to {{args[1]}}',
10: 'Field {{args[0]}} should be less than or equal to {{args[1]}}',
11: '{{args[0]}} is not a function',
12: '{{args[0]}} is not a valid regular expression',
13: '{{args[0]}} is not a valid number range',
14: 'minLength cannot be greater than maxLength',
15: 'Field {{args[0]}} does not match regular expression {{args[1]}}',
16: 'Field {{args[0]}} is not a number',
17: 'Length of {{args[0]}} should be greater than or equal to {{args[1]}}',
18: 'Length of {{args[0]}} should be less than or equal to {{args[1]}}',
19: 'Field {{args[0]}} is not a valid {{args[1]}}',
20: 'configuration file should be pure JSON',
21: 'duplicate {{args[0]}} keys is not allowed',
22: 'Field {{args[0]}} must be less than 1024 characters',
23: '"name" feild must be provided for {{args[0]}} \'s entity in configuration file',

/* general messages, range [100, 499]*/
100: 'Create New Input',
// Delete dialog title
101: 'Delete Confirmation',
102: 'Are you sure you want to delete "{{args[0]}}" {{args[1]}}? Ensure that no input is configured with "{{args[0]}}" as this will stop data collection for that input.',
103: 'Are you sure you want to delete "{{args[0]}}" {{args[1]}}?',
// Error dialog title
104: 'Error Message',
// Warning dialog title
105: 'Warning',
// Input table filter label
106: 'Input Type',
// Configuration table count label
107: 'Items',
// Saving prompt message
108: 'Saving',
// Loading index error message
109: 'Failed to load index',
// Configuration file error
110: 'Internal configuration file error. Something wrong within the package or installation step. Contact your administrator for support. Detail: {{args[0]}}',
111: 'URL',
112: 'email address',
113: 'IPV4 address',
114: 'date in ISO 8601 format',
115: 'Loading',
// Page title
116: 'Inputs',
117: 'Configuration',

'__unknow__': 'An unknown error occurred'
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { SplunkThemeProvider } from '@splunk/themes';

import { defaultTheme } from '@splunk/splunk-utils/themes';

import ConfigManager from '../util/configManager';
import TestComponent from '../components/TestComponent';
import { StyledContainer, StyledGreeting } from './StartStyles';

Expand Down Expand Up @@ -38,9 +39,16 @@ if (page === 'inputs') {
layout(
<SplunkThemeProvider {...themeProviderSettings}>
<StyledContainer>
<StyledGreeting>Hello, from inside Inputs!</StyledGreeting>
<div>Your component will appear below.</div>
<TestComponent name="from inside TestComponent" />
<ConfigManager>
{({loading, appData}) => {
return !loading && appData && (
<>
<StyledGreeting>Hello, from inside Inputs!</StyledGreeting>
<TestComponent name="from inside TestComponent" />
</>
)
}}
</ConfigManager>
</StyledContainer>
</SplunkThemeProvider>,
{ pageTitle: 'Inputs' }
Expand All @@ -49,9 +57,16 @@ if (page === 'inputs') {
layout(
<SplunkThemeProvider {...themeProviderSettings}>
<StyledContainer>
<StyledGreeting>Hello, from inside Configuration!</StyledGreeting>
<div>Your component will appear below.</div>
<TestComponent name="from inside TestComponent" />
<ConfigManager>
{({loading, appData}) => {
return !loading && appData && (
<>
<StyledGreeting>Hello, from inside Configuration!</StyledGreeting>
<TestComponent name="from inside TestComponent" />
</>
)
}}
</ConfigManager>
</StyledContainer>
</SplunkThemeProvider>,
{ pageTitle: 'Configuration' }
Expand Down
Loading