From 114fe586b3d580d7e840569f8c5e1815da755343 Mon Sep 17 00:00:00 2001 From: Dan Hunt Date: Tue, 26 Oct 2021 11:04:58 -0400 Subject: [PATCH] updated to support json input; aws ca bundle; hiding columns: --- app/clients/aws.js | 51 +++++++++-- app/components/CreationForm.js | 69 +++++++++++---- app/components/Home.js | 141 ++++++++++++++++++++----------- app/components/SettingsButton.js | 69 ++++++++++++++- app/ducks/parameters.js | 77 +++++++++-------- app/store/localStore.js | 27 +++++- app/utils/valueIsJson.js | 18 ++++ babel.config.js | 3 +- package.json | 3 +- yarn.lock | 32 ++++++- 10 files changed, 373 insertions(+), 117 deletions(-) create mode 100644 app/utils/valueIsJson.js diff --git a/app/clients/aws.js b/app/clients/aws.js index 905c3cd..08f3601 100644 --- a/app/clients/aws.js +++ b/app/clients/aws.js @@ -1,5 +1,7 @@ import AWS from 'aws-sdk'; -import localStore from '../store/localStore'; +import { Agent as httpsAgent } from 'https'; +import { readFileSync as fsReadFileSync } from 'fs'; +import localStore, { availableSettings } from '../store/localStore'; process.env.AWS_SDK_LOAD_CONFIG = true; @@ -7,18 +9,49 @@ const credentialProvider = new AWS.CredentialProviderChain([ () => new AWS.EnvironmentCredentials('AWS'), () => new AWS.EnvironmentCredentials('AMAZON'), () => - new AWS.SharedIniFileCredentials({ profile: localStore.get('profile') }), - () => new AWS.ProcessCredentials({ profile: localStore.get('profile') }) + new AWS.SharedIniFileCredentials({ + profile: localStore.get(availableSettings.profile) + }), + () => + new AWS.ProcessCredentials({ + profile: localStore.get(availableSettings.profile) + }) // TODO: Add more credential providers as needed. https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/CredentialProviderChain.html#providers-property ]); -const ssm = region => - new AWS.SSM({ region, credentials: null, credentialProvider }); -const kms = region => - new AWS.KMS({ region, credentials: null, credentialProvider }); +const caBundlePath = localStore.get(availableSettings.caBundlePath); + +const ssm = region => { + const awsConfig: AWS.SSM.ClientConfiguration = { + region, + credentials: null, + credentialProvider + }; + if (caBundlePath) { + awsConfig.httpOptions = { + // eslint-disable-next-line new-cap + agent: new httpsAgent({ ca: fsReadFileSync(caBundlePath) }) + }; + } + return new AWS.SSM(awsConfig); +}; +const kms = region => { + const awsConfig: AWS.KMS.ClientConfiguration = { + region, + credentials: null, + credentialProvider + }; + if (caBundlePath) { + awsConfig.httpOptions = { + // eslint-disable-next-line new-cap + agent: new httpsAgent({ ca: fsReadFileSync(caBundlePath) }) + }; + } + return new AWS.KMS(awsConfig); +}; -const getSSM = () => ssm(localStore.get('ssmRegion')); -const getKMS = () => kms(localStore.get('kmsRegion')); +const getSSM = () => ssm(localStore.get(availableSettings.ssmRegion)); +const getKMS = () => kms(localStore.get(availableSettings.kmsRegion)); export default { getSSM, diff --git a/app/components/CreationForm.js b/app/components/CreationForm.js index d974eb0..4e016e1 100644 --- a/app/components/CreationForm.js +++ b/app/components/CreationForm.js @@ -14,11 +14,14 @@ import { import { bindActionCreators } from 'redux'; import { connect } from 'react-redux'; +import JSONInput from 'react-json-editor-ajrm'; +import locale from 'react-json-editor-ajrm/locale/en'; import { formShape, formDataShape } from './formDataShape.propType'; import { actions as parameterActions, selectors as parameterSelectors } from '../ducks/parameters'; +import { valueIsJson } from '../utils/valueIsJson'; const { Option } = Select; const { TextArea } = Input; @@ -79,6 +82,8 @@ class CreationForm extends React.Component { } = this.props; const { validateFields } = form; validateFields((validationErr, values) => { + const params = values; + params.value = values.value.json || values.value; // handle json editor if (!validationErr) { const { creationType } = this.state; const creationFn = @@ -86,7 +91,7 @@ class CreationForm extends React.Component { ? createServiceParameters : createGenericParameter; this.setState({ creationState: ENTITY_STATUS.loading }); - creationFn(values, !!editFlow) + creationFn(params, !!editFlow) .then(res => { notification.success({ message: editFlow @@ -113,6 +118,21 @@ class CreationForm extends React.Component { this.setState({ creationType: e.target.value }); }; + validateValue = async (rule, value, callback) => { + if (!value || !value.plainText || !value.plainText.length === 0) { + return callback('Value is required'); + } + if (value.error && value.error.reason) { + return callback(value.error.reason); + } + if (value.plainText.length > 4096) { + return callback( + 'The maximum allowed size of 4096 characters (assuming all chars are one byte).' + ); + } + return callback(); + }; + render() { const { form, @@ -130,6 +150,8 @@ class CreationForm extends React.Component { wrapperCol: { span: 14 } }; + let useJsonInput = valueIsJson(initialFormData.value); + return (
{!editFlow && ( @@ -247,8 +269,8 @@ class CreationForm extends React.Component { String SecureString - - StringList (Not supported yet) + + StringList (comma separated string, no spaces) )} @@ -285,19 +307,34 @@ class CreationForm extends React.Component { )} )} - - {getFieldDecorator('value', { - initialValue: initialFormData.value, - rules: [ - { required: true, message: 'Please provide the value.' }, - { - max: 4096, - message: 'The maximum allowed length is 4096 characters.' - } - ] - })(