|
11 | 11 |
|
12 | 12 | "use strict";
|
13 | 13 |
|
14 |
| -import { IHandlerParameters, AbstractSession, ITaskWithStatus, TaskStage, TaskProgress, Logger } from "@zowe/imperative"; |
| 14 | +import { IHandlerParameters, AbstractSession, ITaskWithStatus, TaskStage, TaskProgress, Logger, IProfile } from "@zowe/imperative"; |
15 | 15 | import { List, ZosmfSession, SshSession, Shell, Upload, IUploadOptions, ZosFilesAttributes, Create } from "@zowe/cli";
|
16 | 16 | import { BundleDeployer } from "../BundleDeploy/BundleDeployer";
|
17 | 17 | import { Bundle } from "../BundleContent/Bundle";
|
@@ -69,10 +69,15 @@ export class BundlePusher {
|
69 | 69 | "_" + bundle.getVersion();
|
70 | 70 | }
|
71 | 71 |
|
| 72 | + // Get the profiles |
| 73 | + const zosMFProfile = this.getProfile("zosmf"); |
| 74 | + const sshProfile = this.getProfile("ssh"); |
| 75 | + this.validateProfiles(zosMFProfile, sshProfile); |
| 76 | + |
72 | 77 | // Create a zOSMF session
|
73 |
| - const zosMFSession = await this.createZosMFSession(); |
| 78 | + const zosMFSession = await this.createZosMFSession(zosMFProfile); |
74 | 79 | // Create an SSH session
|
75 |
| - const sshSession = await this.createSshSession(); |
| 80 | + const sshSession = await this.createSshSession(sshProfile); |
76 | 81 |
|
77 | 82 | // Start a progress bar (but only in non-verbose mode)
|
78 | 83 | this.progressBar = { percentComplete: 0,
|
@@ -176,23 +181,43 @@ export class BundlePusher {
|
176 | 181 | }
|
177 | 182 | }
|
178 | 183 |
|
179 |
| - private async createZosMFSession(): Promise<AbstractSession> { |
180 |
| - // Create a zosMF session |
181 |
| - const zosmfProfile = this.params.profiles.get("zosmf"); |
| 184 | + private getProfile(type: string): IProfile { |
| 185 | + const profile = this.params.profiles.get(type); |
182 | 186 |
|
183 |
| - if (zosmfProfile === undefined) { |
184 |
| - throw new Error("No zosmf profile found"); |
| 187 | + if (profile === undefined) { |
| 188 | + throw new Error("No " + type + " profile found"); |
185 | 189 | }
|
186 |
| - return ZosmfSession.createBasicZosmfSession(zosmfProfile); |
| 190 | + |
| 191 | + return profile; |
187 | 192 | }
|
188 | 193 |
|
189 |
| - private async createSshSession(): Promise<SshSession> { |
190 |
| - // Create an SSH session |
191 |
| - const sshProfile = this.params.profiles.get("ssh"); |
| 194 | + private issueWarning(msg: string) { |
| 195 | + const warningMsg = "WARNING: " + msg + "\n"; |
| 196 | + this.endProgressBar(); |
| 197 | + this.params.response.console.log(Buffer.from(warningMsg)); |
| 198 | + if (this.params.arguments.silent === undefined) { |
| 199 | + const logger = Logger.getAppLogger(); |
| 200 | + logger.warn(warningMsg); |
| 201 | + } |
| 202 | + this.startProgressBar(); |
| 203 | + } |
192 | 204 |
|
193 |
| - if (sshProfile === undefined) { |
194 |
| - throw new Error("No ssh profile found"); |
| 205 | + private validateProfiles(zosmfProfile: IProfile, sshProfile: IProfile) { |
| 206 | + // Do they share the same host name? |
| 207 | + if (zosmfProfile.host !== sshProfile.host) { |
| 208 | + this.issueWarning("ssh profile --host value '" + sshProfile.host + "' does not match zosmf value '" + zosmfProfile.host + "'."); |
| 209 | + } |
| 210 | + // Do they share the same user name? |
| 211 | + if (zosmfProfile.user !== sshProfile.user) { |
| 212 | + this.issueWarning("ssh profile --user value '" + sshProfile.user + "' does not match zosmf value '" + zosmfProfile.user + "'."); |
195 | 213 | }
|
| 214 | + } |
| 215 | + |
| 216 | + private async createZosMFSession(zosmfProfile: IProfile): Promise<AbstractSession> { |
| 217 | + return ZosmfSession.createBasicZosmfSession(zosmfProfile); |
| 218 | + } |
| 219 | + |
| 220 | + private async createSshSession(sshProfile: IProfile): Promise<SshSession> { |
196 | 221 | return SshSession.createBasicSshSession(sshProfile);
|
197 | 222 | }
|
198 | 223 |
|
@@ -433,14 +458,7 @@ export class BundlePusher {
|
433 | 458 | }
|
434 | 459 |
|
435 | 460 | // A project specific .zosattributes has not been found, so use a default
|
436 |
| - const warningMsg = "WARNING: No .zosAttributes file found in the bundle directory, default values will be applied."; |
437 |
| - this.endProgressBar(); |
438 |
| - this.params.response.console.log(Buffer.from(warningMsg)); |
439 |
| - if (this.params.arguments.silent === undefined) { |
440 |
| - const logger = Logger.getAppLogger(); |
441 |
| - logger.warn(warningMsg); |
442 |
| - } |
443 |
| - this.startProgressBar(); |
| 461 | + this.issueWarning("No .zosAttributes file found in the bundle directory, default values will be applied."); |
444 | 462 | return new ZosFilesAttributes(Bundle.getTemplateZosAttributesFile());
|
445 | 463 | }
|
446 | 464 |
|
@@ -468,13 +486,13 @@ export class BundlePusher {
|
468 | 486 | }
|
469 | 487 |
|
470 | 488 | private startProgressBar() {
|
471 |
| - if (this.params.arguments.verbose !== true) { |
| 489 | + if (this.params.arguments.verbose !== true && this.progressBar !== undefined) { |
472 | 490 | this.params.response.progress.startBar({task: this.progressBar});
|
473 | 491 | }
|
474 | 492 | }
|
475 | 493 |
|
476 | 494 | private endProgressBar() {
|
477 |
| - if (this.params.arguments.verbose !== true) { |
| 495 | + if (this.params.arguments.verbose !== true && this.progressBar !== undefined) { |
478 | 496 | this.params.response.progress.endBar();
|
479 | 497 | }
|
480 | 498 | }
|
|
0 commit comments