Skip to content

Commit

Permalink
feat(plugins): add deployment tool plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
barmac committed Sep 3, 2019
1 parent efedf86 commit fde99e4
Show file tree
Hide file tree
Showing 19 changed files with 7,435 additions and 0 deletions.
16 changes: 16 additions & 0 deletions resources/plugins/deployment-tool/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"plugins": [
"@babel/plugin-proposal-class-properties"
],
"presets": [
[
"@babel/preset-env", {
"modules": false,
"targets": {
"electron": "6"
}
}
],
"@babel/preset-react"
]
}
2 changes: 2 additions & 0 deletions resources/plugins/deployment-tool/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dist
node_modules
26 changes: 26 additions & 0 deletions resources/plugins/deployment-tool/client/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"extends": [
"plugin:bpmn-io/es6",
"plugin:bpmn-io/jsx",
"plugin:bpmn-io/mocha"
],
"rules": {
"import/first": "error",
"import/no-amd": "error",
"import/no-webpack-loader-syntax": "error",
"react/jsx-uses-react": "error",
"react/react-in-jsx-scope": "error"
},
"plugins": [
"import"
],
"env": {
"browser": true,
"es6": true
},
"settings": {
"react": {
"version": "16.4"
}
}
}
17 changes: 17 additions & 0 deletions resources/plugins/deployment-tool/client/AuthTypes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH
* under one or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information regarding copyright
* ownership.
*
* Camunda licenses this file to you under the MIT; you may not use this file
* except in compliance with the MIT License.
*/

const AuthTypes = {
none: 'none',
basic: 'basic',
bearer: 'bearer'
};

export default AuthTypes;
124 changes: 124 additions & 0 deletions resources/plugins/deployment-tool/client/CamundaAPI.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
/**
* Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH
* under one or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information regarding copyright
* ownership.
*
* Camunda licenses this file to you under the MIT; you may not use this file
* except in compliance with the MIT License.
*/

export default class CamundaAPI {
constructor(baseUrl) {
this.baseUrl = baseUrl;
}

async deployDiagram(diagram, details) {
const {
auth,
deploymentName,
tenantId
} = details;

const form = new FormData();

form.append('deployment-name', deploymentName);
form.append('deployment-source', 'Camunda Modeler');
form.append('deploy-changed-only', 'true');

if (tenantId) {
form.append('tenant-id', tenantId);
}

const diagramName = diagram.name;

const blob = new Blob([ diagram.contents ], { type: 'text/xml' });

form.append(diagramName, blob, diagramName);

const headers = this.getHeaders(auth);

let response;

try {
response = await fetch(`${this.baseUrl}/deployment/create`, {
method: 'POST',
body: form,
headers
});
} catch (error) {
response = {
json: () => {
return { message: 'Fetch failed' };
}
};

console.error(error);
}

if (response.ok) {

const {
id,
deployedProcessDefinitions
} = await response.json();

return {
id,
deployedProcessDefinitions,
deployedProcessDefinition: Object.values(deployedProcessDefinitions || {})[0]
};
}

const json = await response.json();

throw responseError('Deployment failed', response, json);
}

getHeaders(auth) {
const headers = {
accept: 'application/json'
};

if (auth) {
headers.authorization = this.getAuthHeader(auth);
}

return headers;
}

getAuthHeader({ bearer, username, password }) {
if (bearer) {
return `Bearer ${bearer}`;
}

if (username && password) {
const credentials = window.btoa(`${username}:${password}`);

return `Basic ${credentials}`;
}

throw new Error('Unknown auth options.');
}
}



// helpers //////////////

const parseError = 'ENGINE-09005 Could not parse BPMN process. Errors: \n*';

function responseError(message, response, details) {
const error = new Error(message);

error.details = details;
error.response = response;

// fix engine not exposing details
if (details && details.message.startsWith(parseError)) {
details.problems = details.message.substring(parseError.length).split(/\s?\n\*\s?/g);
details.message = 'ENGINE-09005 Could not parse BPMN process';
}

return error;
}
Loading

0 comments on commit fde99e4

Please sign in to comment.