Skip to content

Commit

Permalink
Add TS code from #3135 and adapt to new init stype
Browse files Browse the repository at this point in the history
Signed-off-by: 1000TurquoisePogs <[email protected]>
  • Loading branch information
1000TurquoisePogs authored and MarkAckert committed Dec 11, 2024
1 parent 6f4f0cf commit 02e3f7d
Show file tree
Hide file tree
Showing 20 changed files with 803 additions and 4 deletions.
17 changes: 17 additions & 0 deletions bin/commands/init/apfauth/cli.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
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.
*/

import * as index from './index';
import * as configmgr from '../../../libs/configmgr';

index.execute();

configmgr.cleanupTempDir();
13 changes: 13 additions & 0 deletions bin/commands/init/apfauth/index.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,19 @@
# Copyright Contributors to the Zowe Project.
#######################################################################

USE_CONFIGMGR=$(check_configmgr_enabled)
if [ "${USE_CONFIGMGR}" = "true" ]; then
if [ -z "${ZWE_PRIVATE_TMP_MERGED_YAML_DIR}" ]; then

# user-facing command, use tmpdir to not mess up workspace permissions
export ZWE_PRIVATE_TMP_MERGED_YAML_DIR=1
fi
_CEE_RUNOPTS="XPLINK(ON),HEAPPOOLS(OFF)" ${ZWE_zowe_runtimeDirectory}/bin/utils/configmgr -script "${ZWE_zowe_runtimeDirectory}/bin/commands/init/apfauth/cli.js"
else
print_error_and_exit "Error ZWEL0316E: Command requires zowe.useConfigmgr=true to use." "" 316
fi


print_level1_message "APF authorize load libraries"

###############################
Expand Down
47 changes: 47 additions & 0 deletions bin/commands/init/apfauth/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
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.
*/

import * as zosJes from '../../../libs/zos-jes';
import * as zoslib from '../../../libs/zos';
import * as common from '../../../libs/common';
import * as config from '../../../libs/config';

export function execute() {

common.printLevel1Message(`APF authorize load libraries`);

// Validation
common.requireZoweYaml();
const ZOWE_CONFIG = config.getZoweConfig();

// read prefix and validate
const prefix=ZOWE_CONFIG.zowe?.setup?.dataset?.prefix;
if (!prefix) {
common.printErrorAndExit(`Error ZWEL0157E: Zowe dataset prefix (zowe.setup.dataset.prefix) is not defined in Zowe YAML configuration file.`, undefined, 157);
}

// read JCL library and validate
const jcllib = zoslib.verifyGeneratedJcl(ZOWE_CONFIG);
if (!jcllib) {
return common.printErrorAndExit(`Error ZWEL0999E: zowe.setup.dataset.jcllib does not exist, cannot run. Run 'zwe init', 'zwe init generate', or submit JCL ${prefix}.SZWESAMP(ZWEGENER) before running this command.`, undefined, 999);
}


['authLoadlib', 'authPluginLib'].forEach((key)=> {
if (!ZOWE_CONFIG.zowe?.setup?.dataset || !ZOWE_CONFIG.zowe?.setup?.dataset[key]) {
common.printErrorAndExit(`Error ZWEL0157E: zowe.setup.dataset.${key} is not defined in Zowe YAML configuration file.`, undefined, 157);
}
});


zosJes.printAndHandleJcl(`//'${jcllib}(ZWEIAPF)'`, `ZWEIAPF`, jcllib, prefix);
common.printLevel2Message(`Zowe load libraries are APF authorized successfully.`);
}
18 changes: 18 additions & 0 deletions bin/commands/init/cli.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
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.
*/

import * as std from 'cm_std';
import * as index from './index';
import * as configmgr from '../../libs/configmgr';

