secret_manager_service_client.js

"use strict";
// Copyright 2019 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// ** This file is automatically generated by gapic-generator-typescript. **
// ** https://github.com/googleapis/gapic-generator-typescript **
// ** All changes to this file may be overwritten. **
Object.defineProperty(exports, "__esModule", { value: true });
const gax = require("google-gax");
const path = require("path");
const gapicConfig = require("./secret_manager_service_client_config.json");
const version = require('../../../package.json').version;
/**
 *  Secret Manager Service
 *
 *  Manages secrets and operations using those secrets. Implements a REST
 *  model with the following objects:
 *
 *  * [Secret][google.cloud.secrets.v1beta1.Secret]
 *  * [SecretVersion][google.cloud.secrets.v1beta1.SecretVersion]
 * @class
 * @memberof v1beta1
 */
class SecretManagerServiceClient {
    /**
     * Construct an instance of SecretManagerServiceClient.
     *
     * @param {object} [options] - The configuration object. See the subsequent
     *   parameters for more details.
     * @param {object} [options.credentials] - Credentials object.
     * @param {string} [options.credentials.client_email]
     * @param {string} [options.credentials.private_key]
     * @param {string} [options.email] - Account email address. Required when
     *     using a .pem or .p12 keyFilename.
     * @param {string} [options.keyFilename] - Full path to the a .json, .pem, or
     *     .p12 key downloaded from the Google Developers Console. If you provide
     *     a path to a JSON file, the projectId option below is not necessary.
     *     NOTE: .pem and .p12 require you to specify options.email as well.
     * @param {number} [options.port] - The port on which to connect to
     *     the remote host.
     * @param {string} [options.projectId] - The project ID from the Google
     *     Developer's Console, e.g. 'grape-spaceship-123'. We will also check
     *     the environment variable GCLOUD_PROJECT for your project ID. If your
     *     app is running in an environment which supports
     *     {@link https://developers.google.com/identity/protocols/application-default-credentials Application Default Credentials},
     *     your project ID will be detected automatically.
     * @param {function} [options.promise] - Custom promise module to use instead
     *     of native Promises.
     * @param {string} [options.apiEndpoint] - The domain name of the
     *     API remote host.
     */
    constructor(opts) {
        this._descriptors = { page: {}, stream: {}, longrunning: {} };
        this._terminated = false;
        // Ensure that options include the service address and port.
        const staticMembers = this.constructor;
        const servicePath = opts && opts.servicePath
            ? opts.servicePath
            : opts && opts.apiEndpoint
                ? opts.apiEndpoint
                : staticMembers.servicePath;
        const port = opts && opts.port ? opts.port : staticMembers.port;
        if (!opts) {
            opts = { servicePath, port };
        }
        opts.servicePath = opts.servicePath || servicePath;
        opts.port = opts.port || port;
        opts.clientConfig = opts.clientConfig || {};
        const isBrowser = typeof window !== 'undefined';
        if (isBrowser) {
            opts.fallback = true;
        }
        // If we are in browser, we are already using fallback because of the
        // "browser" field in package.json.
        // But if we were explicitly requested to use fallback, let's do it now.
        const gaxModule = !isBrowser && opts.fallback ? gax.fallback : gax;
        // Create a `gaxGrpc` object, with any grpc-specific options
        // sent to the client.
        opts.scopes = this
            .constructor.scopes;
        const gaxGrpc = new gaxModule.GrpcClient(opts);
        // Save the auth object to the client, for use by other methods.
        this.auth = gaxGrpc.auth;
        // Determine the client header string.
        const clientHeader = [`gax/${gaxModule.version}`, `gapic/${version}`];
        if (typeof process !== 'undefined' && 'versions' in process) {
            clientHeader.push(`gl-node/${process.versions.node}`);
        }
        else {
            clientHeader.push(`gl-web/${gaxModule.version}`);
        }
        if (!opts.fallback) {
            clientHeader.push(`grpc/${gaxGrpc.grpcVersion}`);
        }
        if (opts.libName && opts.libVersion) {
            clientHeader.push(`${opts.libName}/${opts.libVersion}`);
        }
        // Load the applicable protos.
        // For Node.js, pass the path to JSON proto file.
        // For browsers, pass the JSON content.
        const nodejsProtoPath = path.join(__dirname, '..', '..', 'protos', 'protos.json');
        const protos = gaxGrpc.loadProto(opts.fallback ? require('../../protos/protos.json') : nodejsProtoPath);
        // This API contains "path templates"; forward-slash-separated
        // identifiers to uniquely identify resources within the API.
        // Create useful helper objects for these.
        this._pathTemplates = {
            secretPathTemplate: new gaxModule.PathTemplate('projects/{project}/secrets/{secret}'),
            secretVersionPathTemplate: new gaxModule.PathTemplate('projects/{project}/secrets/{secret}/versions/{secret_version}'),
        };
        // Some of the methods on this service return "paged" results,
        // (e.g. 50 results at a time, with tokens to get subsequent
        // pages). Denote the keys used for pagination and results.
        this._descriptors.page = {
            listSecrets: new gaxModule.PageDescriptor('pageToken', 'nextPageToken', 'secrets'),
            listSecretVersions: new gaxModule.PageDescriptor('pageToken', 'nextPageToken', 'versions'),
        };
        // Put together the default options sent with requests.
        const defaults = gaxGrpc.constructSettings('google.cloud.secrets.v1beta1.SecretManagerService', gapicConfig, opts.clientConfig || {}, { 'x-goog-api-client': clientHeader.join(' ') });
        // Set up a dictionary of "inner API calls"; the core implementation
        // of calling the API is handled in `google-gax`, with this code
        // merely providing the destination and request information.
        this._innerApiCalls = {};
        // Put together the "service stub" for
        // google.cloud.secrets.v1beta1.SecretManagerService.
        this.secretManagerServiceStub = gaxGrpc.createStub(opts.fallback
            ? protos.lookupService('google.cloud.secrets.v1beta1.SecretManagerService')
            : // tslint:disable-next-line no-any
                protos.google.cloud.secrets.v1beta1.SecretManagerService, opts);
        // Iterate over each of the methods that the service provides
        // and create an API call method for each.
        const secretManagerServiceStubMethods = [
            'listSecrets',
            'createSecret',
            'addSecretVersion',
            'getSecret',
            'updateSecret',
            'deleteSecret',
            'listSecretVersions',
            'getSecretVersion',
            'accessSecretVersion',
            'disableSecretVersion',
            'enableSecretVersion',
            'destroySecretVersion',
            'setIamPolicy',
            'getIamPolicy',
            'testIamPermissions',
        ];
        for (const methodName of secretManagerServiceStubMethods) {
            const innerCallPromise = this.secretManagerServiceStub.then(stub => (...args) => {
                if (this._terminated) {
                    return Promise.reject('The client has already been closed.');
                }
                return stub[methodName].apply(stub, args);
            }, (err) => () => {
                throw err;
            });
            const apiCall = gaxModule.createApiCall(innerCallPromise, defaults[methodName], this._descriptors.page[methodName] ||
                this._descriptors.stream[methodName] ||
                this._descriptors.longrunning[methodName]);
            this._innerApiCalls[methodName] = (argument, callOptions, callback) => {
                return apiCall(argument, callOptions, callback);
            };
        }
    }
    /**
     * The DNS address for this API service.
     */
    static get servicePath() {
        return 'secretmanager.googleapis.com';
    }
    /**
     * The DNS address for this API service - same as servicePath(),
     * exists for compatibility reasons.
     */
    static get apiEndpoint() {
        return 'secretmanager.googleapis.com';
    }
    /**
     * The port for this API service.
     */
    static get port() {
        return 443;
    }
    /**
     * The scopes needed to make gRPC calls for every method defined
     * in this service.
     */
    static get scopes() {
        return ['https://www.googleapis.com/auth/cloud-platform'];
    }
    /**
     * Return the project ID used by this class.
     * @param {function(Error, string)} callback - the callback to
     *   be called with the current project Id.
     */
    getProjectId(callback) {
        if (callback) {
            this.auth.getProjectId(callback);
            return;
        }
        return this.auth.getProjectId();
    }
    /**
     * Creates a new [Secret][google.cloud.secrets.v1beta1.Secret] containing no [SecretVersions][google.cloud.secrets.v1beta1.SecretVersion].
     *
     * @param {Object} request
     *   The request object that will be sent.
     * @param {string} request.parent
     *   Required. The resource name of the project to associate with the
     *   [Secret][google.cloud.secrets.v1beta1.Secret], in the format `projects/*`.
     * @param {string} request.secretId
     *   Required. This must be unique within the project.
     * @param {google.cloud.secrets.v1beta1.Secret} request.secret
     *   A [Secret][google.cloud.secrets.v1beta1.Secret] with initial field values.
     * @param {object} [options]
     *   Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details.
     * @returns {Promise} - The promise which resolves to an array.
     *   The first element of the array is an object representing [Secret]{@link google.cloud.secrets.v1beta1.Secret}.
     *   The promise has a method named "cancel" which cancels the ongoing API call.
     */
    createSecret(request, optionsOrCallback, callback) {
        request = request || {};
        let options;
        if (typeof optionsOrCallback === 'function' && callback === undefined) {
            callback = optionsOrCallback;
            options = {};
        }
        else {
            options = optionsOrCallback;
        }
        options = options || {};
        options.otherArgs = options.otherArgs || {};
        options.otherArgs.headers = options.otherArgs.headers || {};
        options.otherArgs.headers['x-goog-request-params'] = gax.routingHeader.fromParams({
            parent: request.parent || '',
        });
        return this._innerApiCalls.createSecret(request, options, callback);
    }
    /**
     * Creates a new [SecretVersion][google.cloud.secrets.v1beta1.SecretVersion] containing secret data and attaches
     * it to an existing [Secret][google.cloud.secrets.v1beta1.Secret].
     *
     * @param {Object} request
     *   The request object that will be sent.
     * @param {string} request.parent
     *   Required. The resource name of the [Secret][google.cloud.secrets.v1beta1.Secret] to associate with the
     *   [SecretVersion][google.cloud.secrets.v1beta1.SecretVersion] in the format `projects/* /secrets/*`.
     * @param {google.cloud.secrets.v1beta1.SecretPayload} request.payload
     *   Required. The secret payload of the [SecretVersion][google.cloud.secrets.v1beta1.SecretVersion].
     * @param {object} [options]
     *   Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details.
     * @returns {Promise} - The promise which resolves to an array.
     *   The first element of the array is an object representing [SecretVersion]{@link google.cloud.secrets.v1beta1.SecretVersion}.
     *   The promise has a method named "cancel" which cancels the ongoing API call.
     */
    addSecretVersion(request, optionsOrCallback, callback) {
        request = request || {};
        let options;
        if (typeof optionsOrCallback === 'function' && callback === undefined) {
            callback = optionsOrCallback;
            options = {};
        }
        else {
            options = optionsOrCallback;
        }
        options = options || {};
        options.otherArgs = options.otherArgs || {};
        options.otherArgs.headers = options.otherArgs.headers || {};
        options.otherArgs.headers['x-goog-request-params'] = gax.routingHeader.fromParams({
            parent: request.parent || '',
        });
        return this._innerApiCalls.addSecretVersion(request, options, callback);
    }
    /**
     * Gets metadata for a given [Secret][google.cloud.secrets.v1beta1.Secret].
     *
     * @param {Object} request
     *   The request object that will be sent.
     * @param {string} request.name
     *   Required. The resource name of the [Secret][google.cloud.secrets.v1beta1.Secret], in the format `projects/* /secrets/*`.
     * @param {object} [options]
     *   Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details.
     * @returns {Promise} - The promise which resolves to an array.
     *   The first element of the array is an object representing [Secret]{@link google.cloud.secrets.v1beta1.Secret}.
     *   The promise has a method named "cancel" which cancels the ongoing API call.
     */
    getSecret(request, optionsOrCallback, callback) {
        request = request || {};
        let options;
        if (typeof optionsOrCallback === 'function' && callback === undefined) {
            callback = optionsOrCallback;
            options = {};
        }
        else {
            options = optionsOrCallback;
        }
        options = options || {};
        options.otherArgs = options.otherArgs || {};
        options.otherArgs.headers = options.otherArgs.headers || {};
        options.otherArgs.headers['x-goog-request-params'] = gax.routingHeader.fromParams({
            name: request.name || '',
        });
        return this._innerApiCalls.getSecret(request, options, callback);
    }
    /**
     * Updates metadata of an existing [Secret][google.cloud.secrets.v1beta1.Secret].
     *
     * @param {Object} request
     *   The request object that will be sent.
     * @param {google.cloud.secrets.v1beta1.Secret} request.secret
     *   Required. [Secret][google.cloud.secrets.v1beta1.Secret] with updated field values.
     * @param {google.protobuf.FieldMask} request.updateMask
     *   Required. Specifies the fields to be updated.
     * @param {object} [options]
     *   Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details.
     * @returns {Promise} - The promise which resolves to an array.
     *   The first element of the array is an object representing [Secret]{@link google.cloud.secrets.v1beta1.Secret}.
     *   The promise has a method named "cancel" which cancels the ongoing API call.
     */
    updateSecret(request, optionsOrCallback, callback) {
        request = request || {};
        let options;
        if (typeof optionsOrCallback === 'function' && callback === undefined) {
            callback = optionsOrCallback;
            options = {};
        }
        else {
            options = optionsOrCallback;
        }
        options = options || {};
        options.otherArgs = options.otherArgs || {};
        options.otherArgs.headers = options.otherArgs.headers || {};
        options.otherArgs.headers['x-goog-request-params'] = gax.routingHeader.fromParams({
            'secret.name': request.secret.name || '',
        });
        return this._innerApiCalls.updateSecret(request, options, callback);
    }
    /**
     * Deletes a [Secret][google.cloud.secrets.v1beta1.Secret].
     *
     * @param {Object} request
     *   The request object that will be sent.
     * @param {string} request.name
     *   Required. The resource name of the [Secret][google.cloud.secrets.v1beta1.Secret] to delete in the format
     *   `projects/* /secrets/*`.
     * @param {object} [options]
     *   Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details.
     * @returns {Promise} - The promise which resolves to an array.
     *   The first element of the array is an object representing [Empty]{@link google.protobuf.Empty}.
     *   The promise has a method named "cancel" which cancels the ongoing API call.
     */
    deleteSecret(request, optionsOrCallback, callback) {
        request = request || {};
        let options;
        if (typeof optionsOrCallback === 'function' && callback === undefined) {
            callback = optionsOrCallback;
            options = {};
        }
        else {
            options = optionsOrCallback;
        }
        options = options || {};
        options.otherArgs = options.otherArgs || {};
        options.otherArgs.headers = options.otherArgs.headers || {};
        options.otherArgs.headers['x-goog-request-params'] = gax.routingHeader.fromParams({
            name: request.name || '',
        });
        return this._innerApiCalls.deleteSecret(request, options, callback);
    }
    /**
     * Gets metadata for a [SecretVersion][google.cloud.secrets.v1beta1.SecretVersion].
     *
     * `projects/* /secrets/* /versions/latest` is an alias to the `latest`
     * [SecretVersion][google.cloud.secrets.v1beta1.SecretVersion].
     *
     * @param {Object} request
     *   The request object that will be sent.
     * @param {string} request.name
     *   Required. The resource name of the [SecretVersion][google.cloud.secrets.v1beta1.SecretVersion] in the format
     *   `projects/* /secrets/* /versions/*`.
     *   `projects/* /secrets/* /versions/latest` is an alias to the `latest`
     *   [SecretVersion][google.cloud.secrets.v1beta1.SecretVersion].
     * @param {object} [options]
     *   Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details.
     * @returns {Promise} - The promise which resolves to an array.
     *   The first element of the array is an object representing [SecretVersion]{@link google.cloud.secrets.v1beta1.SecretVersion}.
     *   The promise has a method named "cancel" which cancels the ongoing API call.
     */
    getSecretVersion(request, optionsOrCallback, callback) {
        request = request || {};
        let options;
        if (typeof optionsOrCallback === 'function' && callback === undefined) {
            callback = optionsOrCallback;
            options = {};
        }
        else {
            options = optionsOrCallback;
        }
        options = options || {};
        options.otherArgs = options.otherArgs || {};
        options.otherArgs.headers = options.otherArgs.headers || {};
        options.otherArgs.headers['x-goog-request-params'] = gax.routingHeader.fromParams({
            name: request.name || '',
        });
        return this._innerApiCalls.getSecretVersion(request, options, callback);
    }
    /**
     * Accesses a [SecretVersion][google.cloud.secrets.v1beta1.SecretVersion]. This call returns the secret data.
     *
     * `projects/* /secrets/* /versions/latest` is an alias to the `latest`
     * [SecretVersion][google.cloud.secrets.v1beta1.SecretVersion].
     *
     * @param {Object} request
     *   The request object that will be sent.
     * @param {string} request.name
     *   Required. The resource name of the [SecretVersion][google.cloud.secrets.v1beta1.SecretVersion] in the format
     *   `projects/* /secrets/* /versions/*`.
     * @param {object} [options]
     *   Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details.
     * @returns {Promise} - The promise which resolves to an array.
     *   The first element of the array is an object representing [AccessSecretVersionResponse]{@link google.cloud.secrets.v1beta1.AccessSecretVersionResponse}.
     *   The promise has a method named "cancel" which cancels the ongoing API call.
     */
    accessSecretVersion(request, optionsOrCallback, callback) {
        request = request || {};
        let options;
        if (typeof optionsOrCallback === 'function' && callback === undefined) {
            callback = optionsOrCallback;
            options = {};
        }
        else {
            options = optionsOrCallback;
        }
        options = options || {};
        options.otherArgs = options.otherArgs || {};
        options.otherArgs.headers = options.otherArgs.headers || {};
        options.otherArgs.headers['x-goog-request-params'] = gax.routingHeader.fromParams({
            name: request.name || '',
        });
        return this._innerApiCalls.accessSecretVersion(request, options, callback);
    }
    /**
     * Disables a [SecretVersion][google.cloud.secrets.v1beta1.SecretVersion].
     *
     * Sets the [state][google.cloud.secrets.v1beta1.SecretVersion.state] of the [SecretVersion][google.cloud.secrets.v1beta1.SecretVersion] to
     * [DISABLED][google.cloud.secrets.v1beta1.SecretVersion.State.DISABLED].
     *
     * @param {Object} request
     *   The request object that will be sent.
     * @param {string} request.name
     *   Required. The resource name of the [SecretVersion][google.cloud.secrets.v1beta1.SecretVersion] to disable in the format
     *   `projects/* /secrets/* /versions/*`.
     * @param {object} [options]
     *   Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details.
     * @returns {Promise} - The promise which resolves to an array.
     *   The first element of the array is an object representing [SecretVersion]{@link google.cloud.secrets.v1beta1.SecretVersion}.
     *   The promise has a method named "cancel" which cancels the ongoing API call.
     */
    disableSecretVersion(request, optionsOrCallback, callback) {
        request = request || {};
        let options;
        if (typeof optionsOrCallback === 'function' && callback === undefined) {
            callback = optionsOrCallback;
            options = {};
        }
        else {
            options = optionsOrCallback;
        }
        options = options || {};
        options.otherArgs = options.otherArgs || {};
        options.otherArgs.headers = options.otherArgs.headers || {};
        options.otherArgs.headers['x-goog-request-params'] = gax.routingHeader.fromParams({
            name: request.name || '',
        });
        return this._innerApiCalls.disableSecretVersion(request, options, callback);
    }
    /**
     * Enables a [SecretVersion][google.cloud.secrets.v1beta1.SecretVersion].
     *
     * Sets the [state][google.cloud.secrets.v1beta1.SecretVersion.state] of the [SecretVersion][google.cloud.secrets.v1beta1.SecretVersion] to
     * [ENABLED][google.cloud.secrets.v1beta1.SecretVersion.State.ENABLED].
     *
     * @param {Object} request
     *   The request object that will be sent.
     * @param {string} request.name
     *   Required. The resource name of the [SecretVersion][google.cloud.secrets.v1beta1.SecretVersion] to enable in the format
     *   `projects/* /secrets/* /versions/*`.
     * @param {object} [options]
     *   Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details.
     * @returns {Promise} - The promise which resolves to an array.
     *   The first element of the array is an object representing [SecretVersion]{@link google.cloud.secrets.v1beta1.SecretVersion}.
     *   The promise has a method named "cancel" which cancels the ongoing API call.
     */
    enableSecretVersion(request, optionsOrCallback, callback) {
        request = request || {};
        let options;
        if (typeof optionsOrCallback === 'function' && callback === undefined) {
            callback = optionsOrCallback;
            options = {};
        }
        else {
            options = optionsOrCallback;
        }
        options = options || {};
        options.otherArgs = options.otherArgs || {};
        options.otherArgs.headers = options.otherArgs.headers || {};
        options.otherArgs.headers['x-goog-request-params'] = gax.routingHeader.fromParams({
            name: request.name || '',
        });
        return this._innerApiCalls.enableSecretVersion(request, options, callback);
    }
    /**
     * Destroys a [SecretVersion][google.cloud.secrets.v1beta1.SecretVersion].
     *
     * Sets the [state][google.cloud.secrets.v1beta1.SecretVersion.state] of the [SecretVersion][google.cloud.secrets.v1beta1.SecretVersion] to
     * [DESTROYED][google.cloud.secrets.v1beta1.SecretVersion.State.DESTROYED] and irrevocably destroys the
     * secret data.
     *
     * @param {Object} request
     *   The request object that will be sent.
     * @param {string} request.name
     *   Required. The resource name of the [SecretVersion][google.cloud.secrets.v1beta1.SecretVersion] to destroy in the format
     *   `projects/* /secrets/* /versions/*`.
     * @param {object} [options]
     *   Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details.
     * @returns {Promise} - The promise which resolves to an array.
     *   The first element of the array is an object representing [SecretVersion]{@link google.cloud.secrets.v1beta1.SecretVersion}.
     *   The promise has a method named "cancel" which cancels the ongoing API call.
     */
    destroySecretVersion(request, optionsOrCallback, callback) {
        request = request || {};
        let options;
        if (typeof optionsOrCallback === 'function' && callback === undefined) {
            callback = optionsOrCallback;
            options = {};
        }
        else {
            options = optionsOrCallback;
        }
        options = options || {};
        options.otherArgs = options.otherArgs || {};
        options.otherArgs.headers = options.otherArgs.headers || {};
        options.otherArgs.headers['x-goog-request-params'] = gax.routingHeader.fromParams({
            name: request.name || '',
        });
        return this._innerApiCalls.destroySecretVersion(request, options, callback);
    }
    /**
     * Sets the access control policy on the specified secret. Replaces any
     * existing policy.
     *
     * Permissions on [SecretVersions][google.cloud.secrets.v1beta1.SecretVersion] are enforced according
     * to the policy set on the associated [Secret][google.cloud.secrets.v1beta1.Secret].
     *
     * @param {Object} request
     *   The request object that will be sent.
     * @param {object} [options]
     *   Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details.
     * @returns {Promise} - The promise which resolves to an array.
     *   The first element of the array is an object representing [Policy]{@link google.iam.v1.Policy}.
     *   The promise has a method named "cancel" which cancels the ongoing API call.
     */
    setIamPolicy(request, optionsOrCallback, callback) {
        request = request || {};
        let options;
        if (typeof optionsOrCallback === 'function' && callback === undefined) {
            callback = optionsOrCallback;
            options = {};
        }
        else {
            options = optionsOrCallback;
        }
        options = options || {};
        options.otherArgs = options.otherArgs || {};
        options.otherArgs.headers = options.otherArgs.headers || {};
        options.otherArgs.headers['x-goog-request-params'] = gax.routingHeader.fromParams({
            resource: request.resource || '',
        });
        return this._innerApiCalls.setIamPolicy(request, options, callback);
    }
    /**
     * Gets the access control policy for a secret.
     * Returns empty policy if the secret exists and does not have a policy set.
     *
     * @param {Object} request
     *   The request object that will be sent.
     * @param {object} [options]
     *   Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details.
     * @returns {Promise} - The promise which resolves to an array.
     *   The first element of the array is an object representing [Policy]{@link google.iam.v1.Policy}.
     *   The promise has a method named "cancel" which cancels the ongoing API call.
     */
    getIamPolicy(request, optionsOrCallback, callback) {
        request = request || {};
        let options;
        if (typeof optionsOrCallback === 'function' && callback === undefined) {
            callback = optionsOrCallback;
            options = {};
        }
        else {
            options = optionsOrCallback;
        }
        options = options || {};
        options.otherArgs = options.otherArgs || {};
        options.otherArgs.headers = options.otherArgs.headers || {};
        options.otherArgs.headers['x-goog-request-params'] = gax.routingHeader.fromParams({
            resource: request.resource || '',
        });
        return this._innerApiCalls.getIamPolicy(request, options, callback);
    }
    /**
     * Returns permissions that a caller has for the specified secret.
     * If the secret does not exist, this call returns an empty set of
     * permissions, not a NOT_FOUND error.
     *
     * Note: This operation is designed to be used for building permission-aware
     * UIs and command-line tools, not for authorization checking. This operation
     * may "fail open" without warning.
     *
     * @param {Object} request
     *   The request object that will be sent.
     * @param {object} [options]
     *   Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details.
     * @returns {Promise} - The promise which resolves to an array.
     *   The first element of the array is an object representing [TestIamPermissionsResponse]{@link google.iam.v1.TestIamPermissionsResponse}.
     *   The promise has a method named "cancel" which cancels the ongoing API call.
     */
    testIamPermissions(request, optionsOrCallback, callback) {
        request = request || {};
        let options;
        if (typeof optionsOrCallback === 'function' && callback === undefined) {
            callback = optionsOrCallback;
            options = {};
        }
        else {
            options = optionsOrCallback;
        }
        options = options || {};
        options.otherArgs = options.otherArgs || {};
        options.otherArgs.headers = options.otherArgs.headers || {};
        options.otherArgs.headers['x-goog-request-params'] = gax.routingHeader.fromParams({
            resource: request.resource || '',
        });
        return this._innerApiCalls.testIamPermissions(request, options, callback);
    }
    /**
     * Lists [Secrets][google.cloud.secrets.v1beta1.Secret].
     *
     * @param {Object} request
     *   The request object that will be sent.
     * @param {string} request.parent
     *   Required. The resource name of the project associated with the
     *   [Secrets][google.cloud.secrets.v1beta1.Secret], in the format `projects/*`.
     * @param {number} [request.pageSize]
     *   Optional. The maximum number of results to be returned in a single page. If
     *   set to 0, the server decides the number of results to return. If the
     *   number is greater than 25000, it is capped at 25000.
     * @param {string} [request.pageToken]
     *   Optional. Pagination token, returned earlier via
     *   [ListSecretsResponse.next_page_token][google.cloud.secrets.v1beta1.ListSecretsResponse.next_page_token].
     * @param {object} [options]
     *   Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details.
     * @returns {Promise} - The promise which resolves to an array.
     *   The first element of the array is Array of [Secret]{@link google.cloud.secrets.v1beta1.Secret}.
     *   The client library support auto-pagination by default: it will call the API as many
     *   times as needed and will merge results from all the pages into this array.
     *
     *   When autoPaginate: false is specified through options, the array has three elements.
     *   The first element is Array of [Secret]{@link google.cloud.secrets.v1beta1.Secret} that corresponds to
     *   the one page received from the API server.
     *   If the second element is not null it contains the request object of type [ListSecretsRequest]{@link google.cloud.secrets.v1beta1.ListSecretsRequest}
     *   that can be used to obtain the next page of the results.
     *   If it is null, the next page does not exist.
     *   The third element contains the raw response received from the API server. Its type is
     *   [ListSecretsResponse]{@link google.cloud.secrets.v1beta1.ListSecretsResponse}.
     *
     *   The promise has a method named "cancel" which cancels the ongoing API call.
     */
    listSecrets(request, optionsOrCallback, callback) {
        request = request || {};
        let options;
        if (typeof optionsOrCallback === 'function' && callback === undefined) {
            callback = optionsOrCallback;
            options = {};
        }
        else {
            options = optionsOrCallback;
        }
        options = options || {};
        options.otherArgs = options.otherArgs || {};
        options.otherArgs.headers = options.otherArgs.headers || {};
        options.otherArgs.headers['x-goog-request-params'] = gax.routingHeader.fromParams({
            parent: request.parent || '',
        });
        return this._innerApiCalls.listSecrets(request, options, callback);
    }
    /**
     * Equivalent to {@link listSecrets}, but returns a NodeJS Stream object.
     *
     * This fetches the paged responses for {@link listSecrets} continuously
     * and invokes the callback registered for 'data' event for each element in the
     * responses.
     *
     * The returned object has 'end' method when no more elements are required.
     *
     * autoPaginate option will be ignored.
     *
     * @see {@link https://nodejs.org/api/stream.html}
     *
     * @param {Object} request
     *   The request object that will be sent.
     * @param {string} request.parent
     *   Required. The resource name of the project associated with the
     *   [Secrets][google.cloud.secrets.v1beta1.Secret], in the format `projects/*`.
     * @param {number} [request.pageSize]
     *   Optional. The maximum number of results to be returned in a single page. If
     *   set to 0, the server decides the number of results to return. If the
     *   number is greater than 25000, it is capped at 25000.
     * @param {string} [request.pageToken]
     *   Optional. Pagination token, returned earlier via
     *   [ListSecretsResponse.next_page_token][google.cloud.secrets.v1beta1.ListSecretsResponse.next_page_token].
     * @param {object} [options]
     *   Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details.
     * @returns {Stream}
     *   An object stream which emits an object representing [Secret]{@link google.cloud.secrets.v1beta1.Secret} on 'data' event.
     */
    listSecretsStream(request, options) {
        request = request || {};
        const callSettings = new gax.CallSettings(options);
        return this._descriptors.page.listSecrets.createStream(this._innerApiCalls.listSecrets, request, callSettings);
    }
    /**
     * Lists [SecretVersions][google.cloud.secrets.v1beta1.SecretVersion]. This call does not return secret
     * data.
     *
     * @param {Object} request
     *   The request object that will be sent.
     * @param {string} request.parent
     *   Required. The resource name of the [Secret][google.cloud.secrets.v1beta1.Secret] associated with the
     *   [SecretVersions][google.cloud.secrets.v1beta1.SecretVersion] to list, in the format
     *   `projects/* /secrets/*`.
     * @param {number} [request.pageSize]
     *   Optional. The maximum number of results to be returned in a single page. If
     *   set to 0, the server decides the number of results to return. If the
     *   number is greater than 25000, it is capped at 25000.
     * @param {string} [request.pageToken]
     *   Optional. Pagination token, returned earlier via
     *   ListSecretVersionsResponse.next_page_token][].
     * @param {object} [options]
     *   Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details.
     * @returns {Promise} - The promise which resolves to an array.
     *   The first element of the array is Array of [SecretVersion]{@link google.cloud.secrets.v1beta1.SecretVersion}.
     *   The client library support auto-pagination by default: it will call the API as many
     *   times as needed and will merge results from all the pages into this array.
     *
     *   When autoPaginate: false is specified through options, the array has three elements.
     *   The first element is Array of [SecretVersion]{@link google.cloud.secrets.v1beta1.SecretVersion} that corresponds to
     *   the one page received from the API server.
     *   If the second element is not null it contains the request object of type [ListSecretVersionsRequest]{@link google.cloud.secrets.v1beta1.ListSecretVersionsRequest}
     *   that can be used to obtain the next page of the results.
     *   If it is null, the next page does not exist.
     *   The third element contains the raw response received from the API server. Its type is
     *   [ListSecretVersionsResponse]{@link google.cloud.secrets.v1beta1.ListSecretVersionsResponse}.
     *
     *   The promise has a method named "cancel" which cancels the ongoing API call.
     */
    listSecretVersions(request, optionsOrCallback, callback) {
        request = request || {};
        let options;
        if (typeof optionsOrCallback === 'function' && callback === undefined) {
            callback = optionsOrCallback;
            options = {};
        }
        else {
            options = optionsOrCallback;
        }
        options = options || {};
        options.otherArgs = options.otherArgs || {};
        options.otherArgs.headers = options.otherArgs.headers || {};
        options.otherArgs.headers['x-goog-request-params'] = gax.routingHeader.fromParams({
            parent: request.parent || '',
        });
        return this._innerApiCalls.listSecretVersions(request, options, callback);
    }
    /**
     * Equivalent to {@link listSecretVersions}, but returns a NodeJS Stream object.
     *
     * This fetches the paged responses for {@link listSecretVersions} continuously
     * and invokes the callback registered for 'data' event for each element in the
     * responses.
     *
     * The returned object has 'end' method when no more elements are required.
     *
     * autoPaginate option will be ignored.
     *
     * @see {@link https://nodejs.org/api/stream.html}
     *
     * @param {Object} request
     *   The request object that will be sent.
     * @param {string} request.parent
     *   Required. The resource name of the [Secret][google.cloud.secrets.v1beta1.Secret] associated with the
     *   [SecretVersions][google.cloud.secrets.v1beta1.SecretVersion] to list, in the format
     *   `projects/* /secrets/*`.
     * @param {number} [request.pageSize]
     *   Optional. The maximum number of results to be returned in a single page. If
     *   set to 0, the server decides the number of results to return. If the
     *   number is greater than 25000, it is capped at 25000.
     * @param {string} [request.pageToken]
     *   Optional. Pagination token, returned earlier via
     *   ListSecretVersionsResponse.next_page_token][].
     * @param {object} [options]
     *   Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details.
     * @returns {Stream}
     *   An object stream which emits an object representing [SecretVersion]{@link google.cloud.secrets.v1beta1.SecretVersion} on 'data' event.
     */
    listSecretVersionsStream(request, options) {
        request = request || {};
        const callSettings = new gax.CallSettings(options);
        return this._descriptors.page.listSecretVersions.createStream(this._innerApiCalls.listSecretVersions, request, callSettings);
    }
    // --------------------
    // -- Path templates --
    // --------------------
    /**
     * Return a fully-qualified secret resource name string.
     *
     * @param {string} project
     * @param {string} secret
     * @returns {string} Resource name string.
     */
    secretPath(project, secret) {
        return this._pathTemplates.secretPathTemplate.render({
            project,
            secret,
        });
    }
    /**
     * Parse the project from Secret resource.
     *
     * @param {string} secretName
     *   A fully-qualified path representing Secret resource.
     * @returns {string} A string representing the project.
     */
    matchProjectFromSecretName(secretName) {
        return this._pathTemplates.secretPathTemplate.match(secretName).project;
    }
    /**
     * Parse the secret from Secret resource.
     *
     * @param {string} secretName
     *   A fully-qualified path representing Secret resource.
     * @returns {string} A string representing the secret.
     */
    matchSecretFromSecretName(secretName) {
        return this._pathTemplates.secretPathTemplate.match(secretName).secret;
    }
    /**
     * Return a fully-qualified secretversion resource name string.
     *
     * @param {string} project
     * @param {string} secret
     * @returns {string} Resource name string.
     */
    secretVersionPath(project, secret) {
        return this._pathTemplates.secretversionPathTemplate.render({
            project,
            secret,
        });
    }
    /**
     * Parse the project from SecretVersion resource.
     *
     * @param {string} secretversionName
     *   A fully-qualified path representing SecretVersion resource.
     * @returns {string} A string representing the project.
     */
    matchProjectFromSecretVersionName(secretversionName) {
        return this._pathTemplates.secretversionPathTemplate.match(secretversionName).project;
    }
    /**
     * Parse the secret from SecretVersion resource.
     *
     * @param {string} secretversionName
     *   A fully-qualified path representing SecretVersion resource.
     * @returns {string} A string representing the secret.
     */
    matchSecretFromSecretVersionName(secretversionName) {
        return this._pathTemplates.secretversionPathTemplate.match(secretversionName).secret;
    }
    /**
     * Terminate the GRPC channel and close the client.
     *
     * The client will no longer be usable and all future behavior is undefined.
     */
    close() {
        if (!this._terminated) {
            return this.secretManagerServiceStub.then(stub => {
                this._terminated = true;
                stub.close();
            });
        }
        return Promise.resolve();
    }
}
exports.SecretManagerServiceClient = SecretManagerServiceClient;
//# sourceMappingURL=secret_manager_service_client.js.map