Skip to content

Commit

Permalink
Merge pull request #2335 from zowe/zos-download-attributes
Browse files Browse the repository at this point in the history
Zos download attributes
  • Loading branch information
zFernand0 authored Nov 8, 2024
2 parents 3004122 + 6c381ed commit c493ad7
Show file tree
Hide file tree
Showing 18 changed files with 296 additions and 20 deletions.
2 changes: 2 additions & 0 deletions packages/cli/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ All notable changes to the Zowe CLI package will be documented in this file.

## Recent Changes

- Enhancement: Pass a `.zosattributes` file path for the download encoding format by adding the new `--attributes` flag to the `zowe zos-files upload` command. [#2322](https://github.com/zowe/zowe-cli/issues/2322)
- BugFix: Added support for the `--encoding` flag to the `zowe upload dir-to-uss` to allow for encoding uploaded directories for command group consistency. [#2337](https://github.com/zowe/zowe-cli/issues/2337)
- BugFix: Improved output formatting for `zowe zos-tso start app` and `zowe zos-tso send app` commands by parsing and displaying relevant data rather than the entire JSON response. [#2347](https://github.com/zowe/zowe-cli/pull/2347)
- Enhancement: Add the --ignore-not-found flag to avoid file-not-found error messages when deleting files so scripts are not interupted during automated batch processing. The flag bypasses warning prompts to confirm delete actions. [#2254](https://github.com/zowe/zowe-cli/pull/2254)
Expand All @@ -23,6 +24,7 @@ All notable changes to the Zowe CLI package will be documented in this file.

- Enhancement: Added support for running applications on TSO/E address spaces. Start applications and receive/transmit messages using the new `tso start`, `tso receive` and `tso send` commands. [#2280](https://github.com/zowe/zowe-cli/pull/2280)


## `8.4.0`

- Enhancement: Added optional `--attributes` flag to `zowe zos-files upload file-to-uss` to allow passing a .zosattributes file path for upload encoding format. [#2319](https://github.com/zowe/zowe-cli/pull/2319)
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@

exports[`zos-files download uss-file command definition should not have changed 1`] = `
Array [
Object {
"aliases": Array [
"attrs",
],
"conflictsWith": Array [
"binary",
"record",
],
"description": "Path of an attributes file to control how files are downloaded.",
"name": "attributes",
"type": "existingLocalFile",
},
Object {
"aliases": Array [
"b",
Expand Down Expand Up @@ -39,5 +51,9 @@ Array [
"description": "Download the file \\"/a/ibmuser/MyJava.class\\" to \\"java/MyJava.class\\" in binary mode",
"options": "\\"/a/ibmuser/MyJava.class\\" -b -f \\"java/MyJava.class\\"",
},
Object {
"description": "Download the file \\"/a/ibmuser/MyJava.class\\" to \\"java/MyJava.class\\" using a .zosattributes file",
"options": "\\"/a/ibmuser/MyJava.class\\" --attributes /path/to/.zosattributes -f \\"java/MyJava.class\\"",
},
]
`;
3 changes: 2 additions & 1 deletion packages/cli/src/zosfiles/-strings-/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,8 @@ export default {
},
EXAMPLES: {
EX1: `Download the file "/a/ibmuser/my_text.txt" to ./my_text.txt`,
EX2: `Download the file "/a/ibmuser/MyJava.class" to "java/MyJava.class" in binary mode`
EX2: `Download the file "/a/ibmuser/MyJava.class" to "java/MyJava.class" in binary mode`,
EX3: `Download the file "/a/ibmuser/MyJava.class" to "java/MyJava.class" using a .zosattributes file`
}
},
USS_DIR: {
Expand Down
5 changes: 5 additions & 0 deletions packages/cli/src/zosfiles/download/uss/UssFile.definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export const UssFileDefinition: ICommandDefinition = {
}
],
options: [
DownloadOptions.attributes,
DownloadOptions.file,
DownloadOptions.binary,
DownloadOptions.encoding
Expand All @@ -51,6 +52,10 @@ export const UssFileDefinition: ICommandDefinition = {
{
description: strings.EXAMPLES.EX2,
options: `"/a/ibmuser/MyJava.class" -b -f "java/MyJava.class"`
},
{
description: strings.EXAMPLES.EX3,
options: `"/a/ibmuser/MyJava.class" --attributes /path/to/.zosattributes -f "java/MyJava.class"`
}
]
};
37 changes: 25 additions & 12 deletions packages/cli/src/zosfiles/download/uss/UssFile.handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,40 @@

import { ZosFilesBaseHandler } from "../../ZosFilesBase.handler";
import { AbstractSession, IHandlerParameters, ITaskWithStatus, TaskStage } from "@zowe/imperative";
import { Download, IZosFilesResponse } from "@zowe/zos-files-for-zowe-sdk";
import { Download, IZosFilesResponse, ZosFilesAttributes } from "@zowe/zos-files-for-zowe-sdk";

/**
* Handler to download an uss file
* @export
*/
export default class UssFileHandler extends ZosFilesBaseHandler {
public async processWithSession(commandParameters: IHandlerParameters, session: AbstractSession): Promise<IZosFilesResponse> {
public async processWithSession(
commandParameters: IHandlerParameters,
session: AbstractSession
): Promise<IZosFilesResponse> {
const task: ITaskWithStatus = {
percentComplete: 0,
statusMessage: "Downloading USS file",
stageName: TaskStage.IN_PROGRESS
stageName: TaskStage.IN_PROGRESS,
};
commandParameters.response.progress.startBar({task});
return Download.ussFile(session, commandParameters.arguments.ussFileName, {
binary: commandParameters.arguments.binary,
encoding: commandParameters.arguments.encoding,
file: commandParameters.arguments.file,
task,
responseTimeout: commandParameters.arguments.responseTimeout,
overwrite: commandParameters.arguments.overwrite
});
commandParameters.response.progress.startBar({ task });

const attributes = ZosFilesAttributes.loadFromFile(
commandParameters.arguments.attributes
);

return Download.ussFile(
session,
commandParameters.arguments.ussFileName,
{
binary: commandParameters.arguments.binary,
encoding: commandParameters.arguments.encoding,
file: commandParameters.arguments.file,
task,
responseTimeout: commandParameters.arguments.responseTimeout,
overwrite: commandParameters.arguments.overwrite,
attributes,
}
);
}
}
3 changes: 2 additions & 1 deletion packages/zosfiles/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ All notable changes to the Zowe z/OS files SDK package will be documented in thi

## Recent Changes

- Enhancement: Allows for passing a `.zosattributues` file path for the download encoding format via the `attributes` option on the `Download.ussFile` method. [#2322](https://github.com/zowe/zowe-cli/issues/2322)
- BugFix: Added support for the `--encoding` flag to the `zowe upload dir-to-uss` to allow for encoding uploaded directories for command group consistency. [#2337](https://github.com/zowe/zowe-cli/issues/2337)

## `8.6.2`
Expand All @@ -13,7 +14,7 @@ All notable changes to the Zowe z/OS files SDK package will be documented in thi

## `8.4.0`

- Enhancement: Added optional `--attributes` flag to `zowe zos-files upload file-to-uss` to allow passing a .zosattributes file path for upload encoding format. [#2319] (https://github.com/zowe/zowe-cli/pull/2319)
- Enhancement: Added optional `--attributes` flag to `zowe zos-files upload file-to-uss` to allow passing a .zosattributes file path for upload encoding format. [#2319](https://github.com/zowe/zowe-cli/pull/2319)

## `8.2.0`

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
IMountFsOptions,
Mount,
Unmount,
IUSSListOptions
IUSSListOptions,
} from "../../../../src";
import { Imperative, IO, Session } from "@zowe/imperative";
import { inspect } from "util";
Expand All @@ -37,6 +37,7 @@ import { posix } from "path";
import { Shell } from "@zowe/zos-uss-for-zowe-sdk";
import { PassThrough } from "stream";
import { text } from "stream/consumers";
import { runCliScript } from "@zowe/cli-test-utils";

const rimraf = require("rimraf").sync;
const delayTime = 2000;
Expand Down Expand Up @@ -1080,7 +1081,91 @@ describe.each([false, true])("Download Data Set - Encoded: %s", (encoded: boolea
expect(fileContents).toEqual(testData);

});

describe.each([false, true])(
"Download Data Set - Binary: %s",
(binary: boolean) => {
it("should upload and download file with correct encoding", async () => {
let response: any;

// Upload binary or encoded file
const uploadFile: string = binary
? "downloadEncodingCheck.txt"
: "downloadEncodingCheckBinary.txt";
let downloadResponse: any;
let error: any;

// Use text file as to get proper response from getRemoteEncoding()
const ussnameAsTxt = ussname + ".txt";
try {
response = runCliScript(
__dirname +
`/__resources__/${
binary
? "upload_file_to_uss.sh"
: "upload_file_to_uss_binary.sh"
}`,
testEnvironment,
[
defaultSystem.tso.account,
defaultSystem.zosmf.host,
defaultSystem.zosmf.port,
defaultSystem.zosmf.user,
defaultSystem.zosmf.password,
defaultSystem.zosmf.rejectUnauthorized,
__dirname +
"/__resources__/testfiles/" +
uploadFile,
ussnameAsTxt,
binary ? "1047" : true,
]
);
downloadResponse = runCliScript(
__dirname + "/__resources__/download_file.sh",
testEnvironment,
[
defaultSystem.tso.account,
defaultSystem.zosmf.host,
defaultSystem.zosmf.port,
defaultSystem.zosmf.user,
defaultSystem.zosmf.password,
defaultSystem.zosmf.rejectUnauthorized,
ussnameAsTxt,
__dirname +
`/__resources__/${
binary
? ".zosattributes"
: ".zosattributes-binary"
}`,
]
);
} catch (err) {
error = err;
}

expect(error).toBeFalsy();
expect(response).toBeTruthy();
expect(downloadResponse).toBeTruthy();

// Compare the downloaded contents to those uploaded
const fileContents = fs
.readFileSync(
`${testEnvironment.workingDir}/${posix.basename(
ussnameAsTxt
)}`
)
.toString();
expect(fileContents).toEqual(
fs
.readFileSync(
__dirname +
"/__resources__/testfiles/" +
uploadFile
)
.toString()
);
});
}
);
// When requesting etag, z/OSMF has a limit on file size when it stops to return etag by default (>8mb)
// We are passing X-IBM-Return-Etag to force z/OSMF to always return etag, but testing here for case where it would be optional
it("should download a 10mb uss file and return Etag", async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
*.json -
*.bin binary binary
*.jcl IBM-1047 IBM-1047
*.md UTF-8 UTF-8
*.txt UTF-8 IBM-1047
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
*.json -
*.bin binary binary
*.jcl IBM-1047 IBM-1047
*.md UTF-8 UTF-8
*.txt binary binary
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash
account=$1
host=$2
port=$3
user=$4
password=$5
ru=$6
fileToDownload=$7
attributes=$8

zowe zos-files download uss "$fileToDownload" --attributes "$attributes" --host $host --port $port --user $user --password $password --ru $ru
exit $?
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
abcdefghijklmnopqrstuvwxyz
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[][][]
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash
account=$1
host=$2
port=$3
user=$4
password=$5
ru=$6
inputFile=$7
ussName=$8
encoding=$9

zowe zos-files upload file-to-uss "$inputFile" "$ussName" --encoding $encoding --host $host --port $port --user $user --password $password --ru $ru
exit $?
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash
account=$1
host=$2
port=$3
user=$4
password=$5
ru=$6
inputFile=$7
ussName=$8
binary=$9

zowe zos-files upload file-to-uss "$inputFile" "$ussName" --binary $binary --host $host --port $port --user $user --password $password --ru $ru
exit $?
Loading

0 comments on commit c493ad7

Please sign in to comment.