index.execute(std.getenv("ZWE_CLI_PARAMETER_ALLOW_OVERWRITE") == 'true', std.getenv('ZWE_CLI_PARAMETER_SECURITY_DRY_RUN') == 'true', std.getenv('ZWE_CLI_PARAMETER_IGNORE_SECURITY_FAILURES') == 'true', std.getenv("ZWE_CLI_PARAMETER_UPDATE_CONFIG") == 'true');

configmgr.cleanupTempDir();
13 changes: 13 additions & 0 deletions bin/commands/init/index.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,19 @@
# Copyright Contributors to the Zowe Project.
#######################################################################

USE_CONFIGMGR=$(check_configmgr_enabled)
if [ "${USE_CONFIGMGR}" = "true" ]; then
if [ -z "${ZWE_PRIVATE_TMP_MERGED_YAML_DIR}" ]; then

# user-facing command, use tmpdir to not mess up workspace permissions
export ZWE_PRIVATE_TMP_MERGED_YAML_DIR=1
fi
_CEE_RUNOPTS="XPLINK(ON),HEAPPOOLS(OFF)" ${ZWE_zowe_runtimeDirectory}/bin/utils/configmgr -script "${ZWE_zowe_runtimeDirectory}/bin/commands/init/cli.js"
else
print_error_and_exit "Error ZWEL0316E: Command requires zowe.useConfigmgr=true to use." "" 316
fi


print_level0_message "Configure Zowe"

###############################
Expand Down
121 changes: 121 additions & 0 deletions bin/commands/init/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
/*
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.
*/

import * as std from 'cm_std';
import * as shell from '../../libs/shell';
import * as zoslib from '../../libs/zos';
import * as json from '../../libs/json';
import * as zosJes from '../../libs/zos-jes';
import * as zosDataset from '../../libs/zos-dataset';
import * as common from '../../libs/common';
import * as config from '../../libs/config';
import * as node from '../../libs/node';
import * as java from '../../libs/java';

import * as initGenerate from './generate/index';
import * as initMvs from './mvs/index';
import * as initVsam from './vsam/index';
import * as initApfAuth from './apfauth/index';
import * as initSecurity from './security/index';
//import * as initCertificate from './certificate/index';
import * as initStc from './stc/index';

