Correctly pass along allowed IPs for client API keys, closes #2244

This commit is contained in:
Dane Everitt 2020-08-17 19:48:51 -07:00
parent a6cc53793d
commit d41b86f0ea
No known key found for this signature in database
GPG Key ID: EEA66103B3D71F53
2 changed files with 15 additions and 5 deletions

View File

@ -17,4 +17,14 @@ class StoreApiKeyRequest extends ClientApiRequest
'allowed_ips.*' => 'ip', 'allowed_ips.*' => 'ip',
]; ];
} }
/**
* @return array|string[]
*/
public function messages()
{
return [
'allowed_ips.*' => 'All of the IP addresses entered must be valid IPv4 addresses.',
];
}
} }

View File

@ -12,12 +12,15 @@ import { ApiKey } from '@/api/account/getApiKeys';
import tw from 'twin.macro'; import tw from 'twin.macro';
import Button from '@/components/elements/Button'; import Button from '@/components/elements/Button';
import Input, { Textarea } from '@/components/elements/Input'; import Input, { Textarea } from '@/components/elements/Input';
import styled from 'styled-components/macro';
interface Values { interface Values {
description: string; description: string;
allowedIps: string; allowedIps: string;
} }
const CustomTextarea = styled(Textarea)`${tw`h-32`}`;
export default ({ onKeyCreated }: { onKeyCreated: (key: ApiKey) => void }) => { export default ({ onKeyCreated }: { onKeyCreated: (key: ApiKey) => void }) => {
const [ apiKey, setApiKey ] = useState(''); const [ apiKey, setApiKey ] = useState('');
const { addError, clearFlashes } = useStoreActions((actions: Actions<ApplicationStore>) => actions.flashes); const { addError, clearFlashes } = useStoreActions((actions: Actions<ApplicationStore>) => actions.flashes);
@ -66,10 +69,7 @@ export default ({ onKeyCreated }: { onKeyCreated: (key: ApiKey) => void }) => {
</Modal> </Modal>
<Formik <Formik
onSubmit={submit} onSubmit={submit}
initialValues={{ initialValues={{ description: '', allowedIps: '' }}
description: '',
allowedIps: '',
}}
validationSchema={object().shape({ validationSchema={object().shape({
allowedIps: string(), allowedIps: string(),
description: string().required().min(4), description: string().required().min(4),
@ -91,7 +91,7 @@ export default ({ onKeyCreated }: { onKeyCreated: (key: ApiKey) => void }) => {
name={'allowedIps'} name={'allowedIps'}
description={'Leave blank to allow any IP address to use this API key, otherwise provide each IP address on a new line.'} description={'Leave blank to allow any IP address to use this API key, otherwise provide each IP address on a new line.'}
> >
<Field as={Textarea} name={'allowedIps'} css={tw`h-32`}/> <Field name={'allowedIps'} as={CustomTextarea}/>
</FormikFieldWrapper> </FormikFieldWrapper>
<div css={tw`flex justify-end mt-6`}> <div css={tw`flex justify-end mt-6`}>
<Button>Create</Button> <Button>Create</Button>