UNPKG

@zowe/cli

Version:

Zowe CLI is a command line interface (CLI) that provides a simple and streamlined way to interact with IBM z/OS.

107 lines 6.23 kB
"use strict"; /* * This program and the accompanying materials are made available under the terms of the * Eclipse Public License v2.0 which accompanies this distribution, and is available at * https://www.eclipse.org/legal/epl-v20.html * * SPDX-License-Identifier: EPL-2.0 * * Copyright Contributors to the Zowe Project. * */ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); const rest_1 = require("../../../rest"); const WorkflowValidator_1 = require("./WorkflowValidator"); const imperative_1 = require("@zowe/imperative"); const WorkflowConstants_1 = require("./WorkflowConstants"); /** * Get list of workflows from registry. * @export * @class ListWorkflows */ class ListWorkflows { /** * This operation returns list of workflows. * Parameters are optional,request can include one or more parameters to filter the results. * @param {AbstractSession} session - z/OSMF connection info * @param {string} zOSMFVersion - the URI path that identifies the version of the provisioning service. * @param {string} workflowName - the URI path with optional parameter for listing filtered workflows. * @param {string} category - the URI path with optional parameter for listing filtered workflows. * @param {string} system - the URI path with optional parameter for listing filtered workflows. * @param {string} owner - the URI path with optional parameter for listing filtered workflows. * @param {string} vendor - the URI path with optional parameter for listing filtered workflows. * @param {string} statusName - the URI path with optional parameter for listing filtered workflows. * @returns {string} z/OSMF response object * @memberof ListWorkflows */ static listWorkflows(session, zOSMFVersion = WorkflowConstants_1.WorkflowConstants.ZOSMF_VERSION, workflowName, category, system, owner, vendor, statusName) { return __awaiter(this, void 0, void 0, function* () { WorkflowValidator_1.WorkflowValidator.validateSession(session); WorkflowValidator_1.WorkflowValidator.validateNotEmptyString(zOSMFVersion, WorkflowConstants_1.nozOSMFVersion.message); const resourcesQuery = ListWorkflows.getResourcesQuery(zOSMFVersion, [ { key: WorkflowConstants_1.WorkflowConstants.workflowName, value: workflowName ? encodeURIComponent(workflowName) : null }, { key: WorkflowConstants_1.WorkflowConstants.category, value: category }, { key: WorkflowConstants_1.WorkflowConstants.system, value: system }, { key: WorkflowConstants_1.WorkflowConstants.owner, value: owner }, { key: WorkflowConstants_1.WorkflowConstants.vendor, value: vendor }, { key: WorkflowConstants_1.WorkflowConstants.statusName, value: statusName }, ]); return rest_1.ZosmfRestClient.getExpectJSON(session, resourcesQuery); }); } /** * This operation Builds URI path from provided parameters. * @param {string} zOSMFVersion - the URI path that identifies the version of the provisioning service. * @param {string} params - The array with URI path with filters for listing filtered workflows. * @returns {string} URI path for the REST call. * @memberof ListWorkflows */ static getResourcesQuery(zOSMFVersion, params) { let query = `${WorkflowConstants_1.WorkflowConstants.RESOURCE}/${zOSMFVersion}/${WorkflowConstants_1.WorkflowConstants.WORKFLOW_RESOURCE}`; let sign = "?"; params.forEach((element) => { if (element.value) { // Validate if parameter value does not contains ? or & WorkflowValidator_1.WorkflowValidator.validateParameter(element.value, WorkflowConstants_1.wrongString.message); query += sign + `${element.key}=${element.value}`; sign = "&"; } }); return query; } /** * This operation is used to return a worflow-key by given workflow name. * @param {AbstractSession} session - z/OSMF connection info * @param {string} workflowName - workflow name by which to list workflows * @param {string} zOSMFVersion - identifies the version of the provisioning service. * @returns {Promise<string> | null} - Promise with string containing wf key, or null if none was found * @throws {ImperativeError} * @memberof ListWorkflows */ static getWfKey(session, workflowName, zOSMFVersion = WorkflowConstants_1.WorkflowConstants.ZOSMF_VERSION) { return __awaiter(this, void 0, void 0, function* () { WorkflowValidator_1.WorkflowValidator.validateSession(session); WorkflowValidator_1.WorkflowValidator.validateNotEmptyString(zOSMFVersion, WorkflowConstants_1.nozOSMFVersion.message); WorkflowValidator_1.WorkflowValidator.validateNotEmptyString(workflowName, WorkflowConstants_1.noWorkflowName.message); const result = yield this.listWorkflows(session, zOSMFVersion, workflowName); // Check if there was more than one workflows found if (result.workflows.length > 1) { throw new imperative_1.ImperativeError({ msg: `More than one workflows found with name ` + workflowName, }); } return result.workflows.length !== 0 ? result.workflows[0].workflowKey : null; }); } } exports.ListWorkflows = ListWorkflows; //# sourceMappingURL=ListWorkflows.js.map