export function execute(allowOverwrite?: boolean, dryRun?: boolean, ignoreSecurityFailures?: boolean, updateConfig?: boolean) {
common.printLevel0Message(`Configure Zowe`);

// Validation
common.requireZoweYaml();

// Read job name and validate
const zoweConfig = config.getZoweConfig();


common.printLevel1Message(`Check if need to update runtime directory, Java and/or node.js settings in Zowe YAML configuration`);
// node.home
let newNodeHome;
const configNodeHome=zoweConfig.node?.home;
// only try to update if it's not defined
if (!configNodeHome || configNodeHome == 'DETECT') {
node.requireNode();
newNodeHome=std.getenv('NODE_HOME');
}

// java.home
let newJavaHome;
const configJavaHome=zoweConfig.java?.home;
// only try to update if it's not defined
if (!configJavaHome || configJavaHome == 'DETECT') {
java.requireJava();
newJavaHome=std.getenv('JAVA_HOME');
}

// zowe.runtimeDirectory
let newZoweRuntimeDir;
// do we have zowe.runtimeDirectory defined in zowe.yaml?
const configRuntimeDir = zoweConfig.zowe?.runtimeDirectory;
if (configRuntimeDir) {
if (configRuntimeDir != std.getenv('ZWE_zowe_runtimeDirectory')) {
common.printErrorAndExit(`Error ZWEL0105E: The Zowe YAML config file is associated to Zowe runtime "${configRuntimeDir}", which is not same as where zwe command is located.`, undefined, 105);
}
} else {
newZoweRuntimeDir = std.getenv('ZWE_zowe_runtimeDirectory');
}

if (newNodeHome || newJavaHome || newZoweRuntimeDir) {
if (std.getenv("ZWE_CLI_PARAMETER_UPDATE_CONFIG") == "true") {
let updateObj:any = {};
if (newNodeHome) {
updateObj.node = {home: newNodeHome};
}
if (newJavaHome) {
updateObj.java = {home: newJavaHome};
}
if (newZoweRuntimeDir) {
updateObj.zowe = {runtimeDirectory: newZoweRuntimeDir};
}
json.updateZoweYamlFromObj(std.getenv('ZOWE_CLI_PARAMETER_CONFIG'), updateObj);

common.printLevel2Message(`Runtime directory, Java and/or node.js settings are updated successfully.`);
} else {
common.printMessage(`These configurations need to be added to your YAML configuration file:`);
common.printMessage(``);
if (newZoweRuntimeDir) {
common.printMessage(`zowe:`);
common.printMessage(` runtimeDirectory: "${newZoweRuntimeDir}"`);
}
if (newNodeHome) {
common.printMessage(`node:`);
common.printMessage(` home: "${newNodeHome}"`);
}
if (newJavaHome) {
common.printMessage(`java:`);
common.printMessage(` home: "${newJavaHome}"`);
}

common.printLevel2Message(`Please manually update "${std.getenv('ZWE_CLI_PARAMETER_CONFIG')}" before you start Zowe.`);
}
} else {
common.printLevel2Message(`No need to update runtime directory, Java and node.js settings.`);
}

initGenerate.execute(dryRun);
initMvs.execute(allowOverwrite);
initVsam.execute(allowOverwrite, dryRun, updateConfig);
if (std.getenv("ZWE_CLI_PARAMETER_SKIP_SECURITY_SETUP") != 'true') {
initApfAuth.execute();
initSecurity.execute(dryRun, ignoreSecurityFailures);
}
//initCertificate.execute();
let result = shell.execSync('sh', '-c', `${std.getenv('ZWE_zowe_runtimeDirectory')}/bin/zwe init certificate ${dryRun?'--dry-run':''} ${updateConfig?'--update-config':''} ${allowOverwrite?'--alow-overwrite':''} ${ignoreSecurityFailures?'--ignore-security-failures':''} -c "${std.getenv('ZWE_CLI_PARAMETER_CONFIG')}"`);
initStc.execute(allowOverwrite);

common.printLevel1Message(`Zowe is configured successfully.`);
}
18 changes: 18 additions & 0 deletions bin/commands/init/mvs/cli.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
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.
*/

import * as std from 'cm_std';
import * as index from './index';
import * as configmgr from '../../../libs/configmgr';

index.execute(std.getenv("ZWE_CLI_PARAMETER_ALLOW_OVERWRITE") == 'true');

configmgr.cleanupTempDir();
15 changes: 14 additions & 1 deletion bin/commands/init/mvs/index.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,19 @@
# Copyright Contributors to the Zowe Project.
#######################################################################

USE_CONFIGMGR=$(check_configmgr_enabled)
if [ "${USE_CONFIGMGR}" = "true" ]; then
if [ -z "${ZWE_PRIVATE_TMP_MERGED_YAML_DIR}" ]; then

# user-facing command, use tmpdir to not mess up workspace permissions
export ZWE_PRIVATE_TMP_MERGED_YAML_DIR=1
fi
_CEE_RUNOPTS="XPLINK(ON),HEAPPOOLS(OFF)" ${ZWE_zowe_runtimeDirectory}/bin/utils/configmgr -script "${ZWE_zowe_runtimeDirectory}/bin/commands/init/mvs/cli.js"
else
print_error_and_exit "Error ZWEL0316E: Command requires zowe.useConfigmgr=true to use." "" 316
fi


print_level1_message "Initialize Zowe custom data sets"

###############################
Expand All @@ -28,7 +41,7 @@ if [ -z "${prefix}" ]; then
print_error_and_exit "Error ZWEL0157E: Zowe dataset prefix (zowe.setup.dataset.prefix) is not defined in Zowe YAML configuration file." "" 157
fi

