diff --git a/client/src/app/modals/deploy-diagram/AuthTypes.js b/client/src/app/modals/deploy-diagram/AuthTypes.js new file mode 100644 index 0000000000..56d2be4d34 --- /dev/null +++ b/client/src/app/modals/deploy-diagram/AuthTypes.js @@ -0,0 +1,7 @@ +const AuthTypes = { + none: 'none', + basic: 'basic', + bearer: 'bearer' +}; + +export default AuthTypes; diff --git a/client/src/app/modals/deploy-diagram/DeployDiagramModal.js b/client/src/app/modals/deploy-diagram/DeployDiagramModal.js index db9c281ae0..d3f8750995 100644 --- a/client/src/app/modals/deploy-diagram/DeployDiagramModal.js +++ b/client/src/app/modals/deploy-diagram/DeployDiagramModal.js @@ -1,6 +1,7 @@ import React from 'react'; import View from './View'; +import AuthTypes from './AuthTypes'; import errorMessageFunctions from './error-messages'; @@ -15,6 +16,17 @@ const defaultState = { error: '' }; +const initialFormValues = { + endpointUrl: '', + tenantId: '', + deploymentName: '', + authType: 'none', + username: '', + password: '', + bearer: '' +}; + + class DeployDiagramModal extends React.Component { constructor(props) { super(props); @@ -69,8 +81,34 @@ class DeployDiagramModal extends React.Component { } } + validateUsername = username => { + if (!username.length) { + return 'Username must not be void.'; + } + } + + validatePassword = password => { + if (!password.length) { + return 'Password must not be void.'; + } + } + + validateBearer = bearer => { + if (!bearer.length) { + return 'Token must not be void.'; + } + } + render() { const { endpoints } = this.props; + const validators = { + endpointUrl: this.validateEndpointUrl, + deploymentName: this.validateDeploymentName, + username: this.validateUsername, + password: this.validatePassword, + bearer: this.validateBearer + }; + return ; } @@ -101,6 +137,12 @@ class DeployDiagramModal extends React.Component { tenantId: values.tenantId }; + const auth = this.getAuth(values); + + if (auth) { + payload.auth = auth; + } + return payload; } @@ -120,6 +162,21 @@ class DeployDiagramModal extends React.Component { return url; } + getAuth({ authType, username, password, bearer }) { + switch (authType) { + case AuthTypes.basic: + return { + username, + password + }; + case AuthTypes.bearer: { + return { + bearer + }; + } + } + } + getErrorMessage(error) { for (const getMessage of errorMessageFunctions) { const errorMessage = getMessage(error); diff --git a/client/src/app/modals/deploy-diagram/View.js b/client/src/app/modals/deploy-diagram/View.js index 49f3d0a0e4..c650e7387f 100644 --- a/client/src/app/modals/deploy-diagram/View.js +++ b/client/src/app/modals/deploy-diagram/View.js @@ -13,6 +13,8 @@ import { ModalWrapper } from '../../primitives'; +import AuthTypes from './AuthTypes'; + import css from './View.less'; @@ -27,8 +29,7 @@ const View = (props) => { initialValues, onClose, onDeploy, - validateEndpointUrl, - validateDeploymentName + validators } = props; return ( @@ -44,7 +45,7 @@ const View = (props) => { initialValues={ initialValues } onSubmit={ onDeploy } > - {({ errors, isSubmitting, submitCount, touched }) => ( + {({ isSubmitting, values }) => ( { isSubmitting && } @@ -54,55 +55,45 @@ const View = (props) => { { error && }
-
- -
-
- - - { errors.endpointUrl && touched.endpointUrl ? ( -
{errors.endpointUrl}
- ) : null} - -
- Should point to a running Camunda Engine REST API endpoint. -
-
+ + + + +
- +
- - - { errors.deploymentName && touched.deploymentName ? ( -
{errors.deploymentName}
- ) : null} + + + + +
-
- -
+ { values.authType === AuthTypes.basic && } -
- -
+ { values.authType === AuthTypes.bearer && }