Skip to content

Commit 6cf7acb

Browse files
committed
cmd overrides for zosmf profile
Signed-off-by: Paul Cooper <[email protected]>
1 parent 688e4f4 commit 6cf7acb

29 files changed

+302
-55
lines changed

__tests__/api/BundlePush/BundlePusher.test.ts

Lines changed: 69 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*/
1111

1212
import { BundlePusher } from "../../../src/api/BundlePush/BundlePusher";
13-
import { IHandlerParameters, ImperativeError, IImperativeError } from "@zowe/imperative";
13+
import { IHandlerParameters, ImperativeError, IImperativeError, IProfile } from "@zowe/imperative";
1414
import * as cmci from "@zowe/cics";
1515
import * as PushBundleDefinition from "../../../src/cli/push/bundle/PushBundle.definition";
1616
import * as fse from "fs-extra";
@@ -111,7 +111,7 @@ describe("BundlePusher01", () => {
111111
lstatSpy = jest.spyOn(fs, "lstatSync").mockImplementation(() => ( IS_NOT_DIRECTORY ));
112112
cmciSpy = jest.spyOn(cmci, "getResource").mockImplementation(() => ({ response: { records: {} } }));
113113
consoleText = "";
114-
zosmfProfile = { host: "wibble", user: "user", password: "thisIsntReal" };
114+
zosmfProfile = { host: "wibble", user: "user", password: "thisIsntReal", port: 443, rejectUnauthorized: true };
115115
sshProfile = { host: "wibble", user: "user", password: "thisIsntReal" };
116116
cicsProfile = undefined;
117117
});
@@ -199,6 +199,58 @@ describe("BundlePusher01", () => {
199199

200200
expect(zosMFSpy).toHaveBeenCalledTimes(1);
201201
});
202+
it("should implement --zosmf-* overrides" , async () => {
203+
zosmfProfile = { host: "wibble", user: "user" };
204+
sshProfile = { host: "wibble", user: "user" };
205+
const parms = getCommonParmsForPushTests();
206+
parms.arguments.zh = "overrideHost";
207+
parms.arguments.zp = 123;
208+
parms.arguments.zu = "overrideUser";
209+
parms.arguments.zpw = "overridePassword";
210+
parms.arguments.zru = false;
211+
parms.arguments.zbp = "overrideBasePath";
212+
zosMFSpy.mockImplementationOnce((profile: IProfile) => {
213+
expect(profile.host).toMatch("overrideHost");
214+
expect(profile.port).toEqual(123);
215+
expect(profile.user).toMatch("overrideUser");
216+
expect(profile.password).toMatch("overridePassword");
217+
expect(profile.rejectUnauthorized).toEqual(false);
218+
expect(profile.basePath).toMatch("overrideBasePath");
219+
});
220+
221+
await runPushTest("__tests__/__resources__/ExampleBundle01", true,
222+
"PUSH operation completed", parms);
223+
});
224+
it("should complain if zosmf-host notset" , async () => {
225+
zosmfProfile = undefined;
226+
227+
await runPushTestWithError("__tests__/__resources__/ExampleBundle01", false,
228+
"Required parameter --zosmf-host is not set.");
229+
});
230+
it("should complain if zosmf-port notset" , async () => {
231+
zosmfProfile = { host: "wibble" };
232+
233+
await runPushTestWithError("__tests__/__resources__/ExampleBundle01", false,
234+
"Required parameter --zosmf-port is not set.");
235+
});
236+
it("should complain if zosmf-user notset" , async () => {
237+
zosmfProfile = { host: "wibble", port: 443 };
238+
239+
await runPushTestWithError("__tests__/__resources__/ExampleBundle01", false,
240+
"Required parameter --zosmf-user is not set.");
241+
});
242+
it("should complain if zosmf-password notset" , async () => {
243+
zosmfProfile = { host: "wibble", port: 443, user: "user" };
244+
245+
await runPushTestWithError("__tests__/__resources__/ExampleBundle01", false,
246+
"Required parameter --zosmf-password is not set.");
247+
});
248+
it("should complain if zosmf-reject-unauthorized notset" , async () => {
249+
zosmfProfile = { host: "wibble", port: 443, user: "user", password: "thisIsntReal" };
250+
251+
await runPushTestWithError("__tests__/__resources__/ExampleBundle01", false,
252+
"Required parameter --zosmf-reject-unauthorized is not set.");
253+
});
202254
it("should complain with missing SSH profile for push", async () => {
203255
sshSpy.mockImplementationOnce(() => { throw new Error( "Injected SSH Create error" ); });
204256
await runPushTestWithError("__tests__/__resources__/ExampleBundle01", false, "Injected SSH Create error");
@@ -207,15 +259,13 @@ describe("BundlePusher01", () => {
207259
expect(sshSpy).toHaveBeenCalledTimes(1);
208260
});
209261
it("should complain with mismatching zOSMF and SSH profile host names", async () => {
210-
zosmfProfile = { host: "wibble", user: "user" };
211262
sshProfile = { host: "wobble", user: "user" };
212263

213264
await runPushTest("__tests__/__resources__/ExampleBundle01", true,
214265
"PUSH operation completed");
215266
expect(consoleText).toContain("WARNING: ssh profile --host value 'wobble' does not match zosmf value 'wibble'.");
216267
});
217268
it("should not complain with matching zOSMF and SSH profile host names", async () => {
218-
zosmfProfile = { host: "wibble", user: "user" };
219269
sshProfile = { host: "wibble", user: "user" };
220270

221271
await runPushTest("__tests__/__resources__/ExampleBundle01", true,
@@ -237,67 +287,59 @@ describe("BundlePusher01", () => {
237287
expect(consoleText).not.toContain("WARNING: cics profile");
238288
});
239289
it("should complain with mismatching zOSMF and SSH profile user names", async () => {
240-
zosmfProfile = { host: "wibble", user: "fred" };
241290
sshProfile = { host: "wibble", user: "joe" };
242291

243292
await runPushTest("__tests__/__resources__/ExampleBundle01", true,
244293
"PUSH operation completed");
245-
expect(consoleText).toContain("WARNING: ssh profile --user value 'joe' does not match zosmf value 'fred'.");
294+
expect(consoleText).toContain("WARNING: ssh profile --user value 'joe' does not match zosmf value 'user'.");
246295
});
247296
it("should not complain with matching zOSMF and SSH profile user names", async () => {
248-
zosmfProfile = { host: "wibble", user: "fred" };
249-
sshProfile = { host: "wibble", user: "fred" };
297+
sshProfile = { host: "wibble", user: "user" };
250298

251299
await runPushTest("__tests__/__resources__/ExampleBundle01", true,
252300
"PUSH operation completed");
253301
expect(consoleText).not.toContain("WARNING: ssh profile");
254302
});
255303
it("should not complain with matching zOSMF and SSH profile user names - case", async () => {
256-
zosmfProfile = { host: "wibble", user: "fred" };
257-
sshProfile = { host: "wibble", user: "FRED" };
304+
sshProfile = { host: "wibble", user: "USER" };
258305

259306
await runPushTest("__tests__/__resources__/ExampleBundle01", true,
260307
"PUSH operation completed");
261308
expect(consoleText).not.toContain("WARNING: ssh profile");
262309
});
263310
it("should complain with mismatching zOSMF and CICS profile user names", async () => {
264-
zosmfProfile = { host: "wibble", user: "fred" };
265311
sshProfile = { host: "wibble", user: "fred" };
266312
cicsProfile = { host: "wibble", user: "joe", password: "thisIsntReal", cicsPlex: "12345678" };
267313

268314
await runPushTest("__tests__/__resources__/ExampleBundle01", true,
269315
"PUSH operation completed");
270-
expect(consoleText).toContain("WARNING: cics profile --user value 'joe' does not match zosmf value 'fred'.");
316+
expect(consoleText).toContain("WARNING: cics profile --user value 'joe' does not match zosmf value 'user'.");
271317
});
272318
it("should complain with mismatching zOSMF and SSH profile passwords", async () => {
273-
zosmfProfile = { host: "wibble", user: "fred", password: "fakeZosmfPassword" };
274-
sshProfile = { host: "wibble", user: "fred", password: "fakeSshPassword" };
319+
sshProfile = { host: "wibble", user: "user", password: "fakeSshPassword" };
275320

276321
await runPushTestWithError("__tests__/__resources__/ExampleBundle01", false,
277322
"Incompatible security credentials exist in the zosmf and ssh profiles.");
278323

279-
expect(consoleText).not.toContain("fakeZosmfPassword");
324+
expect(consoleText).not.toContain("thisIsntReal");
280325
expect(consoleText).not.toContain("fakeSshPassword");
281326
});
282327
it("should tolerate mismatching zOSMF and SSH credentials if SSH keys are used", async () => {
283-
zosmfProfile = { host: "wibble", user: "fred", password: "fakeZosmfPassword" };
284328
sshProfile = { host: "wibble", user: "fred", privateKey: "fakeSshKey" };
285329

286330
await runPushTest("__tests__/__resources__/ExampleBundle01", true,
287331
"PUSH operation completed");
288332

289-
expect(consoleText).not.toContain("fakeZosmfPassword");
333+
expect(consoleText).not.toContain("thisIsntReal");
290334
expect(consoleText).not.toContain("fakeSshKey");
291335
});
292336
it("should complain with mismatching zOSMF and cics profile passwords", async () => {
293-
zosmfProfile = { host: "wibble", user: "fred", password: "fakePassword" };
294-
sshProfile = { host: "wibble", user: "fred", password: "fakePassword" };
295-
cicsProfile = { host: "wibble", user: "fred", password: "fakePassword2", cicsPlex: "12345678" };
337+
cicsProfile = { host: "wibble", user: "user", password: "fakePassword2", cicsPlex: "12345678" };
296338

297339
await runPushTestWithError("__tests__/__resources__/ExampleBundle01", false,
298340
"Incompatible security credentials exist in the zosmf and cics profiles.");
299341

300-
expect(consoleText).not.toContain("fakePassword");
342+
expect(consoleText).not.toContain("thisIsntReal");
301343
expect(consoleText).not.toContain("fakePassword2");
302344
});
303345
it("should complain with mismatching cics-deploy and CICS plex names", async () => {
@@ -1552,5 +1594,11 @@ function getCommonParmsForPushTests(): IHandlerParameters {
15521594
parms.arguments.targetstate = "ENABLED";
15531595
parms.arguments.targetdir = "/u/ThisDoesNotExist";
15541596
parms.arguments.overwrite = undefined;
1597+
parms.arguments.zh = undefined;
1598+
parms.arguments.zp = undefined;
1599+
parms.arguments.zu = undefined;
1600+
parms.arguments.zpw = undefined;
1601+
parms.arguments.zru = undefined;
1602+
parms.arguments.zbp = undefined;
15551603
return parms;
15561604
}

docs/pages/cdp/CLIReadme.md

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ the target group of CICS regions\.
2020

2121
zowe cics-deploy deploy bundle [options]
2222

23-
#### cics-deploy
23+
#### cics-deploy Options
2424

2525
* `--name` | `-n` *(string)*
2626

@@ -142,7 +142,7 @@ required\.
142142

143143
zowe cics-deploy generate bundle [options]
144144

145-
#### cics-deploy
145+
#### cics-deploy Options
146146

147147
* `--bundle-id` | `-b` | `--id` | `--bundleid` *(string)*
148148

@@ -215,7 +215,7 @@ Push a CICS bundle from the working directory to a target CICSplex\.
215215

216216
zowe cics-deploy push bundle [options]
217217

218-
#### cics-deploy
218+
#### cics-deploy Options
219219

220220
* `--name` | `-n` *(string)*
221221

@@ -303,11 +303,35 @@ Push a CICS bundle from the working directory to a target CICSplex\.
303303
* Enable or disable the ability to replace an existing bundle directory or bundle
304304
on the remote system\.
305305

306-
#### Profile Options
306+
#### Zosmf Connection Options
307307

308-
* `--zosmf-profile` | `--zosmf-p` *(string)*
308+
* `--zosmf-host` | `--zh` *(string)*
309309

310-
* The name of a (zosmf) profile to load for this command execution\.
310+
* The z/OSMF server host name\.
311+
312+
* `--zosmf-port` | `--zp` *(number)*
313+
314+
* The z/OSMF server port\.
315+
316+
* `--zosmf-user` | `--zu` *(string)*
317+
318+
* Mainframe (z/OSMF) user name, which can be the same as your TSO login\.
319+
320+
* `--zosmf-password` | `--zpw` *(string)*
321+
322+
* Mainframe (z/OSMF) password, which can be the same as your TSO password\.
323+
324+
* `--zosmf-reject-unauthorized` | `--zru` *(boolean)*
325+
326+
* Reject self\-signed certificates\.
327+
328+
* `--zosmf-base-path` | `--zbp` *(string)*
329+
330+
* The base path for your API mediation layer instance\. Specify this option to
331+
prepend the base path to all z/OSMF resources when making REST requests\. Do not
332+
specify this option if you are not using an API mediation layer\.
333+
334+
#### Profile Options
311335

312336
* `--ssh-profile` | `--ssh-p` *(string)*
313337

@@ -317,6 +341,10 @@ Push a CICS bundle from the working directory to a target CICSplex\.
317341

318342
* The name of a (cics\-deploy) profile to load for this command execution\.
319343

344+
* `--zosmf-profile` | `--zosmf-p` *(string)*
345+
346+
* The name of a (zosmf) profile to load for this command execution\.
347+
320348
* `--cics-profile` | `--cics-p` *(string)*
321349

322350
* The name of a (cics) profile to load for this command execution\.
@@ -349,7 +377,7 @@ target group of CICS regions\.
349377

350378
zowe cics-deploy undeploy bundle [options]
351379

352-
#### cics-deploy
380+
#### cics-deploy Options
353381

354382
* `--name` | `-n` *(string)*
355383

src/api/BundlePush/BundlePusher.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { getResource, IResourceParms } from "@zowe/cics";
1717
import { BundleDeployer } from "../BundleDeploy/BundleDeployer";
1818
import { Bundle } from "../BundleContent/Bundle";
1919
import { SubtaskWithStatus } from "./SubtaskWithStatus";
20+
import { ZosmfConfig } from "./ZosmfConfig";
2021

2122

2223
/**
@@ -76,6 +77,7 @@ export class BundlePusher {
7677
const zosMFProfile = this.getProfile("zosmf", true);
7778
const sshProfile = this.getProfile("ssh", true);
7879
const cicsProfile = this.getProfile("cics", false);
80+
ZosmfConfig.mergeProfile(zosMFProfile, this.params);
7981
this.validateProfiles(zosMFProfile, sshProfile, cicsProfile);
8082

8183
// Create a zOSMF session
@@ -185,10 +187,10 @@ export class BundlePusher {
185187
}
186188

187189
private getProfile(type: string, required: boolean): IProfile {
188-
const profile = this.params.profiles.get(type);
190+
let profile = this.params.profiles.get(type);
189191

190192
if (required && profile === undefined) {
191-
throw new Error("No " + type + " profile found");
193+
profile = {};
192194
}
193195

194196
return profile;

src/api/BundlePush/ZosmfConfig.ts

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/*
2+
* This program and the accompanying materials are made available under the terms of the
3+
* Eclipse Public License v2.0 which accompanies this distribution, and is available at
4+
* https://www.eclipse.org/legal/epl-v20.html
5+
*
6+
* SPDX-License-Identifier: EPL-2.0
7+
*
8+
* Copyright IBM Corp, 2019
9+
*
10+
*/
11+
12+
"use strict";
13+
14+
import { IHandlerParameters, IProfile } from "@zowe/imperative";
15+
16+
17+
/**
18+
* Class to represent a CICS Bundle Pusher.
19+
*
20+
* @export
21+
* @class ZosmfConfig
22+
*/
23+
export class ZosmfConfig {
24+
25+
/**
26+
* Merge command line overrides together with the optional zosmfProfile into a
27+
* composite whole
28+
*/
29+
public static mergeProfile(zosmfProfile: IProfile, params: IHandlerParameters) {
30+
31+
if (params.arguments.zh !== undefined) {
32+
zosmfProfile.host = params.arguments.zh;
33+
zosmfProfile.H = params.arguments.zh;
34+
}
35+
36+
if (params.arguments.zp !== undefined) {
37+
zosmfProfile.port = params.arguments.zp;
38+
zosmfProfile.P = params.arguments.zp;
39+
}
40+
41+
if (params.arguments.zu !== undefined) {
42+
zosmfProfile.user = params.arguments.zu;
43+
zosmfProfile.u = params.arguments.zu;
44+
}
45+
46+
if (params.arguments.zpw !== undefined) {
47+
zosmfProfile.password = params.arguments.zpw;
48+
zosmfProfile.pass = params.arguments.zpw;
49+
zosmfProfile.pw = params.arguments.zpw;
50+
}
51+
52+
if (params.arguments.zru !== undefined) {
53+
zosmfProfile.rejectUnauthorized = params.arguments.zru;
54+
zosmfProfile.ru = params.arguments.zru;
55+
}
56+
57+
if (params.arguments.zbp !== undefined) {
58+
zosmfProfile.basePath = params.arguments.zbp;
59+
zosmfProfile.bp = params.arguments.zbp;
60+
}
61+
62+
ZosmfConfig.validateRequired(zosmfProfile);
63+
}
64+
65+
private static validateRequired(zosmfProfile: IProfile) {
66+
if (zosmfProfile.host === undefined) {
67+
throw new Error("Required parameter --zosmf-host is not set.");
68+
}
69+
if (zosmfProfile.port === undefined) {
70+
throw new Error("Required parameter --zosmf-port is not set.");
71+
}
72+
if (zosmfProfile.user === undefined) {
73+
throw new Error("Required parameter --zosmf-user is not set.");
74+
}
75+
if (zosmfProfile.password === undefined) {
76+
throw new Error("Required parameter --zosmf-password is not set.");
77+
}
78+
if (zosmfProfile.rejectUnauthorized === undefined) {
79+
throw new Error("Required parameter --zosmf-reject-unauthorized is not set.");
80+
}
81+
}
82+
83+
}

src/cli/deploy/bundle/options/Bundledir.option.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export const BundledirOption: ICommandOptionDefinition = {
2323
type: "string",
2424
required: true,
2525
stringLengthRange: [1, MAX_LENGTH],
26-
group: "cics-deploy",
26+
group: "cics-deploy Options",
2727
description: "Specifies the location of the CICS bundle (up to 255 characters) on zFS."
2828
};
2929

src/cli/deploy/bundle/options/Description.option.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export const DescriptionOption: ICommandOptionDefinition = {
2323
type: "string",
2424
required: false,
2525
stringLengthRange: [1, MAX_LENGTH],
26-
group: "cics-deploy",
26+
group: "cics-deploy Options",
2727
description: "An optional value that specifies a description of the bundle definition (up to 58 characters)."
2828
};
2929

0 commit comments

Comments
 (0)