jcllib_location=$(verify_generated_jcl)
jcllib=$(verify_generated_jcl)
if [ "$?" -eq 1 ]; then
print_error_and_exit "Error ZWEL0999E: zowe.setup.dataset.jcllib does not exist, cannot run. Run 'zwe init', 'zwe init generate', or submit JCL ${prefix}.SZWESAMP(ZWEGENER) before running this command." "" 999
fi
Expand Down
90 changes: 90 additions & 0 deletions bin/commands/init/mvs/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/*
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.
*/

import * as zoslib from '../../../libs/zos';
import * as zosJes from '../../../libs/zos-jes';
import * as zosdataset from '../../../libs/zos-dataset';
import * as common from '../../../libs/common';
import * as config from '../../../libs/config';

export function execute(allowOverwrite?: boolean) {
common.printLevel1Message(`Initialize Zowe custom data sets`);
common.requireZoweYaml();
const ZOWE_CONFIG = config.getZoweConfig();

const datasets = [
{ configKey: 'parmlib',
description: 'Zowe parameter library'
},
{ configKey: 'authLoadlib',
description: 'Zowe authorized load library'
},
{ configKey: 'authPluginLib',
description: 'Zowe authorized plugin library'
}
];

const prefix=ZOWE_CONFIG.zowe.setup?.dataset?.prefix;
if (!prefix) {
common.printErrorAndExit(`Error ZWEL0157E: Zowe dataset prefix (zowe.setup.dataset.prefix) is not defined in Zowe YAML configuration file.`, undefined, 157);
}

const jcllib = zoslib.verifyGeneratedJcl(ZOWE_CONFIG);
if (!jcllib) {
common.printErrorAndExit(`Error ZWEL0999E: zowe.setup.dataset.jcllib does not exist, cannot run. Run 'zwe init', 'zwe init generate', or submit JCL ${prefix}.SZWESAMP(ZWEGENER) before running this command.`, undefined, 999);
}

let runALoadlibCreate: boolean;

common.printMessage(`Create data sets if they do not exist`);
let skippedDatasets: boolean = false;

datasets.forEach((datasetDef) => {
// read def and validate
let skip:boolean = false;
const ds=ZOWE_CONFIG.zowe.setup?.dataset ? ZOWE_CONFIG.zowe.setup.dataset[datasetDef.configKey] : undefined;
if (!ds) {
// authLoadlib can be empty
if (datasetDef.configKey == 'authLoadlib') {
skip=true;
} else {
common.printErrorAndExit(`Error ZWEL0157E: ${datasetDef.configKey} (zowe.setup.dataset.${datasetDef.configKey}) is not defined in Zowe YAML configuration file.`, undefined, 157);
}
}

if (datasetDef.configKey == 'authLoadlib') {
runALoadlibCreate = ds == prefix+'SZWEAUTH' ? false : true;
}

if (!skip) {
const datasetExists=zosdataset.isDatasetExists(ds);
if (datasetExists) {
if (allowOverwrite) {
common.printMessage(`Warning ZWEL0300W: ${ds} already exists. Members in this data set will be overwritten.`);
} else {
skippedDatasets = true;
common.printMessage(`Warning ZWEL0301W: ${ds} already exists and will not be overwritten. For upgrades, you must use --allow-overwrite.`);
}
}
}
});

if (skippedDatasets && !allowOverwrite) {
common.printMessage(`Skipped writing to a dataset. To write, you must use --allow-overwrite.`);
} else {
zosJes.printAndHandleJcl(`//'${jcllib}(ZWEIMVS)'`, `ZWEIMVS`, jcllib, prefix);
if (runALoadlibCreate === true) {
zosJes.printAndHandleJcl(`//'${jcllib}(ZWEIMVS2)'`, `ZWEIMVS2`, jcllib, prefix);
}
}

common.printLevel2Message(`Zowe custom data sets are initialized successfully.`);
}
Loading

0 comments on commit 02e3f7d

Please sign in to comment.