Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore!: removed deprecated fields #1860

Merged
merged 4 commits into from
Apr 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions src/bucket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,6 @@ export interface EnableLoggingOptions {
export interface GetFilesOptions {
autoPaginate?: boolean;
delimiter?: string;
/**
* @deprecated dirrectory is deprecated
* @internal
* */
directory?: string;
endOffset?: string;
includeTrailingDelimiter?: boolean;
prefix?: string;
Expand Down Expand Up @@ -2344,8 +2339,6 @@ class Bucket extends ServiceObject {
* names, aside from the prefix, contain delimiter will have their name
* truncated after the delimiter, returned in `apiResponse.prefixes`.
* Duplicate prefixes are omitted.
* @deprecated @property {string} [directory] Filter results based on a directory name, or
* more technically, a "prefix". Assumes delimeter to be '/'. Deprecated. Use prefix instead.
* @property {string} [endOffset] Filter results to objects whose names are
* lexicographically before endOffset. If startOffset is also set, the objects
* listed have names between startOffset (inclusive) and endOffset (exclusive).
Expand Down Expand Up @@ -2384,8 +2377,6 @@ class Bucket extends ServiceObject {
* names, aside from the prefix, contain delimiter will have their name
* truncated after the delimiter, returned in `apiResponse.prefixes`.
* Duplicate prefixes are omitted.
* @deprecated @param {string} [query.directory] Filter results based on a directory name, or
* more technically, a "prefix". Assumes delimeter to be '/'. Deprecated. Use query.prefix instead.
* @param {string} [query.endOffset] Filter results to objects whose names are
* lexicographically before endOffset. If startOffset is also set, the objects
* listed have names between startOffset (inclusive) and endOffset (exclusive).
Expand Down Expand Up @@ -2521,11 +2512,6 @@ class Bucket extends ServiceObject {
}
query = Object.assign({}, query);

if (query.directory) {
query.prefix = `${query.directory}/`.replace(/\/*$/, '/');
delete query.directory;
}

this.request(
{
uri: '/o',
Expand Down
117 changes: 0 additions & 117 deletions src/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2307,123 +2307,6 @@ class File extends ServiceObject<File> {
);
}

getSignedPolicy(
options: GetSignedPolicyOptions
): Promise<GetSignedPolicyResponse>;
getSignedPolicy(
options: GetSignedPolicyOptions,
callback: GetSignedPolicyCallback
): void;
getSignedPolicy(callback: GetSignedPolicyCallback): void;
/**
* @typedef {array} GetSignedPolicyResponse
* @property {object} 0 The document policy.
*/
/**
* @callback GetSignedPolicyCallback
* @param {?Error} err Request error, if any.
* @param {object} policy The document policy.
*/
/**
* Get a v2 signed policy document to allow a user to upload data with a POST
* request.
*
* In Google Cloud Platform environments, such as Cloud Functions and App
* Engine, you usually don't provide a `keyFilename` or `credentials` during
* instantiation. In those environments, we call the
* {@link https://cloud.google.com/iam/docs/reference/credentials/rest/v1/projects.serviceAccounts/signBlob| signBlob API}
* to create a signed policy. That API requires either the
* `https://www.googleapis.com/auth/iam` or
* `https://www.googleapis.com/auth/cloud-platform` scope, so be sure they are
* enabled.
*
* See {@link https://cloud.google.com/storage/docs/xml-api/post-object#policydocument| Policy Document Reference}
*
* @deprecated `getSignedPolicy()` is deprecated in favor of
* `generateSignedPostPolicyV2()` and `generateSignedPostPolicyV4()`.
* Currently, this method is an alias to `getSignedPolicyV2()`,
* and will be removed in a future major release.
* We recommend signing new policies using v4.
* @internal
*
* @throws {Error} If an expiration timestamp from the past is given.
* @throws {Error} If options.equals has an array with less or more than two
* members.
* @throws {Error} If options.startsWith has an array with less or more than two
* members.
*
* @param {object} options Configuration options.
* @param {array|array[]} [options.equals] Array of request parameters and
* their expected value (e.g. [['$<field>', '<value>']]). Values are
* translated into equality constraints in the conditions field of the
* policy document (e.g. ['eq', '$<field>', '<value>']). If only one
* equality condition is to be specified, options.equals can be a one-
* dimensional array (e.g. ['$<field>', '<value>']).
* @param {*} options.expires - A timestamp when this policy will expire. Any
* value given is passed to `new Date()`.
* @param {array|array[]} [options.startsWith] Array of request parameters and
* their expected prefixes (e.g. [['$<field>', '<value>']). Values are
* translated into starts-with constraints in the conditions field of the
* policy document (e.g. ['starts-with', '$<field>', '<value>']). If only
* one prefix condition is to be specified, options.startsWith can be a
* one- dimensional array (e.g. ['$<field>', '<value>']).
* @param {string} [options.acl] ACL for the object from possibly predefined
* ACLs.
* @param {string} [options.successRedirect] The URL to which the user client
* is redirected if the upload is successful.
* @param {string} [options.successStatus] - The status of the Google Storage
* response if the upload is successful (must be string).
* @param {object} [options.contentLengthRange]
* @param {number} [options.contentLengthRange.min] Minimum value for the
* request's content length.
* @param {number} [options.contentLengthRange.max] Maximum value for the
* request's content length.
* @param {GetSignedPolicyCallback} [callback] Callback function.
* @returns {Promise<GetSignedPolicyResponse>}
*
* @example
* ```
* const {Storage} = require('@google-cloud/storage');
* const storage = new Storage();
* const myBucket = storage.bucket('my-bucket');
*
* const file = myBucket.file('my-file');
* const options = {
* equals: ['$Content-Type', 'image/jpeg'],
* expires: '10-25-2022',
* contentLengthRange: {
* min: 0,
* max: 1024
* }
* };
*
* file.getSignedPolicy(options, function(err, policy) {
* // policy.string: the policy document in plain text.
* // policy.base64: the policy document in base64.
* // policy.signature: the policy signature in base64.
* });
*
* //-
* // If the callback is omitted, we'll return a Promise.
* //-
* file.getSignedPolicy(options).then(function(data) {
* const policy = data[0];
* });
* ```
*/
getSignedPolicy(
optionsOrCallback?: GetSignedPolicyOptions | GetSignedPolicyCallback,
cb?: GetSignedPolicyCallback
): void | Promise<GetSignedPolicyResponse> {
const args = normalize<GetSignedPolicyOptions, GetSignedPolicyCallback>(
optionsOrCallback,
cb
);
const options = args.options;
const callback = args.callback;
this.generateSignedPostPolicyV2(options, callback);
}

generateSignedPostPolicyV2(
options: GenerateSignedPostPolicyV2Options
): Promise<GenerateSignedPostPolicyV2Response>;
Expand Down
15 changes: 2 additions & 13 deletions src/nodejs-common/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -773,25 +773,14 @@ export class Util {
callback: BodyResponseCallback
): void | Abortable {
let autoRetryValue = AUTO_RETRY_DEFAULT;
if (
config.autoRetry !== undefined &&
config.retryOptions?.autoRetry !== undefined
) {
throw new ApiError(
'autoRetry is deprecated. Use retryOptions.autoRetry instead.'
);
} else if (config.autoRetry !== undefined) {
if (config.autoRetry !== undefined) {
autoRetryValue = config.autoRetry;
} else if (config.retryOptions?.autoRetry !== undefined) {
autoRetryValue = config.retryOptions.autoRetry;
}

let maxRetryValue = MAX_RETRY_DEFAULT;
if (config.maxRetries && config.retryOptions?.maxRetries) {
throw new ApiError(
'maxRetries is deprecated. Use retryOptions.maxRetries instead.'
);
} else if (config.maxRetries) {
if (config.maxRetries) {
maxRetryValue = config.maxRetries;
} else if (config.retryOptions?.maxRetries) {
maxRetryValue = config.retryOptions.maxRetries;
Expand Down
47 changes: 7 additions & 40 deletions src/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,21 +69,6 @@ export interface PreconditionOptions {

export interface StorageOptions extends ServiceOptions {
retryOptions?: RetryOptions;
/**
* @deprecated Use retryOptions instead.
* @internal
*/
autoRetry?: boolean;
/**
* @deprecated Use retryOptions instead.
* @internal
*/
maxRetries?: number;
/**
* **This option is deprecated.**
* @todo Remove in next major release.
*/
promise?: typeof Promise;
/**
* The API endpoint of the service used to make requests.
* Defaults to `storage.googleapis.com`.
Expand Down Expand Up @@ -199,8 +184,6 @@ export enum ExceptionMessages {
}

export enum StorageExceptionMessages {
AUTO_RETRY_DEPRECATED = 'autoRetry is deprecated. Use retryOptions.autoRetry instead.',
MAX_RETRIES_DEPRECATED = 'maxRetries is deprecated. Use retryOptions.maxRetries instead.',
BUCKET_NAME_REQUIRED = 'A bucket name is needed to use Cloud Storage.',
BUCKET_NAME_REQUIRED_CREATE = 'A name is required to create a bucket.',
HMAC_SERVICE_ACCOUNT = 'The first argument must be a service account email to create an HMAC key.',
Expand Down Expand Up @@ -593,32 +576,16 @@ export class Storage extends Service {
// Note: EMULATOR_HOST is an experimental configuration variable. Use apiEndpoint instead.
const baseUrl = EMULATOR_HOST || `${options.apiEndpoint}/storage/v1`;

let autoRetryValue = AUTO_RETRY_DEFAULT;
if (
options.autoRetry !== undefined &&
options.retryOptions?.autoRetry !== undefined
) {
throw new ApiError(StorageExceptionMessages.AUTO_RETRY_DEPRECATED);
} else if (options.autoRetry !== undefined) {
autoRetryValue = options.autoRetry;
} else if (options.retryOptions?.autoRetry !== undefined) {
autoRetryValue = options.retryOptions.autoRetry;
}

let maxRetryValue = MAX_RETRY_DEFAULT;
if (options.maxRetries && options.retryOptions?.maxRetries) {
throw new ApiError(StorageExceptionMessages.MAX_RETRIES_DEPRECATED);
} else if (options.maxRetries) {
maxRetryValue = options.maxRetries;
} else if (options.retryOptions?.maxRetries) {
maxRetryValue = options.retryOptions.maxRetries;
}

const config = {
apiEndpoint: options.apiEndpoint!,
retryOptions: {
autoRetry: autoRetryValue,
maxRetries: maxRetryValue,
autoRetry:
options.retryOptions?.autoRetry !== undefined
? options.retryOptions?.autoRetry
: AUTO_RETRY_DEFAULT,
maxRetries: options.retryOptions?.maxRetries
? options.retryOptions?.maxRetries
: MAX_RETRY_DEFAULT,
retryDelayMultiplier: options.retryOptions?.retryDelayMultiplier
? options.retryOptions?.retryDelayMultiplier
: RETRY_DELAY_MULTIPLIER_DEFAULT,
Expand Down
25 changes: 0 additions & 25 deletions system-test/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3263,31 +3263,6 @@ describe('storage', () => {
});
});

it('should get files from a directory', done => {
//Note: Directory is deprecated.
bucket.getFiles({directory: DIRECTORY_NAME}, (err, files) => {
assert.ifError(err);
assert.strictEqual(files!.length, 3);
done();
});
});

it('should get files from a directory as a stream', done => {
//Note: Directory is deprecated.
let numFilesEmitted = 0;

bucket
.getFilesStream({directory: DIRECTORY_NAME})
.on('error', done)
.on('data', () => {
numFilesEmitted++;
})
.on('end', () => {
assert.strictEqual(numFilesEmitted, 3);
done();
});
});

it('should paginate the list', done => {
const query = {
maxResults: NEW_FILES.length - 1,
Expand Down
21 changes: 0 additions & 21 deletions test/bucket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1714,27 +1714,6 @@ describe('Bucket', () => {
bucket.getFiles({maxResults: 5, pageToken: token}, util.noop);
});

it('should allow setting a directory', done => {
//Note: Directory is deprecated.
const directory = 'directory-name';
bucket.request = (reqOpts: DecorateRequestOptions) => {
assert.strictEqual(reqOpts.qs.prefix, `${directory}/`);
assert.strictEqual(reqOpts.qs.directory, undefined);
done();
};
bucket.getFiles({directory}, assert.ifError);
});

it('should strip excess slashes from a directory', done => {
//Note: Directory is deprecated.
const directory = 'directory-name///';
bucket.request = (reqOpts: DecorateRequestOptions) => {
assert.strictEqual(reqOpts.qs.prefix, 'directory-name/');
done();
};
bucket.getFiles({directory}, assert.ifError);
});

it('should return nextQuery if more results exist', () => {
const token = 'next-page-token';
bucket.request = (
Expand Down
21 changes: 0 additions & 21 deletions test/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ import {
SetFileMetadataOptions,
GetSignedUrlConfig,
GenerateSignedPostPolicyV2Options,
GenerateSignedPostPolicyV2Callback,
} from '../src';
import {
SignedPostPolicyV4Output,
Expand Down Expand Up @@ -2862,26 +2861,6 @@ describe('File', () => {
});
});

describe('getSignedPolicy', () => {
it('should alias to generateSignedPostPolicyV2', done => {
const options = {
expires: Date.now() + 2000,
};
const callback = () => {};

file.generateSignedPostPolicyV2 = (
argOpts: GenerateSignedPostPolicyV2Options,
argCb: GenerateSignedPostPolicyV2Callback
) => {
assert.strictEqual(argOpts, options);
assert.strictEqual(argCb, callback);
done();
};

file.getSignedPolicy(options, callback);
});
});

describe('generateSignedPostPolicyV2', () => {
let CONFIG: GenerateSignedPostPolicyV2Options;

Expand Down
Loading