Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
const _ = require('lodash');
const Promise = require('bluebird');
const Command = require('../../../Command');
const createRoot = require('../../root/create.cmd');
const { sdk } = require('../../../../../logic');
const { crudFilenameOption } = require('../../../helpers/general');

function builder(y) {
crudFilenameOption(y);
return y
.option('workflow', {
describe: 'Workflow ID that the Workflow-Data-Item belongs to',
required: true,
})
.example('codefresh create workflow-data-item --workflow [WORKFLOW_ID] --file ./file.json', 'Create new Workflow-Data-Iten that belongs to WORKFLOW_ID with content from "./file.json"')
}

async function handler({ workflow, filename }) {
let payload;
if (filename) { // file content
payload = filename;
}
const res = await sdk.workflows.pushWorkflowData({
payload,
workflowId: workflow,
});
console.log(`Workflow-Data-Item ${_.get(res, '_id')} created`);
return Promise.resolve();
}

const command = new Command({
command: 'workflow-data-item',
aliases: ['wdi'],
parent: createRoot,
description: 'Create New Workflow Data Item',
webDocs: {
category: 'Workflow-Data',
title: 'Create',
},
builder,
handler,
});

module.exports = command;
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
const _ = require('lodash');
const Promise = require('bluebird');
const Command = require('../../../Command');
const getRoot = require('../../root/get.cmd');
const { sdk } = require('../../../../../logic');
const Output = require('../../../../../output/Output');
const WorkflowDataItem = require('../../../../../logic/entities/WorkflowDataItem');

async function _get(workflowId, workflowDataItemIds, decrypt) {
const result = [];
await Promise.map((workflowDataItemIds), async (id) => {
const res = await sdk.workflows.getWorkflowDataItem({
workflowId,
id,
decrypt,
});
result.push(WorkflowDataItem.fromResponse(res));
return Promise.resolve();
});
return result;
}

async function _list(workflowId) {
const res = await sdk.workflows.getWorkflowData({
workflowId,
});
return _.map(res.docs, WorkflowDataItem.fromResponse);
}

function builder(y) {
return y
.positional('id', {
describe: 'Workflow-Data-Item ID',
})
.option('workflow', {
describe: 'Workflow ID that the Workflow-Data-Item belongs to',
required: true,
})
.option('decrypt', {
describe: 'When requesting spesific Workflow-Data-Item, decrypt the stored data',
typoe: 'boolean',
})
.example('codefresh get workflow-data-item --workflow [WORKFLOW_ID]', 'Get all Workflow-Data-Items for given WORKFLOW_ID')
.example('codefresh get workflow-data-item [WORKFLOW_DATA_ITEM_ID] --decrypt --workflow [WORKFLOW_ID]', 'Get and decrypt WORKFLOW_DATA_ITEM_ID that is was reported to WORKFLOW_ID');
}

async function handler({ workflow, id, decrypt }) {
let res;
if (id && id.length > 0) {
res = await _get(workflow, id, decrypt);
} else {
res = await _list(workflow);
}
Output.print(res);
}

const command = new Command({
command: 'workflow-data-item [id..]',
aliases: ['wdi'],
parent: getRoot,
description: 'Get Workflow Data Item',
usage: 'Passing [id] argument will cause a retrieval of a specific Workflow-Data-Item.',
webDocs: {
category: 'Workflow-Data',
title: 'Get',
},
builder,
handler,
});

module.exports = command;
48 changes: 48 additions & 0 deletions lib/logic/entities/WorkflowDataItem.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
const _ = require('lodash');
const Entity = require('./Entity');

class WorkflowDataItem extends Entity {
constructor(data) {
super();
this.entityType = 'workflow-data-item';
this.info = data;
this.defaultColumns = [
'id',
'created-at',
'data',
];
this.wideColumns = _.clone(this.defaultColumns);
}

static _strinfigyData(input) {
if (input.data === '*****') {
return input;
}
const data = JSON.stringify(input.data);
return {
...input,
data,
};
}

toDefault() {
return WorkflowDataItem._strinfigyData(super.toDefault());
}

toWide() {
return WorkflowDataItem._strinfigyData(super.toWide());
}

static fromResponse(response) {
const id = response._id;
const createdAt = _.get(response, 'metadata.createdAt');
const data = _.get(response, 'data', '*****');
return new WorkflowDataItem({
id,
'created-at': createdAt,
data,
});
}
}

module.exports = WorkflowDataItem;
122 changes: 122 additions & 0 deletions openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -2193,6 +2193,128 @@
"x-sdk-interface": "workflows.list"
}
},
"/workflow/{workflowId}/data": {
"post": {
"operationId": "push-workflow-data",
"parameters": [
{
"description": "id of a workflowId object",
"in": "path",
"name": "workflowId",
"required": true,
"schema": {
"type": "string"
}
}
],
"responses": {
"201": {
"content": {
"application/json": {
"schema": {
"type": "object"
}
}
},
"description": "json"
}
},
"tags": [
"Builds"
],
"requestBody": {
"content": {
"application/json": {
"schema": {
"type": "object"
}
}
}
},
"summary": "Push New Workflow Data",
"x-sdk-interface": "workflows.pushWorkflowData"
},
"get": {
"operationId": "get-workflow-data",
"parameters": [
{
"description": "id of a workflowId object",
"in": "path",
"name": "workflowId",
"required": true,
"schema": {
"type": "string"
}
}
],
"responses": {
"200": {
"content": {
"application/json": {
"schema": {
"type": "object"
}
}
},
"description": "json"
}
},
"tags": [
"Builds"
],
"summary": "Get Workflow Data",
"x-sdk-interface": "workflows.getWorkflowData"
}
},
"/workflow/{workflowId}/data/{id}": {
"get": {
"operationId": "get-workflow-data-item",
"parameters": [
{
"description": "id of a workflowId object",
"in": "path",
"name": "workflowId",
"required": true,
"schema": {
"type": "string"
}
},
{
"description": "id of an object",
"in": "path",
"name": "id",
"required": true,
"schema": {
"type": "string"
}
},
{
"in": "query",
"name": "decrypt",
"schema": {
"type": "boolean"
}
}
],
"responses": {
"200": {
"content": {
"application/json": {
"schema": {
"type": "object"
}
}
},
"description": "json"
}
},
"tags": [
"Builds"
],
"summary": "Get Workflow Data Item",
"x-sdk-interface": "workflows.getWorkflowDataItem"
}
},
"/builds/{buildId}/update": {
"post": {
"parameters": [
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "codefresh",
"version": "0.69.6",
"version": "0.70.0",
"description": "Codefresh command line utility",
"main": "index.js",
"preferGlobal": true,
Expand Down