diff --git a/protos/google/spanner/admin/database/v1/spanner_database_admin.proto b/protos/google/spanner/admin/database/v1/spanner_database_admin.proto index 38023e072..91489ae4b 100644 --- a/protos/google/spanner/admin/database/v1/spanner_database_admin.proto +++ b/protos/google/spanner/admin/database/v1/spanner_database_admin.proto @@ -187,6 +187,10 @@ service DatabaseAdmin { post: "/v1/{resource=projects/*/instances/*/backups/*}:testIamPermissions" body: "*" } + additional_bindings { + post: "/v1/{resource=projects/*/instances/*/databases/*/databaseRoles/*}:testIamPermissions" + body: "*" + } }; option (google.api.method_signature) = "resource,permissions"; } @@ -334,6 +338,14 @@ service DatabaseAdmin { }; option (google.api.method_signature) = "parent"; } + + // Lists Cloud Spanner database roles. + rpc ListDatabaseRoles(ListDatabaseRolesRequest) returns (ListDatabaseRolesResponse) { + option (google.api.http) = { + get: "/v1/{parent=projects/*/instances/*/databases/*}/databaseRoles" + }; + option (google.api.method_signature) = "parent"; + } } // Information about the database restore. @@ -868,3 +880,51 @@ enum RestoreSourceType { // A backup was used as the source of the restore. BACKUP = 1; } + +// A Cloud Spanner database role. +message DatabaseRole { + option (google.api.resource) = { + type: "spanner.googleapis.com/DatabaseRole" + pattern: "projects/{project}/instances/{instance}/databases/{database}/databaseRoles/{role}" + }; + + // Required. The name of the database role. Values are of the form + // `projects//instances//databases//databaseRoles/ + // {role}`, where `` is as specified in the `CREATE ROLE` + // DDL statement. This name can be passed to Get/Set IAMPolicy methods to + // identify the database role. + string name = 1 [(google.api.field_behavior) = REQUIRED]; +} + +// The request for [ListDatabaseRoles][google.spanner.admin.database.v1.DatabaseAdmin.ListDatabaseRoles]. +message ListDatabaseRolesRequest { + // Required. The database whose roles should be listed. + // Values are of the form + // `projects//instances//databases//databaseRoles`. + string parent = 1 [ + (google.api.field_behavior) = REQUIRED, + (google.api.resource_reference) = { + type: "spanner.googleapis.com/Database" + } + ]; + + // Number of database roles to be returned in the response. If 0 or less, + // defaults to the server's maximum allowed page size. + int32 page_size = 2; + + // If non-empty, `page_token` should contain a + // [next_page_token][google.spanner.admin.database.v1.ListDatabaseRolesResponse.next_page_token] from a + // previous [ListDatabaseRolesResponse][google.spanner.admin.database.v1.ListDatabaseRolesResponse]. + string page_token = 3; +} + +// The response for [ListDatabaseRoles][google.spanner.admin.database.v1.DatabaseAdmin.ListDatabaseRoles]. +message ListDatabaseRolesResponse { + // Database roles that matched the request. + repeated DatabaseRole database_roles = 1; + + // `next_page_token` can be sent in a subsequent + // [ListDatabaseRoles][google.spanner.admin.database.v1.DatabaseAdmin.ListDatabaseRoles] + // call to fetch more of the matching roles. + string next_page_token = 2; +} diff --git a/protos/protos.d.ts b/protos/protos.d.ts index 6741347a2..3ca40c1d4 100644 --- a/protos/protos.d.ts +++ b/protos/protos.d.ts @@ -7580,6 +7580,20 @@ export namespace google { * @returns Promise */ public listBackupOperations(request: google.spanner.admin.database.v1.IListBackupOperationsRequest): Promise; + + /** + * Calls ListDatabaseRoles. + * @param request ListDatabaseRolesRequest message or plain object + * @param callback Node-style callback called with the error, if any, and ListDatabaseRolesResponse + */ + public listDatabaseRoles(request: google.spanner.admin.database.v1.IListDatabaseRolesRequest, callback: google.spanner.admin.database.v1.DatabaseAdmin.ListDatabaseRolesCallback): void; + + /** + * Calls ListDatabaseRoles. + * @param request ListDatabaseRolesRequest message or plain object + * @returns Promise + */ + public listDatabaseRoles(request: google.spanner.admin.database.v1.IListDatabaseRolesRequest): Promise; } namespace DatabaseAdmin { @@ -7709,6 +7723,13 @@ export namespace google { * @param [response] ListBackupOperationsResponse */ type ListBackupOperationsCallback = (error: (Error|null), response?: google.spanner.admin.database.v1.ListBackupOperationsResponse) => void; + + /** + * Callback as used by {@link google.spanner.admin.database.v1.DatabaseAdmin#listDatabaseRoles}. + * @param error Error, if any + * @param [response] ListDatabaseRolesResponse + */ + type ListDatabaseRolesCallback = (error: (Error|null), response?: google.spanner.admin.database.v1.ListDatabaseRolesResponse) => void; } /** Properties of a RestoreInfo. */ @@ -9589,6 +9610,294 @@ export namespace google { TYPE_UNSPECIFIED = 0, BACKUP = 1 } + + /** Properties of a DatabaseRole. */ + interface IDatabaseRole { + + /** DatabaseRole name */ + name?: (string|null); + } + + /** Represents a DatabaseRole. */ + class DatabaseRole implements IDatabaseRole { + + /** + * Constructs a new DatabaseRole. + * @param [properties] Properties to set + */ + constructor(properties?: google.spanner.admin.database.v1.IDatabaseRole); + + /** DatabaseRole name. */ + public name: string; + + /** + * Creates a new DatabaseRole instance using the specified properties. + * @param [properties] Properties to set + * @returns DatabaseRole instance + */ + public static create(properties?: google.spanner.admin.database.v1.IDatabaseRole): google.spanner.admin.database.v1.DatabaseRole; + + /** + * Encodes the specified DatabaseRole message. Does not implicitly {@link google.spanner.admin.database.v1.DatabaseRole.verify|verify} messages. + * @param message DatabaseRole message or plain object to encode + * @param [writer] Writer to encode to + * @returns Writer + */ + public static encode(message: google.spanner.admin.database.v1.IDatabaseRole, writer?: $protobuf.Writer): $protobuf.Writer; + + /** + * Encodes the specified DatabaseRole message, length delimited. Does not implicitly {@link google.spanner.admin.database.v1.DatabaseRole.verify|verify} messages. + * @param message DatabaseRole message or plain object to encode + * @param [writer] Writer to encode to + * @returns Writer + */ + public static encodeDelimited(message: google.spanner.admin.database.v1.IDatabaseRole, writer?: $protobuf.Writer): $protobuf.Writer; + + /** + * Decodes a DatabaseRole message from the specified reader or buffer. + * @param reader Reader or buffer to decode from + * @param [length] Message length if known beforehand + * @returns DatabaseRole + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + public static decode(reader: ($protobuf.Reader|Uint8Array), length?: number): google.spanner.admin.database.v1.DatabaseRole; + + /** + * Decodes a DatabaseRole message from the specified reader or buffer, length delimited. + * @param reader Reader or buffer to decode from + * @returns DatabaseRole + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + public static decodeDelimited(reader: ($protobuf.Reader|Uint8Array)): google.spanner.admin.database.v1.DatabaseRole; + + /** + * Verifies a DatabaseRole message. + * @param message Plain object to verify + * @returns `null` if valid, otherwise the reason why it is not + */ + public static verify(message: { [k: string]: any }): (string|null); + + /** + * Creates a DatabaseRole message from a plain object. Also converts values to their respective internal types. + * @param object Plain object + * @returns DatabaseRole + */ + public static fromObject(object: { [k: string]: any }): google.spanner.admin.database.v1.DatabaseRole; + + /** + * Creates a plain object from a DatabaseRole message. Also converts values to other types if specified. + * @param message DatabaseRole + * @param [options] Conversion options + * @returns Plain object + */ + public static toObject(message: google.spanner.admin.database.v1.DatabaseRole, options?: $protobuf.IConversionOptions): { [k: string]: any }; + + /** + * Converts this DatabaseRole to JSON. + * @returns JSON object + */ + public toJSON(): { [k: string]: any }; + } + + /** Properties of a ListDatabaseRolesRequest. */ + interface IListDatabaseRolesRequest { + + /** ListDatabaseRolesRequest parent */ + parent?: (string|null); + + /** ListDatabaseRolesRequest pageSize */ + pageSize?: (number|null); + + /** ListDatabaseRolesRequest pageToken */ + pageToken?: (string|null); + } + + /** Represents a ListDatabaseRolesRequest. */ + class ListDatabaseRolesRequest implements IListDatabaseRolesRequest { + + /** + * Constructs a new ListDatabaseRolesRequest. + * @param [properties] Properties to set + */ + constructor(properties?: google.spanner.admin.database.v1.IListDatabaseRolesRequest); + + /** ListDatabaseRolesRequest parent. */ + public parent: string; + + /** ListDatabaseRolesRequest pageSize. */ + public pageSize: number; + + /** ListDatabaseRolesRequest pageToken. */ + public pageToken: string; + + /** + * Creates a new ListDatabaseRolesRequest instance using the specified properties. + * @param [properties] Properties to set + * @returns ListDatabaseRolesRequest instance + */ + public static create(properties?: google.spanner.admin.database.v1.IListDatabaseRolesRequest): google.spanner.admin.database.v1.ListDatabaseRolesRequest; + + /** + * Encodes the specified ListDatabaseRolesRequest message. Does not implicitly {@link google.spanner.admin.database.v1.ListDatabaseRolesRequest.verify|verify} messages. + * @param message ListDatabaseRolesRequest message or plain object to encode + * @param [writer] Writer to encode to + * @returns Writer + */ + public static encode(message: google.spanner.admin.database.v1.IListDatabaseRolesRequest, writer?: $protobuf.Writer): $protobuf.Writer; + + /** + * Encodes the specified ListDatabaseRolesRequest message, length delimited. Does not implicitly {@link google.spanner.admin.database.v1.ListDatabaseRolesRequest.verify|verify} messages. + * @param message ListDatabaseRolesRequest message or plain object to encode + * @param [writer] Writer to encode to + * @returns Writer + */ + public static encodeDelimited(message: google.spanner.admin.database.v1.IListDatabaseRolesRequest, writer?: $protobuf.Writer): $protobuf.Writer; + + /** + * Decodes a ListDatabaseRolesRequest message from the specified reader or buffer. + * @param reader Reader or buffer to decode from + * @param [length] Message length if known beforehand + * @returns ListDatabaseRolesRequest + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + public static decode(reader: ($protobuf.Reader|Uint8Array), length?: number): google.spanner.admin.database.v1.ListDatabaseRolesRequest; + + /** + * Decodes a ListDatabaseRolesRequest message from the specified reader or buffer, length delimited. + * @param reader Reader or buffer to decode from + * @returns ListDatabaseRolesRequest + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + public static decodeDelimited(reader: ($protobuf.Reader|Uint8Array)): google.spanner.admin.database.v1.ListDatabaseRolesRequest; + + /** + * Verifies a ListDatabaseRolesRequest message. + * @param message Plain object to verify + * @returns `null` if valid, otherwise the reason why it is not + */ + public static verify(message: { [k: string]: any }): (string|null); + + /** + * Creates a ListDatabaseRolesRequest message from a plain object. Also converts values to their respective internal types. + * @param object Plain object + * @returns ListDatabaseRolesRequest + */ + public static fromObject(object: { [k: string]: any }): google.spanner.admin.database.v1.ListDatabaseRolesRequest; + + /** + * Creates a plain object from a ListDatabaseRolesRequest message. Also converts values to other types if specified. + * @param message ListDatabaseRolesRequest + * @param [options] Conversion options + * @returns Plain object + */ + public static toObject(message: google.spanner.admin.database.v1.ListDatabaseRolesRequest, options?: $protobuf.IConversionOptions): { [k: string]: any }; + + /** + * Converts this ListDatabaseRolesRequest to JSON. + * @returns JSON object + */ + public toJSON(): { [k: string]: any }; + } + + /** Properties of a ListDatabaseRolesResponse. */ + interface IListDatabaseRolesResponse { + + /** ListDatabaseRolesResponse databaseRoles */ + databaseRoles?: (google.spanner.admin.database.v1.IDatabaseRole[]|null); + + /** ListDatabaseRolesResponse nextPageToken */ + nextPageToken?: (string|null); + } + + /** Represents a ListDatabaseRolesResponse. */ + class ListDatabaseRolesResponse implements IListDatabaseRolesResponse { + + /** + * Constructs a new ListDatabaseRolesResponse. + * @param [properties] Properties to set + */ + constructor(properties?: google.spanner.admin.database.v1.IListDatabaseRolesResponse); + + /** ListDatabaseRolesResponse databaseRoles. */ + public databaseRoles: google.spanner.admin.database.v1.IDatabaseRole[]; + + /** ListDatabaseRolesResponse nextPageToken. */ + public nextPageToken: string; + + /** + * Creates a new ListDatabaseRolesResponse instance using the specified properties. + * @param [properties] Properties to set + * @returns ListDatabaseRolesResponse instance + */ + public static create(properties?: google.spanner.admin.database.v1.IListDatabaseRolesResponse): google.spanner.admin.database.v1.ListDatabaseRolesResponse; + + /** + * Encodes the specified ListDatabaseRolesResponse message. Does not implicitly {@link google.spanner.admin.database.v1.ListDatabaseRolesResponse.verify|verify} messages. + * @param message ListDatabaseRolesResponse message or plain object to encode + * @param [writer] Writer to encode to + * @returns Writer + */ + public static encode(message: google.spanner.admin.database.v1.IListDatabaseRolesResponse, writer?: $protobuf.Writer): $protobuf.Writer; + + /** + * Encodes the specified ListDatabaseRolesResponse message, length delimited. Does not implicitly {@link google.spanner.admin.database.v1.ListDatabaseRolesResponse.verify|verify} messages. + * @param message ListDatabaseRolesResponse message or plain object to encode + * @param [writer] Writer to encode to + * @returns Writer + */ + public static encodeDelimited(message: google.spanner.admin.database.v1.IListDatabaseRolesResponse, writer?: $protobuf.Writer): $protobuf.Writer; + + /** + * Decodes a ListDatabaseRolesResponse message from the specified reader or buffer. + * @param reader Reader or buffer to decode from + * @param [length] Message length if known beforehand + * @returns ListDatabaseRolesResponse + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + public static decode(reader: ($protobuf.Reader|Uint8Array), length?: number): google.spanner.admin.database.v1.ListDatabaseRolesResponse; + + /** + * Decodes a ListDatabaseRolesResponse message from the specified reader or buffer, length delimited. + * @param reader Reader or buffer to decode from + * @returns ListDatabaseRolesResponse + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + public static decodeDelimited(reader: ($protobuf.Reader|Uint8Array)): google.spanner.admin.database.v1.ListDatabaseRolesResponse; + + /** + * Verifies a ListDatabaseRolesResponse message. + * @param message Plain object to verify + * @returns `null` if valid, otherwise the reason why it is not + */ + public static verify(message: { [k: string]: any }): (string|null); + + /** + * Creates a ListDatabaseRolesResponse message from a plain object. Also converts values to their respective internal types. + * @param object Plain object + * @returns ListDatabaseRolesResponse + */ + public static fromObject(object: { [k: string]: any }): google.spanner.admin.database.v1.ListDatabaseRolesResponse; + + /** + * Creates a plain object from a ListDatabaseRolesResponse message. Also converts values to other types if specified. + * @param message ListDatabaseRolesResponse + * @param [options] Conversion options + * @returns Plain object + */ + public static toObject(message: google.spanner.admin.database.v1.ListDatabaseRolesResponse, options?: $protobuf.IConversionOptions): { [k: string]: any }; + + /** + * Converts this ListDatabaseRolesResponse to JSON. + * @returns JSON object + */ + public toJSON(): { [k: string]: any }; + } } } diff --git a/protos/protos.js b/protos/protos.js index b65c0f521..fa61cbdec 100644 --- a/protos/protos.js +++ b/protos/protos.js @@ -19268,6 +19268,39 @@ * @variation 2 */ + /** + * Callback as used by {@link google.spanner.admin.database.v1.DatabaseAdmin#listDatabaseRoles}. + * @memberof google.spanner.admin.database.v1.DatabaseAdmin + * @typedef ListDatabaseRolesCallback + * @type {function} + * @param {Error|null} error Error, if any + * @param {google.spanner.admin.database.v1.ListDatabaseRolesResponse} [response] ListDatabaseRolesResponse + */ + + /** + * Calls ListDatabaseRoles. + * @function listDatabaseRoles + * @memberof google.spanner.admin.database.v1.DatabaseAdmin + * @instance + * @param {google.spanner.admin.database.v1.IListDatabaseRolesRequest} request ListDatabaseRolesRequest message or plain object + * @param {google.spanner.admin.database.v1.DatabaseAdmin.ListDatabaseRolesCallback} callback Node-style callback called with the error, if any, and ListDatabaseRolesResponse + * @returns {undefined} + * @variation 1 + */ + Object.defineProperty(DatabaseAdmin.prototype.listDatabaseRoles = function listDatabaseRoles(request, callback) { + return this.rpcCall(listDatabaseRoles, $root.google.spanner.admin.database.v1.ListDatabaseRolesRequest, $root.google.spanner.admin.database.v1.ListDatabaseRolesResponse, request, callback); + }, "name", { value: "ListDatabaseRoles" }); + + /** + * Calls ListDatabaseRoles. + * @function listDatabaseRoles + * @memberof google.spanner.admin.database.v1.DatabaseAdmin + * @instance + * @param {google.spanner.admin.database.v1.IListDatabaseRolesRequest} request ListDatabaseRolesRequest message or plain object + * @returns {Promise} Promise + * @variation 2 + */ + return DatabaseAdmin; })(); @@ -23909,6 +23942,656 @@ return values; })(); + v1.DatabaseRole = (function() { + + /** + * Properties of a DatabaseRole. + * @memberof google.spanner.admin.database.v1 + * @interface IDatabaseRole + * @property {string|null} [name] DatabaseRole name + */ + + /** + * Constructs a new DatabaseRole. + * @memberof google.spanner.admin.database.v1 + * @classdesc Represents a DatabaseRole. + * @implements IDatabaseRole + * @constructor + * @param {google.spanner.admin.database.v1.IDatabaseRole=} [properties] Properties to set + */ + function DatabaseRole(properties) { + if (properties) + for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i) + if (properties[keys[i]] != null) + this[keys[i]] = properties[keys[i]]; + } + + /** + * DatabaseRole name. + * @member {string} name + * @memberof google.spanner.admin.database.v1.DatabaseRole + * @instance + */ + DatabaseRole.prototype.name = ""; + + /** + * Creates a new DatabaseRole instance using the specified properties. + * @function create + * @memberof google.spanner.admin.database.v1.DatabaseRole + * @static + * @param {google.spanner.admin.database.v1.IDatabaseRole=} [properties] Properties to set + * @returns {google.spanner.admin.database.v1.DatabaseRole} DatabaseRole instance + */ + DatabaseRole.create = function create(properties) { + return new DatabaseRole(properties); + }; + + /** + * Encodes the specified DatabaseRole message. Does not implicitly {@link google.spanner.admin.database.v1.DatabaseRole.verify|verify} messages. + * @function encode + * @memberof google.spanner.admin.database.v1.DatabaseRole + * @static + * @param {google.spanner.admin.database.v1.IDatabaseRole} message DatabaseRole message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + DatabaseRole.encode = function encode(message, writer) { + if (!writer) + writer = $Writer.create(); + if (message.name != null && Object.hasOwnProperty.call(message, "name")) + writer.uint32(/* id 1, wireType 2 =*/10).string(message.name); + return writer; + }; + + /** + * Encodes the specified DatabaseRole message, length delimited. Does not implicitly {@link google.spanner.admin.database.v1.DatabaseRole.verify|verify} messages. + * @function encodeDelimited + * @memberof google.spanner.admin.database.v1.DatabaseRole + * @static + * @param {google.spanner.admin.database.v1.IDatabaseRole} message DatabaseRole message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + DatabaseRole.encodeDelimited = function encodeDelimited(message, writer) { + return this.encode(message, writer).ldelim(); + }; + + /** + * Decodes a DatabaseRole message from the specified reader or buffer. + * @function decode + * @memberof google.spanner.admin.database.v1.DatabaseRole + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @param {number} [length] Message length if known beforehand + * @returns {google.spanner.admin.database.v1.DatabaseRole} DatabaseRole + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + DatabaseRole.decode = function decode(reader, length) { + if (!(reader instanceof $Reader)) + reader = $Reader.create(reader); + var end = length === undefined ? reader.len : reader.pos + length, message = new $root.google.spanner.admin.database.v1.DatabaseRole(); + while (reader.pos < end) { + var tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.name = reader.string(); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }; + + /** + * Decodes a DatabaseRole message from the specified reader or buffer, length delimited. + * @function decodeDelimited + * @memberof google.spanner.admin.database.v1.DatabaseRole + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @returns {google.spanner.admin.database.v1.DatabaseRole} DatabaseRole + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + DatabaseRole.decodeDelimited = function decodeDelimited(reader) { + if (!(reader instanceof $Reader)) + reader = new $Reader(reader); + return this.decode(reader, reader.uint32()); + }; + + /** + * Verifies a DatabaseRole message. + * @function verify + * @memberof google.spanner.admin.database.v1.DatabaseRole + * @static + * @param {Object.} message Plain object to verify + * @returns {string|null} `null` if valid, otherwise the reason why it is not + */ + DatabaseRole.verify = function verify(message) { + if (typeof message !== "object" || message === null) + return "object expected"; + if (message.name != null && message.hasOwnProperty("name")) + if (!$util.isString(message.name)) + return "name: string expected"; + return null; + }; + + /** + * Creates a DatabaseRole message from a plain object. Also converts values to their respective internal types. + * @function fromObject + * @memberof google.spanner.admin.database.v1.DatabaseRole + * @static + * @param {Object.} object Plain object + * @returns {google.spanner.admin.database.v1.DatabaseRole} DatabaseRole + */ + DatabaseRole.fromObject = function fromObject(object) { + if (object instanceof $root.google.spanner.admin.database.v1.DatabaseRole) + return object; + var message = new $root.google.spanner.admin.database.v1.DatabaseRole(); + if (object.name != null) + message.name = String(object.name); + return message; + }; + + /** + * Creates a plain object from a DatabaseRole message. Also converts values to other types if specified. + * @function toObject + * @memberof google.spanner.admin.database.v1.DatabaseRole + * @static + * @param {google.spanner.admin.database.v1.DatabaseRole} message DatabaseRole + * @param {$protobuf.IConversionOptions} [options] Conversion options + * @returns {Object.} Plain object + */ + DatabaseRole.toObject = function toObject(message, options) { + if (!options) + options = {}; + var object = {}; + if (options.defaults) + object.name = ""; + if (message.name != null && message.hasOwnProperty("name")) + object.name = message.name; + return object; + }; + + /** + * Converts this DatabaseRole to JSON. + * @function toJSON + * @memberof google.spanner.admin.database.v1.DatabaseRole + * @instance + * @returns {Object.} JSON object + */ + DatabaseRole.prototype.toJSON = function toJSON() { + return this.constructor.toObject(this, $protobuf.util.toJSONOptions); + }; + + return DatabaseRole; + })(); + + v1.ListDatabaseRolesRequest = (function() { + + /** + * Properties of a ListDatabaseRolesRequest. + * @memberof google.spanner.admin.database.v1 + * @interface IListDatabaseRolesRequest + * @property {string|null} [parent] ListDatabaseRolesRequest parent + * @property {number|null} [pageSize] ListDatabaseRolesRequest pageSize + * @property {string|null} [pageToken] ListDatabaseRolesRequest pageToken + */ + + /** + * Constructs a new ListDatabaseRolesRequest. + * @memberof google.spanner.admin.database.v1 + * @classdesc Represents a ListDatabaseRolesRequest. + * @implements IListDatabaseRolesRequest + * @constructor + * @param {google.spanner.admin.database.v1.IListDatabaseRolesRequest=} [properties] Properties to set + */ + function ListDatabaseRolesRequest(properties) { + if (properties) + for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i) + if (properties[keys[i]] != null) + this[keys[i]] = properties[keys[i]]; + } + + /** + * ListDatabaseRolesRequest parent. + * @member {string} parent + * @memberof google.spanner.admin.database.v1.ListDatabaseRolesRequest + * @instance + */ + ListDatabaseRolesRequest.prototype.parent = ""; + + /** + * ListDatabaseRolesRequest pageSize. + * @member {number} pageSize + * @memberof google.spanner.admin.database.v1.ListDatabaseRolesRequest + * @instance + */ + ListDatabaseRolesRequest.prototype.pageSize = 0; + + /** + * ListDatabaseRolesRequest pageToken. + * @member {string} pageToken + * @memberof google.spanner.admin.database.v1.ListDatabaseRolesRequest + * @instance + */ + ListDatabaseRolesRequest.prototype.pageToken = ""; + + /** + * Creates a new ListDatabaseRolesRequest instance using the specified properties. + * @function create + * @memberof google.spanner.admin.database.v1.ListDatabaseRolesRequest + * @static + * @param {google.spanner.admin.database.v1.IListDatabaseRolesRequest=} [properties] Properties to set + * @returns {google.spanner.admin.database.v1.ListDatabaseRolesRequest} ListDatabaseRolesRequest instance + */ + ListDatabaseRolesRequest.create = function create(properties) { + return new ListDatabaseRolesRequest(properties); + }; + + /** + * Encodes the specified ListDatabaseRolesRequest message. Does not implicitly {@link google.spanner.admin.database.v1.ListDatabaseRolesRequest.verify|verify} messages. + * @function encode + * @memberof google.spanner.admin.database.v1.ListDatabaseRolesRequest + * @static + * @param {google.spanner.admin.database.v1.IListDatabaseRolesRequest} message ListDatabaseRolesRequest message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + ListDatabaseRolesRequest.encode = function encode(message, writer) { + if (!writer) + writer = $Writer.create(); + if (message.parent != null && Object.hasOwnProperty.call(message, "parent")) + writer.uint32(/* id 1, wireType 2 =*/10).string(message.parent); + if (message.pageSize != null && Object.hasOwnProperty.call(message, "pageSize")) + writer.uint32(/* id 2, wireType 0 =*/16).int32(message.pageSize); + if (message.pageToken != null && Object.hasOwnProperty.call(message, "pageToken")) + writer.uint32(/* id 3, wireType 2 =*/26).string(message.pageToken); + return writer; + }; + + /** + * Encodes the specified ListDatabaseRolesRequest message, length delimited. Does not implicitly {@link google.spanner.admin.database.v1.ListDatabaseRolesRequest.verify|verify} messages. + * @function encodeDelimited + * @memberof google.spanner.admin.database.v1.ListDatabaseRolesRequest + * @static + * @param {google.spanner.admin.database.v1.IListDatabaseRolesRequest} message ListDatabaseRolesRequest message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + ListDatabaseRolesRequest.encodeDelimited = function encodeDelimited(message, writer) { + return this.encode(message, writer).ldelim(); + }; + + /** + * Decodes a ListDatabaseRolesRequest message from the specified reader or buffer. + * @function decode + * @memberof google.spanner.admin.database.v1.ListDatabaseRolesRequest + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @param {number} [length] Message length if known beforehand + * @returns {google.spanner.admin.database.v1.ListDatabaseRolesRequest} ListDatabaseRolesRequest + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + ListDatabaseRolesRequest.decode = function decode(reader, length) { + if (!(reader instanceof $Reader)) + reader = $Reader.create(reader); + var end = length === undefined ? reader.len : reader.pos + length, message = new $root.google.spanner.admin.database.v1.ListDatabaseRolesRequest(); + while (reader.pos < end) { + var tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.parent = reader.string(); + break; + case 2: + message.pageSize = reader.int32(); + break; + case 3: + message.pageToken = reader.string(); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }; + + /** + * Decodes a ListDatabaseRolesRequest message from the specified reader or buffer, length delimited. + * @function decodeDelimited + * @memberof google.spanner.admin.database.v1.ListDatabaseRolesRequest + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @returns {google.spanner.admin.database.v1.ListDatabaseRolesRequest} ListDatabaseRolesRequest + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + ListDatabaseRolesRequest.decodeDelimited = function decodeDelimited(reader) { + if (!(reader instanceof $Reader)) + reader = new $Reader(reader); + return this.decode(reader, reader.uint32()); + }; + + /** + * Verifies a ListDatabaseRolesRequest message. + * @function verify + * @memberof google.spanner.admin.database.v1.ListDatabaseRolesRequest + * @static + * @param {Object.} message Plain object to verify + * @returns {string|null} `null` if valid, otherwise the reason why it is not + */ + ListDatabaseRolesRequest.verify = function verify(message) { + if (typeof message !== "object" || message === null) + return "object expected"; + if (message.parent != null && message.hasOwnProperty("parent")) + if (!$util.isString(message.parent)) + return "parent: string expected"; + if (message.pageSize != null && message.hasOwnProperty("pageSize")) + if (!$util.isInteger(message.pageSize)) + return "pageSize: integer expected"; + if (message.pageToken != null && message.hasOwnProperty("pageToken")) + if (!$util.isString(message.pageToken)) + return "pageToken: string expected"; + return null; + }; + + /** + * Creates a ListDatabaseRolesRequest message from a plain object. Also converts values to their respective internal types. + * @function fromObject + * @memberof google.spanner.admin.database.v1.ListDatabaseRolesRequest + * @static + * @param {Object.} object Plain object + * @returns {google.spanner.admin.database.v1.ListDatabaseRolesRequest} ListDatabaseRolesRequest + */ + ListDatabaseRolesRequest.fromObject = function fromObject(object) { + if (object instanceof $root.google.spanner.admin.database.v1.ListDatabaseRolesRequest) + return object; + var message = new $root.google.spanner.admin.database.v1.ListDatabaseRolesRequest(); + if (object.parent != null) + message.parent = String(object.parent); + if (object.pageSize != null) + message.pageSize = object.pageSize | 0; + if (object.pageToken != null) + message.pageToken = String(object.pageToken); + return message; + }; + + /** + * Creates a plain object from a ListDatabaseRolesRequest message. Also converts values to other types if specified. + * @function toObject + * @memberof google.spanner.admin.database.v1.ListDatabaseRolesRequest + * @static + * @param {google.spanner.admin.database.v1.ListDatabaseRolesRequest} message ListDatabaseRolesRequest + * @param {$protobuf.IConversionOptions} [options] Conversion options + * @returns {Object.} Plain object + */ + ListDatabaseRolesRequest.toObject = function toObject(message, options) { + if (!options) + options = {}; + var object = {}; + if (options.defaults) { + object.parent = ""; + object.pageSize = 0; + object.pageToken = ""; + } + if (message.parent != null && message.hasOwnProperty("parent")) + object.parent = message.parent; + if (message.pageSize != null && message.hasOwnProperty("pageSize")) + object.pageSize = message.pageSize; + if (message.pageToken != null && message.hasOwnProperty("pageToken")) + object.pageToken = message.pageToken; + return object; + }; + + /** + * Converts this ListDatabaseRolesRequest to JSON. + * @function toJSON + * @memberof google.spanner.admin.database.v1.ListDatabaseRolesRequest + * @instance + * @returns {Object.} JSON object + */ + ListDatabaseRolesRequest.prototype.toJSON = function toJSON() { + return this.constructor.toObject(this, $protobuf.util.toJSONOptions); + }; + + return ListDatabaseRolesRequest; + })(); + + v1.ListDatabaseRolesResponse = (function() { + + /** + * Properties of a ListDatabaseRolesResponse. + * @memberof google.spanner.admin.database.v1 + * @interface IListDatabaseRolesResponse + * @property {Array.|null} [databaseRoles] ListDatabaseRolesResponse databaseRoles + * @property {string|null} [nextPageToken] ListDatabaseRolesResponse nextPageToken + */ + + /** + * Constructs a new ListDatabaseRolesResponse. + * @memberof google.spanner.admin.database.v1 + * @classdesc Represents a ListDatabaseRolesResponse. + * @implements IListDatabaseRolesResponse + * @constructor + * @param {google.spanner.admin.database.v1.IListDatabaseRolesResponse=} [properties] Properties to set + */ + function ListDatabaseRolesResponse(properties) { + this.databaseRoles = []; + if (properties) + for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i) + if (properties[keys[i]] != null) + this[keys[i]] = properties[keys[i]]; + } + + /** + * ListDatabaseRolesResponse databaseRoles. + * @member {Array.} databaseRoles + * @memberof google.spanner.admin.database.v1.ListDatabaseRolesResponse + * @instance + */ + ListDatabaseRolesResponse.prototype.databaseRoles = $util.emptyArray; + + /** + * ListDatabaseRolesResponse nextPageToken. + * @member {string} nextPageToken + * @memberof google.spanner.admin.database.v1.ListDatabaseRolesResponse + * @instance + */ + ListDatabaseRolesResponse.prototype.nextPageToken = ""; + + /** + * Creates a new ListDatabaseRolesResponse instance using the specified properties. + * @function create + * @memberof google.spanner.admin.database.v1.ListDatabaseRolesResponse + * @static + * @param {google.spanner.admin.database.v1.IListDatabaseRolesResponse=} [properties] Properties to set + * @returns {google.spanner.admin.database.v1.ListDatabaseRolesResponse} ListDatabaseRolesResponse instance + */ + ListDatabaseRolesResponse.create = function create(properties) { + return new ListDatabaseRolesResponse(properties); + }; + + /** + * Encodes the specified ListDatabaseRolesResponse message. Does not implicitly {@link google.spanner.admin.database.v1.ListDatabaseRolesResponse.verify|verify} messages. + * @function encode + * @memberof google.spanner.admin.database.v1.ListDatabaseRolesResponse + * @static + * @param {google.spanner.admin.database.v1.IListDatabaseRolesResponse} message ListDatabaseRolesResponse message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + ListDatabaseRolesResponse.encode = function encode(message, writer) { + if (!writer) + writer = $Writer.create(); + if (message.databaseRoles != null && message.databaseRoles.length) + for (var i = 0; i < message.databaseRoles.length; ++i) + $root.google.spanner.admin.database.v1.DatabaseRole.encode(message.databaseRoles[i], writer.uint32(/* id 1, wireType 2 =*/10).fork()).ldelim(); + if (message.nextPageToken != null && Object.hasOwnProperty.call(message, "nextPageToken")) + writer.uint32(/* id 2, wireType 2 =*/18).string(message.nextPageToken); + return writer; + }; + + /** + * Encodes the specified ListDatabaseRolesResponse message, length delimited. Does not implicitly {@link google.spanner.admin.database.v1.ListDatabaseRolesResponse.verify|verify} messages. + * @function encodeDelimited + * @memberof google.spanner.admin.database.v1.ListDatabaseRolesResponse + * @static + * @param {google.spanner.admin.database.v1.IListDatabaseRolesResponse} message ListDatabaseRolesResponse message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + ListDatabaseRolesResponse.encodeDelimited = function encodeDelimited(message, writer) { + return this.encode(message, writer).ldelim(); + }; + + /** + * Decodes a ListDatabaseRolesResponse message from the specified reader or buffer. + * @function decode + * @memberof google.spanner.admin.database.v1.ListDatabaseRolesResponse + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @param {number} [length] Message length if known beforehand + * @returns {google.spanner.admin.database.v1.ListDatabaseRolesResponse} ListDatabaseRolesResponse + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + ListDatabaseRolesResponse.decode = function decode(reader, length) { + if (!(reader instanceof $Reader)) + reader = $Reader.create(reader); + var end = length === undefined ? reader.len : reader.pos + length, message = new $root.google.spanner.admin.database.v1.ListDatabaseRolesResponse(); + while (reader.pos < end) { + var tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + if (!(message.databaseRoles && message.databaseRoles.length)) + message.databaseRoles = []; + message.databaseRoles.push($root.google.spanner.admin.database.v1.DatabaseRole.decode(reader, reader.uint32())); + break; + case 2: + message.nextPageToken = reader.string(); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }; + + /** + * Decodes a ListDatabaseRolesResponse message from the specified reader or buffer, length delimited. + * @function decodeDelimited + * @memberof google.spanner.admin.database.v1.ListDatabaseRolesResponse + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @returns {google.spanner.admin.database.v1.ListDatabaseRolesResponse} ListDatabaseRolesResponse + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + ListDatabaseRolesResponse.decodeDelimited = function decodeDelimited(reader) { + if (!(reader instanceof $Reader)) + reader = new $Reader(reader); + return this.decode(reader, reader.uint32()); + }; + + /** + * Verifies a ListDatabaseRolesResponse message. + * @function verify + * @memberof google.spanner.admin.database.v1.ListDatabaseRolesResponse + * @static + * @param {Object.} message Plain object to verify + * @returns {string|null} `null` if valid, otherwise the reason why it is not + */ + ListDatabaseRolesResponse.verify = function verify(message) { + if (typeof message !== "object" || message === null) + return "object expected"; + if (message.databaseRoles != null && message.hasOwnProperty("databaseRoles")) { + if (!Array.isArray(message.databaseRoles)) + return "databaseRoles: array expected"; + for (var i = 0; i < message.databaseRoles.length; ++i) { + var error = $root.google.spanner.admin.database.v1.DatabaseRole.verify(message.databaseRoles[i]); + if (error) + return "databaseRoles." + error; + } + } + if (message.nextPageToken != null && message.hasOwnProperty("nextPageToken")) + if (!$util.isString(message.nextPageToken)) + return "nextPageToken: string expected"; + return null; + }; + + /** + * Creates a ListDatabaseRolesResponse message from a plain object. Also converts values to their respective internal types. + * @function fromObject + * @memberof google.spanner.admin.database.v1.ListDatabaseRolesResponse + * @static + * @param {Object.} object Plain object + * @returns {google.spanner.admin.database.v1.ListDatabaseRolesResponse} ListDatabaseRolesResponse + */ + ListDatabaseRolesResponse.fromObject = function fromObject(object) { + if (object instanceof $root.google.spanner.admin.database.v1.ListDatabaseRolesResponse) + return object; + var message = new $root.google.spanner.admin.database.v1.ListDatabaseRolesResponse(); + if (object.databaseRoles) { + if (!Array.isArray(object.databaseRoles)) + throw TypeError(".google.spanner.admin.database.v1.ListDatabaseRolesResponse.databaseRoles: array expected"); + message.databaseRoles = []; + for (var i = 0; i < object.databaseRoles.length; ++i) { + if (typeof object.databaseRoles[i] !== "object") + throw TypeError(".google.spanner.admin.database.v1.ListDatabaseRolesResponse.databaseRoles: object expected"); + message.databaseRoles[i] = $root.google.spanner.admin.database.v1.DatabaseRole.fromObject(object.databaseRoles[i]); + } + } + if (object.nextPageToken != null) + message.nextPageToken = String(object.nextPageToken); + return message; + }; + + /** + * Creates a plain object from a ListDatabaseRolesResponse message. Also converts values to other types if specified. + * @function toObject + * @memberof google.spanner.admin.database.v1.ListDatabaseRolesResponse + * @static + * @param {google.spanner.admin.database.v1.ListDatabaseRolesResponse} message ListDatabaseRolesResponse + * @param {$protobuf.IConversionOptions} [options] Conversion options + * @returns {Object.} Plain object + */ + ListDatabaseRolesResponse.toObject = function toObject(message, options) { + if (!options) + options = {}; + var object = {}; + if (options.arrays || options.defaults) + object.databaseRoles = []; + if (options.defaults) + object.nextPageToken = ""; + if (message.databaseRoles && message.databaseRoles.length) { + object.databaseRoles = []; + for (var j = 0; j < message.databaseRoles.length; ++j) + object.databaseRoles[j] = $root.google.spanner.admin.database.v1.DatabaseRole.toObject(message.databaseRoles[j], options); + } + if (message.nextPageToken != null && message.hasOwnProperty("nextPageToken")) + object.nextPageToken = message.nextPageToken; + return object; + }; + + /** + * Converts this ListDatabaseRolesResponse to JSON. + * @function toJSON + * @memberof google.spanner.admin.database.v1.ListDatabaseRolesResponse + * @instance + * @returns {Object.} JSON object + */ + ListDatabaseRolesResponse.prototype.toJSON = function toJSON() { + return this.constructor.toObject(this, $protobuf.util.toJSONOptions); + }; + + return ListDatabaseRolesResponse; + })(); + return v1; })(); diff --git a/protos/protos.json b/protos/protos.json index 6f7657d9d..0385e5618 100644 --- a/protos/protos.json +++ b/protos/protos.json @@ -1931,7 +1931,7 @@ "options": { "(google.api.http).post": "/v1/{resource=projects/*/instances/*/databases/*}:testIamPermissions", "(google.api.http).body": "*", - "(google.api.http).additional_bindings.post": "/v1/{resource=projects/*/instances/*/backups/*}:testIamPermissions", + "(google.api.http).additional_bindings.post": "/v1/{resource=projects/*/instances/*/databases/*/databaseRoles/*}:testIamPermissions", "(google.api.http).additional_bindings.body": "*", "(google.api.method_signature)": "resource,permissions" }, @@ -1940,10 +1940,16 @@ "(google.api.http)": { "post": "/v1/{resource=projects/*/instances/*/databases/*}:testIamPermissions", "body": "*", - "additional_bindings": { - "post": "/v1/{resource=projects/*/instances/*/backups/*}:testIamPermissions", - "body": "*" - } + "additional_bindings": [ + { + "post": "/v1/{resource=projects/*/instances/*/backups/*}:testIamPermissions", + "body": "*" + }, + { + "post": "/v1/{resource=projects/*/instances/*/databases/*/databaseRoles/*}:testIamPermissions", + "body": "*" + } + ] } }, { @@ -2144,6 +2150,24 @@ "(google.api.method_signature)": "parent" } ] + }, + "ListDatabaseRoles": { + "requestType": "ListDatabaseRolesRequest", + "responseType": "ListDatabaseRolesResponse", + "options": { + "(google.api.http).get": "/v1/{parent=projects/*/instances/*/databases/*}/databaseRoles", + "(google.api.method_signature)": "parent" + }, + "parsedOptions": [ + { + "(google.api.http)": { + "get": "/v1/{parent=projects/*/instances/*/databases/*}/databaseRoles" + } + }, + { + "(google.api.method_signature)": "parent" + } + ] } } }, @@ -2606,6 +2630,54 @@ "TYPE_UNSPECIFIED": 0, "BACKUP": 1 } + }, + "DatabaseRole": { + "options": { + "(google.api.resource).type": "spanner.googleapis.com/DatabaseRole", + "(google.api.resource).pattern": "projects/{project}/instances/{instance}/databases/{database}/databaseRoles/{role}" + }, + "fields": { + "name": { + "type": "string", + "id": 1, + "options": { + "(google.api.field_behavior)": "REQUIRED" + } + } + } + }, + "ListDatabaseRolesRequest": { + "fields": { + "parent": { + "type": "string", + "id": 1, + "options": { + "(google.api.field_behavior)": "REQUIRED", + "(google.api.resource_reference).type": "spanner.googleapis.com/Database" + } + }, + "pageSize": { + "type": "int32", + "id": 2 + }, + "pageToken": { + "type": "string", + "id": 3 + } + } + }, + "ListDatabaseRolesResponse": { + "fields": { + "databaseRoles": { + "rule": "repeated", + "type": "DatabaseRole", + "id": 1 + }, + "nextPageToken": { + "type": "string", + "id": 2 + } + } } } } diff --git a/src/v1/database_admin_client.ts b/src/v1/database_admin_client.ts index aa5127cab..d0e6f24de 100644 --- a/src/v1/database_admin_client.ts +++ b/src/v1/database_admin_client.ts @@ -181,6 +181,9 @@ export class DatabaseAdminClient { databasePathTemplate: new this._gaxModule.PathTemplate( 'projects/{project}/instances/{instance}/databases/{database}' ), + databaseRolePathTemplate: new this._gaxModule.PathTemplate( + 'projects/{project}/instances/{instance}/databases/{database}/databaseRoles/{role}' + ), instancePathTemplate: new this._gaxModule.PathTemplate( 'projects/{project}/instances/{instance}' ), @@ -210,6 +213,11 @@ export class DatabaseAdminClient { 'nextPageToken', 'operations' ), + listDatabaseRoles: new this._gaxModule.PageDescriptor( + 'pageToken', + 'nextPageToken', + 'databaseRoles' + ), }; const protoFilesRoot = this._gaxModule.protobuf.Root.fromJSON(jsonProtos); @@ -224,31 +232,46 @@ export class DatabaseAdminClient { lroOptions.protoJson = protoFilesRoot; lroOptions.httpRules = [ { - selector: 'google.longrunning.Operations.GetOperation', - get: '/v1/{name=projects/*/instances/*/databases/*/operations/*}', + selector: 'google.longrunning.Operations.CancelOperation', + post: '/v1/{name=projects/*/instances/*/databases/*/operations/*}:cancel', additional_bindings: [ - {get: '/v1/{name=projects/*/instances/*/operations/*}'}, + {post: '/v1/{name=projects/*/instances/*/operations/*}:cancel'}, + { + post: '/v1/{name=projects/*/instances/*/backups/*/operations/*}:cancel', + }, + { + post: '/v1/{name=projects/*/instanceConfigs/*/operations/*}:cancel', + }, ], }, { - selector: 'google.longrunning.Operations.ListOperations', - get: '/v1/{name=projects/*/instances/*/databases/*/operations}', + selector: 'google.longrunning.Operations.DeleteOperation', + delete: '/v1/{name=projects/*/instances/*/databases/*/operations/*}', additional_bindings: [ - {get: '/v1/{name=projects/*/instances/*/operations}'}, + {delete: '/v1/{name=projects/*/instances/*/operations/*}'}, + { + delete: + '/v1/{name=projects/*/instances/*/backups/*/operations/*}', + }, + {delete: '/v1/{name=projects/*/instanceConfigs/*/operations/*}'}, ], }, { - selector: 'google.longrunning.Operations.CancelOperation', - post: '/v1/{name=projects/*/instances/*/databases/*/operations/*}:cancel', + selector: 'google.longrunning.Operations.GetOperation', + get: '/v1/{name=projects/*/instances/*/databases/*/operations/*}', additional_bindings: [ - {post: '/v1/{name=projects/*/instances/*/operations/*}:cancel'}, + {get: '/v1/{name=projects/*/instances/*/operations/*}'}, + {get: '/v1/{name=projects/*/instances/*/backups/*/operations/*}'}, + {get: '/v1/{name=projects/*/instanceConfigs/*/operations/*}'}, ], }, { - selector: 'google.longrunning.Operations.DeleteOperation', - delete: '/v1/{name=projects/*/instances/*/databases/*/operations/*}', + selector: 'google.longrunning.Operations.ListOperations', + get: '/v1/{name=projects/*/instances/*/databases/*/operations}', additional_bindings: [ - {delete: '/v1/{name=projects/*/instances/*/operations/*}'}, + {get: '/v1/{name=projects/*/instances/*/operations}'}, + {get: '/v1/{name=projects/*/instances/*/backups/*/operations}'}, + {get: '/v1/{name=projects/*/instanceConfigs/*/operations}'}, ], }, ]; @@ -383,6 +406,7 @@ export class DatabaseAdminClient { 'restoreDatabase', 'listDatabaseOperations', 'listBackupOperations', + 'listDatabaseRoles', ]; for (const methodName of databaseAdminStubMethods) { const callPromise = this.databaseAdminStub.then( @@ -3448,6 +3472,387 @@ export class DatabaseAdminClient { callSettings ) as AsyncIterable; } + /** + * Lists Cloud Spanner database roles. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.parent + * Required. The database whose roles should be listed. + * Values are of the form + * `projects//instances//databases//databaseRoles`. + * @param {number} request.pageSize + * Number of database roles to be returned in the response. If 0 or less, + * defaults to the server's maximum allowed page size. + * @param {string} request.pageToken + * If non-empty, `page_token` should contain a + * {@link google.spanner.admin.database.v1.ListDatabaseRolesResponse.next_page_token|next_page_token} from a + * previous {@link google.spanner.admin.database.v1.ListDatabaseRolesResponse|ListDatabaseRolesResponse}. + * @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 [DatabaseRole]{@link google.spanner.admin.database.v1.DatabaseRole}. + * The client library will perform 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. + * Note that it can affect your quota. + * We recommend using `listDatabaseRolesAsync()` + * method described below for async iteration which you can stop as needed. + * Please see the + * [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination) + * for more details and examples. + */ + listDatabaseRoles( + request?: protos.google.spanner.admin.database.v1.IListDatabaseRolesRequest, + options?: CallOptions + ): Promise< + [ + protos.google.spanner.admin.database.v1.IDatabaseRole[], + protos.google.spanner.admin.database.v1.IListDatabaseRolesRequest | null, + protos.google.spanner.admin.database.v1.IListDatabaseRolesResponse + ] + >; + listDatabaseRoles( + request: protos.google.spanner.admin.database.v1.IListDatabaseRolesRequest, + options: CallOptions, + callback: PaginationCallback< + protos.google.spanner.admin.database.v1.IListDatabaseRolesRequest, + | protos.google.spanner.admin.database.v1.IListDatabaseRolesResponse + | null + | undefined, + protos.google.spanner.admin.database.v1.IDatabaseRole + > + ): void; + listDatabaseRoles( + request: protos.google.spanner.admin.database.v1.IListDatabaseRolesRequest, + callback: PaginationCallback< + protos.google.spanner.admin.database.v1.IListDatabaseRolesRequest, + | protos.google.spanner.admin.database.v1.IListDatabaseRolesResponse + | null + | undefined, + protos.google.spanner.admin.database.v1.IDatabaseRole + > + ): void; + listDatabaseRoles( + request?: protos.google.spanner.admin.database.v1.IListDatabaseRolesRequest, + optionsOrCallback?: + | CallOptions + | PaginationCallback< + protos.google.spanner.admin.database.v1.IListDatabaseRolesRequest, + | protos.google.spanner.admin.database.v1.IListDatabaseRolesResponse + | null + | undefined, + protos.google.spanner.admin.database.v1.IDatabaseRole + >, + callback?: PaginationCallback< + protos.google.spanner.admin.database.v1.IListDatabaseRolesRequest, + | protos.google.spanner.admin.database.v1.IListDatabaseRolesResponse + | null + | undefined, + protos.google.spanner.admin.database.v1.IDatabaseRole + > + ): Promise< + [ + protos.google.spanner.admin.database.v1.IDatabaseRole[], + protos.google.spanner.admin.database.v1.IListDatabaseRolesRequest | null, + protos.google.spanner.admin.database.v1.IListDatabaseRolesResponse + ] + > | void { + request = request || {}; + let options: CallOptions; + if (typeof optionsOrCallback === 'function' && callback === undefined) { + callback = optionsOrCallback; + options = {}; + } else { + options = optionsOrCallback as CallOptions; + } + 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 || '', + }); + this.initialize(); + return this.innerApiCalls.listDatabaseRoles(request, options, callback); + } + + /** + * Equivalent to `method.name.toCamelCase()`, but returns a NodeJS Stream object. + * @param {Object} request + * The request object that will be sent. + * @param {string} request.parent + * Required. The database whose roles should be listed. + * Values are of the form + * `projects//instances//databases//databaseRoles`. + * @param {number} request.pageSize + * Number of database roles to be returned in the response. If 0 or less, + * defaults to the server's maximum allowed page size. + * @param {string} request.pageToken + * If non-empty, `page_token` should contain a + * {@link google.spanner.admin.database.v1.ListDatabaseRolesResponse.next_page_token|next_page_token} from a + * previous {@link google.spanner.admin.database.v1.ListDatabaseRolesResponse|ListDatabaseRolesResponse}. + * @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 [DatabaseRole]{@link google.spanner.admin.database.v1.DatabaseRole} on 'data' event. + * The client library will perform auto-pagination by default: it will call the API as many + * times as needed. Note that it can affect your quota. + * We recommend using `listDatabaseRolesAsync()` + * method described below for async iteration which you can stop as needed. + * Please see the + * [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination) + * for more details and examples. + */ + listDatabaseRolesStream( + request?: protos.google.spanner.admin.database.v1.IListDatabaseRolesRequest, + options?: CallOptions + ): Transform { + request = request || {}; + 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 || '', + }); + const defaultCallSettings = this._defaults['listDatabaseRoles']; + const callSettings = defaultCallSettings.merge(options); + this.initialize(); + return this.descriptors.page.listDatabaseRoles.createStream( + this.innerApiCalls.listDatabaseRoles as gax.GaxCall, + request, + callSettings + ); + } + + /** + * Equivalent to `listDatabaseRoles`, but returns an iterable object. + * + * `for`-`await`-`of` syntax is used with the iterable to get response elements on-demand. + * @param {Object} request + * The request object that will be sent. + * @param {string} request.parent + * Required. The database whose roles should be listed. + * Values are of the form + * `projects//instances//databases//databaseRoles`. + * @param {number} request.pageSize + * Number of database roles to be returned in the response. If 0 or less, + * defaults to the server's maximum allowed page size. + * @param {string} request.pageToken + * If non-empty, `page_token` should contain a + * {@link google.spanner.admin.database.v1.ListDatabaseRolesResponse.next_page_token|next_page_token} from a + * previous {@link google.spanner.admin.database.v1.ListDatabaseRolesResponse|ListDatabaseRolesResponse}. + * @param {object} [options] + * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. + * @returns {Object} + * An iterable Object that allows [async iteration](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols). + * When you iterate the returned iterable, each element will be an object representing + * [DatabaseRole]{@link google.spanner.admin.database.v1.DatabaseRole}. The API will be called under the hood as needed, once per the page, + * so you can stop the iteration when you don't need more results. + * Please see the + * [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination) + * for more details and examples. + * @example include:samples/generated/v1/database_admin.list_database_roles.js + * region_tag:spanner_v1_generated_DatabaseAdmin_ListDatabaseRoles_async + */ + listDatabaseRolesAsync( + request?: protos.google.spanner.admin.database.v1.IListDatabaseRolesRequest, + options?: CallOptions + ): AsyncIterable { + request = request || {}; + 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 || '', + }); + const defaultCallSettings = this._defaults['listDatabaseRoles']; + const callSettings = defaultCallSettings.merge(options); + this.initialize(); + return this.descriptors.page.listDatabaseRoles.asyncIterate( + this.innerApiCalls['listDatabaseRoles'] as GaxCall, + request as unknown as RequestType, + callSettings + ) as AsyncIterable; + } + /** + * Gets the latest state of a long-running operation. Clients can use this + * method to poll the operation result at intervals as recommended by the API + * service. + * + * @param {Object} request - The request object that will be sent. + * @param {string} request.name - The name of the operation resource. + * @param {Object=} options + * Optional parameters. You can override the default settings for this call, + * e.g, timeout, retries, paginations, etc. See [gax.CallOptions]{@link + * https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the + * details. + * @param {function(?Error, ?Object)=} callback + * The function which will be called with the result of the API call. + * + * The second parameter to the callback is an object representing + * [google.longrunning.Operation]{@link + * external:"google.longrunning.Operation"}. + * @return {Promise} - The promise which resolves to an array. + * The first element of the array is an object representing + * [google.longrunning.Operation]{@link + * external:"google.longrunning.Operation"}. The promise has a method named + * "cancel" which cancels the ongoing API call. + * + * @example + * ``` + * const client = longrunning.operationsClient(); + * const name = ''; + * const [response] = await client.getOperation({name}); + * // doThingsWith(response) + * ``` + */ + getOperation( + request: protos.google.longrunning.GetOperationRequest, + options?: + | gax.CallOptions + | Callback< + protos.google.longrunning.Operation, + protos.google.longrunning.GetOperationRequest, + {} | null | undefined + >, + callback?: Callback< + protos.google.longrunning.Operation, + protos.google.longrunning.GetOperationRequest, + {} | null | undefined + > + ): Promise<[protos.google.longrunning.Operation]> { + return this.operationsClient.getOperation(request, options, callback); + } + /** + * Lists operations that match the specified filter in the request. If the + * server doesn't support this method, it returns `UNIMPLEMENTED`. Returns an iterable object. + * + * For-await-of syntax is used with the iterable to recursively get response element on-demand. + * + * @param {Object} request - The request object that will be sent. + * @param {string} request.name - The name of the operation collection. + * @param {string} request.filter - The standard list filter. + * @param {number=} request.pageSize - + * The maximum number of resources contained in the underlying API + * response. If page streaming is performed per-resource, this + * parameter does not affect the return value. If page streaming is + * performed per-page, this determines the maximum number of + * resources in a page. + * @param {Object=} options + * Optional parameters. You can override the default settings for this call, + * e.g, timeout, retries, paginations, etc. See [gax.CallOptions]{@link + * https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the + * details. + * @returns {Object} + * An iterable Object that conforms to @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols. + * + * @example + * ``` + * const client = longrunning.operationsClient(); + * for await (const response of client.listOperationsAsync(request)); + * // doThingsWith(response) + * ``` + */ + listOperationsAsync( + request: protos.google.longrunning.ListOperationsRequest, + options?: gax.CallOptions + ): AsyncIterable { + return this.operationsClient.listOperationsAsync(request, options); + } + /** + * Starts asynchronous cancellation on a long-running operation. The server + * makes a best effort to cancel the operation, but success is not + * guaranteed. If the server doesn't support this method, it returns + * `google.rpc.Code.UNIMPLEMENTED`. Clients can use + * {@link Operations.GetOperation} or + * other methods to check whether the cancellation succeeded or whether the + * operation completed despite cancellation. On successful cancellation, + * the operation is not deleted; instead, it becomes an operation with + * an {@link Operation.error} value with a {@link google.rpc.Status.code} of + * 1, corresponding to `Code.CANCELLED`. + * + * @param {Object} request - The request object that will be sent. + * @param {string} request.name - The name of the operation resource to be cancelled. + * @param {Object=} options + * Optional parameters. You can override the default settings for this call, + * e.g, timeout, retries, paginations, etc. See [gax.CallOptions]{@link + * https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the + * details. + * @param {function(?Error)=} callback + * The function which will be called with the result of the API call. + * @return {Promise} - The promise which resolves when API call finishes. + * The promise has a method named "cancel" which cancels the ongoing API + * call. + * + * @example + * ``` + * const client = longrunning.operationsClient(); + * await client.cancelOperation({name: ''}); + * ``` + */ + cancelOperation( + request: protos.google.longrunning.CancelOperationRequest, + options?: + | gax.CallOptions + | Callback< + protos.google.protobuf.Empty, + protos.google.longrunning.CancelOperationRequest, + {} | undefined | null + >, + callback?: Callback< + protos.google.longrunning.CancelOperationRequest, + protos.google.protobuf.Empty, + {} | undefined | null + > + ): Promise { + return this.operationsClient.cancelOperation(request, options, callback); + } + + /** + * Deletes a long-running operation. This method indicates that the client is + * no longer interested in the operation result. It does not cancel the + * operation. If the server doesn't support this method, it returns + * `google.rpc.Code.UNIMPLEMENTED`. + * + * @param {Object} request - The request object that will be sent. + * @param {string} request.name - The name of the operation resource to be deleted. + * @param {Object=} options + * Optional parameters. You can override the default settings for this call, + * e.g, timeout, retries, paginations, etc. See [gax.CallOptions]{@link + * https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the + * details. + * @param {function(?Error)=} callback + * The function which will be called with the result of the API call. + * @return {Promise} - The promise which resolves when API call finishes. + * The promise has a method named "cancel" which cancels the ongoing API + * call. + * + * @example + * ``` + * const client = longrunning.operationsClient(); + * await client.deleteOperation({name: ''}); + * ``` + */ + deleteOperation( + request: protos.google.longrunning.DeleteOperationRequest, + options?: + | gax.CallOptions + | Callback< + protos.google.protobuf.Empty, + protos.google.longrunning.DeleteOperationRequest, + {} | null | undefined + >, + callback?: Callback< + protos.google.protobuf.Empty, + protos.google.longrunning.DeleteOperationRequest, + {} | null | undefined + > + ): Promise { + return this.operationsClient.deleteOperation(request, options, callback); + } + // -------------------- // -- Path templates -- // -------------------- @@ -3621,6 +4026,77 @@ export class DatabaseAdminClient { return this.pathTemplates.databasePathTemplate.match(databaseName).database; } + /** + * Return a fully-qualified databaseRole resource name string. + * + * @param {string} project + * @param {string} instance + * @param {string} database + * @param {string} role + * @returns {string} Resource name string. + */ + databaseRolePath( + project: string, + instance: string, + database: string, + role: string + ) { + return this.pathTemplates.databaseRolePathTemplate.render({ + project: project, + instance: instance, + database: database, + role: role, + }); + } + + /** + * Parse the project from DatabaseRole resource. + * + * @param {string} databaseRoleName + * A fully-qualified path representing DatabaseRole resource. + * @returns {string} A string representing the project. + */ + matchProjectFromDatabaseRoleName(databaseRoleName: string) { + return this.pathTemplates.databaseRolePathTemplate.match(databaseRoleName) + .project; + } + + /** + * Parse the instance from DatabaseRole resource. + * + * @param {string} databaseRoleName + * A fully-qualified path representing DatabaseRole resource. + * @returns {string} A string representing the instance. + */ + matchInstanceFromDatabaseRoleName(databaseRoleName: string) { + return this.pathTemplates.databaseRolePathTemplate.match(databaseRoleName) + .instance; + } + + /** + * Parse the database from DatabaseRole resource. + * + * @param {string} databaseRoleName + * A fully-qualified path representing DatabaseRole resource. + * @returns {string} A string representing the database. + */ + matchDatabaseFromDatabaseRoleName(databaseRoleName: string) { + return this.pathTemplates.databaseRolePathTemplate.match(databaseRoleName) + .database; + } + + /** + * Parse the role from DatabaseRole resource. + * + * @param {string} databaseRoleName + * A fully-qualified path representing DatabaseRole resource. + * @returns {string} A string representing the role. + */ + matchRoleFromDatabaseRoleName(databaseRoleName: string) { + return this.pathTemplates.databaseRolePathTemplate.match(databaseRoleName) + .role; + } + /** * Return a fully-qualified instance resource name string. * diff --git a/src/v1/database_admin_client_config.json b/src/v1/database_admin_client_config.json index a70c4bd30..035f43bc8 100644 --- a/src/v1/database_admin_client_config.json +++ b/src/v1/database_admin_client_config.json @@ -118,6 +118,11 @@ "timeout_millis": 3600000, "retry_codes_name": "idempotent", "retry_params_name": "e9fafda332ce8a1702dc1575de3ca81c4feb4799" + }, + "ListDatabaseRoles": { + "timeout_millis": 3600000, + "retry_codes_name": "idempotent", + "retry_params_name": "e9fafda332ce8a1702dc1575de3ca81c4feb4799" } } } diff --git a/test/gapic_database_admin_v1.ts b/test/gapic_database_admin_v1.ts index 7b07d600f..560c24b3a 100644 --- a/test/gapic_database_admin_v1.ts +++ b/test/gapic_database_admin_v1.ts @@ -3522,6 +3522,622 @@ describe('v1.DatabaseAdminClient', () => { }); }); + describe('listDatabaseRoles', () => { + it('invokes listDatabaseRoles without error', async () => { + const client = new databaseadminModule.v1.DatabaseAdminClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.spanner.admin.database.v1.ListDatabaseRolesRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = [ + generateSampleMessage( + new protos.google.spanner.admin.database.v1.DatabaseRole() + ), + generateSampleMessage( + new protos.google.spanner.admin.database.v1.DatabaseRole() + ), + generateSampleMessage( + new protos.google.spanner.admin.database.v1.DatabaseRole() + ), + ]; + client.innerApiCalls.listDatabaseRoles = stubSimpleCall(expectedResponse); + const [response] = await client.listDatabaseRoles(request); + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.listDatabaseRoles as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + + it('invokes listDatabaseRoles without error using callback', async () => { + const client = new databaseadminModule.v1.DatabaseAdminClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.spanner.admin.database.v1.ListDatabaseRolesRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = [ + generateSampleMessage( + new protos.google.spanner.admin.database.v1.DatabaseRole() + ), + generateSampleMessage( + new protos.google.spanner.admin.database.v1.DatabaseRole() + ), + generateSampleMessage( + new protos.google.spanner.admin.database.v1.DatabaseRole() + ), + ]; + client.innerApiCalls.listDatabaseRoles = + stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.listDatabaseRoles( + request, + ( + err?: Error | null, + result?: + | protos.google.spanner.admin.database.v1.IDatabaseRole[] + | null + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + } + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.listDatabaseRoles as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions /*, callback defined above */) + ); + }); + + it('invokes listDatabaseRoles with error', async () => { + const client = new databaseadminModule.v1.DatabaseAdminClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.spanner.admin.database.v1.ListDatabaseRolesRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedError = new Error('expected'); + client.innerApiCalls.listDatabaseRoles = stubSimpleCall( + undefined, + expectedError + ); + await assert.rejects(client.listDatabaseRoles(request), expectedError); + assert( + (client.innerApiCalls.listDatabaseRoles as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + + it('invokes listDatabaseRolesStream without error', async () => { + const client = new databaseadminModule.v1.DatabaseAdminClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.spanner.admin.database.v1.ListDatabaseRolesRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedResponse = [ + generateSampleMessage( + new protos.google.spanner.admin.database.v1.DatabaseRole() + ), + generateSampleMessage( + new protos.google.spanner.admin.database.v1.DatabaseRole() + ), + generateSampleMessage( + new protos.google.spanner.admin.database.v1.DatabaseRole() + ), + ]; + client.descriptors.page.listDatabaseRoles.createStream = + stubPageStreamingCall(expectedResponse); + const stream = client.listDatabaseRolesStream(request); + const promise = new Promise((resolve, reject) => { + const responses: protos.google.spanner.admin.database.v1.DatabaseRole[] = + []; + stream.on( + 'data', + (response: protos.google.spanner.admin.database.v1.DatabaseRole) => { + responses.push(response); + } + ); + stream.on('end', () => { + resolve(responses); + }); + stream.on('error', (err: Error) => { + reject(err); + }); + }); + const responses = await promise; + assert.deepStrictEqual(responses, expectedResponse); + assert( + (client.descriptors.page.listDatabaseRoles.createStream as SinonStub) + .getCall(0) + .calledWith(client.innerApiCalls.listDatabaseRoles, request) + ); + assert.strictEqual( + ( + client.descriptors.page.listDatabaseRoles.createStream as SinonStub + ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], + expectedHeaderRequestParams + ); + }); + + it('invokes listDatabaseRolesStream with error', async () => { + const client = new databaseadminModule.v1.DatabaseAdminClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.spanner.admin.database.v1.ListDatabaseRolesRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedError = new Error('expected'); + client.descriptors.page.listDatabaseRoles.createStream = + stubPageStreamingCall(undefined, expectedError); + const stream = client.listDatabaseRolesStream(request); + const promise = new Promise((resolve, reject) => { + const responses: protos.google.spanner.admin.database.v1.DatabaseRole[] = + []; + stream.on( + 'data', + (response: protos.google.spanner.admin.database.v1.DatabaseRole) => { + responses.push(response); + } + ); + stream.on('end', () => { + resolve(responses); + }); + stream.on('error', (err: Error) => { + reject(err); + }); + }); + await assert.rejects(promise, expectedError); + assert( + (client.descriptors.page.listDatabaseRoles.createStream as SinonStub) + .getCall(0) + .calledWith(client.innerApiCalls.listDatabaseRoles, request) + ); + assert.strictEqual( + ( + client.descriptors.page.listDatabaseRoles.createStream as SinonStub + ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], + expectedHeaderRequestParams + ); + }); + + it('uses async iteration with listDatabaseRoles without error', async () => { + const client = new databaseadminModule.v1.DatabaseAdminClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.spanner.admin.database.v1.ListDatabaseRolesRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedResponse = [ + generateSampleMessage( + new protos.google.spanner.admin.database.v1.DatabaseRole() + ), + generateSampleMessage( + new protos.google.spanner.admin.database.v1.DatabaseRole() + ), + generateSampleMessage( + new protos.google.spanner.admin.database.v1.DatabaseRole() + ), + ]; + client.descriptors.page.listDatabaseRoles.asyncIterate = + stubAsyncIterationCall(expectedResponse); + const responses: protos.google.spanner.admin.database.v1.IDatabaseRole[] = + []; + const iterable = client.listDatabaseRolesAsync(request); + for await (const resource of iterable) { + responses.push(resource!); + } + assert.deepStrictEqual(responses, expectedResponse); + assert.deepStrictEqual( + ( + client.descriptors.page.listDatabaseRoles.asyncIterate as SinonStub + ).getCall(0).args[1], + request + ); + assert.strictEqual( + ( + client.descriptors.page.listDatabaseRoles.asyncIterate as SinonStub + ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], + expectedHeaderRequestParams + ); + }); + + it('uses async iteration with listDatabaseRoles with error', async () => { + const client = new databaseadminModule.v1.DatabaseAdminClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.spanner.admin.database.v1.ListDatabaseRolesRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedError = new Error('expected'); + client.descriptors.page.listDatabaseRoles.asyncIterate = + stubAsyncIterationCall(undefined, expectedError); + const iterable = client.listDatabaseRolesAsync(request); + await assert.rejects(async () => { + const responses: protos.google.spanner.admin.database.v1.IDatabaseRole[] = + []; + for await (const resource of iterable) { + responses.push(resource!); + } + }); + assert.deepStrictEqual( + ( + client.descriptors.page.listDatabaseRoles.asyncIterate as SinonStub + ).getCall(0).args[1], + request + ); + assert.strictEqual( + ( + client.descriptors.page.listDatabaseRoles.asyncIterate as SinonStub + ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], + expectedHeaderRequestParams + ); + }); + }); + describe('getOperation', () => { + it('invokes getOperation without error', async () => { + const client = new databaseadminModule.v1.DatabaseAdminClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new operationsProtos.google.longrunning.GetOperationRequest() + ); + const expectedResponse = generateSampleMessage( + new operationsProtos.google.longrunning.Operation() + ); + client.operationsClient.getOperation = stubSimpleCall(expectedResponse); + const response = await client.getOperation(request); + assert.deepStrictEqual(response, [expectedResponse]); + assert( + (client.operationsClient.getOperation as SinonStub) + .getCall(0) + .calledWith(request) + ); + }); + it('invokes getOperation without error using callback', async () => { + const client = new databaseadminModule.v1.DatabaseAdminClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + const request = generateSampleMessage( + new operationsProtos.google.longrunning.GetOperationRequest() + ); + const expectedResponse = generateSampleMessage( + new operationsProtos.google.longrunning.Operation() + ); + client.operationsClient.getOperation = sinon + .stub() + .callsArgWith(2, null, expectedResponse); + const promise = new Promise((resolve, reject) => { + client.operationsClient.getOperation( + request, + undefined, + ( + err?: Error | null, + result?: operationsProtos.google.longrunning.Operation | null + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + } + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + assert((client.operationsClient.getOperation as SinonStub).getCall(0)); + }); + it('invokes getOperation with error', async () => { + const client = new databaseadminModule.v1.DatabaseAdminClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + const request = generateSampleMessage( + new operationsProtos.google.longrunning.GetOperationRequest() + ); + const expectedError = new Error('expected'); + client.operationsClient.getOperation = stubSimpleCall( + undefined, + expectedError + ); + await assert.rejects(async () => { + await client.getOperation(request); + }, expectedError); + assert( + (client.operationsClient.getOperation as SinonStub) + .getCall(0) + .calledWith(request) + ); + }); + }); + describe('cancelOperation', () => { + it('invokes cancelOperation without error', async () => { + const client = new databaseadminModule.v1.DatabaseAdminClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new operationsProtos.google.longrunning.CancelOperationRequest() + ); + const expectedResponse = generateSampleMessage( + new protos.google.protobuf.Empty() + ); + client.operationsClient.cancelOperation = + stubSimpleCall(expectedResponse); + const response = await client.cancelOperation(request); + assert.deepStrictEqual(response, [expectedResponse]); + assert( + (client.operationsClient.cancelOperation as SinonStub) + .getCall(0) + .calledWith(request) + ); + }); + it('invokes cancelOperation without error using callback', async () => { + const client = new databaseadminModule.v1.DatabaseAdminClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + const request = generateSampleMessage( + new operationsProtos.google.longrunning.CancelOperationRequest() + ); + const expectedResponse = generateSampleMessage( + new protos.google.protobuf.Empty() + ); + client.operationsClient.cancelOperation = sinon + .stub() + .callsArgWith(2, null, expectedResponse); + const promise = new Promise((resolve, reject) => { + client.operationsClient.cancelOperation( + request, + undefined, + ( + err?: Error | null, + result?: protos.google.protobuf.Empty | null + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + } + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + assert((client.operationsClient.cancelOperation as SinonStub).getCall(0)); + }); + it('invokes cancelOperation with error', async () => { + const client = new databaseadminModule.v1.DatabaseAdminClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + const request = generateSampleMessage( + new operationsProtos.google.longrunning.CancelOperationRequest() + ); + const expectedError = new Error('expected'); + client.operationsClient.cancelOperation = stubSimpleCall( + undefined, + expectedError + ); + await assert.rejects(async () => { + await client.cancelOperation(request); + }, expectedError); + assert( + (client.operationsClient.cancelOperation as SinonStub) + .getCall(0) + .calledWith(request) + ); + }); + }); + describe('deleteOperation', () => { + it('invokes deleteOperation without error', async () => { + const client = new databaseadminModule.v1.DatabaseAdminClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new operationsProtos.google.longrunning.DeleteOperationRequest() + ); + const expectedResponse = generateSampleMessage( + new protos.google.protobuf.Empty() + ); + client.operationsClient.deleteOperation = + stubSimpleCall(expectedResponse); + const response = await client.deleteOperation(request); + assert.deepStrictEqual(response, [expectedResponse]); + assert( + (client.operationsClient.deleteOperation as SinonStub) + .getCall(0) + .calledWith(request) + ); + }); + it('invokes deleteOperation without error using callback', async () => { + const client = new databaseadminModule.v1.DatabaseAdminClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + const request = generateSampleMessage( + new operationsProtos.google.longrunning.DeleteOperationRequest() + ); + const expectedResponse = generateSampleMessage( + new protos.google.protobuf.Empty() + ); + client.operationsClient.deleteOperation = sinon + .stub() + .callsArgWith(2, null, expectedResponse); + const promise = new Promise((resolve, reject) => { + client.operationsClient.deleteOperation( + request, + undefined, + ( + err?: Error | null, + result?: protos.google.protobuf.Empty | null + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + } + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + assert((client.operationsClient.deleteOperation as SinonStub).getCall(0)); + }); + it('invokes deleteOperation with error', async () => { + const client = new databaseadminModule.v1.DatabaseAdminClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + const request = generateSampleMessage( + new operationsProtos.google.longrunning.DeleteOperationRequest() + ); + const expectedError = new Error('expected'); + client.operationsClient.deleteOperation = stubSimpleCall( + undefined, + expectedError + ); + await assert.rejects(async () => { + await client.deleteOperation(request); + }, expectedError); + assert( + (client.operationsClient.deleteOperation as SinonStub) + .getCall(0) + .calledWith(request) + ); + }); + }); + describe('listOperationsAsync', () => { + it('uses async iteration with listOperations without error', async () => { + const client = new databaseadminModule.v1.DatabaseAdminClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + const request = generateSampleMessage( + new operationsProtos.google.longrunning.ListOperationsRequest() + ); + const expectedResponse = [ + generateSampleMessage( + new operationsProtos.google.longrunning.ListOperationsResponse() + ), + generateSampleMessage( + new operationsProtos.google.longrunning.ListOperationsResponse() + ), + generateSampleMessage( + new operationsProtos.google.longrunning.ListOperationsResponse() + ), + ]; + client.operationsClient.descriptor.listOperations.asyncIterate = + stubAsyncIterationCall(expectedResponse); + const responses: operationsProtos.google.longrunning.ListOperationsResponse[] = + []; + const iterable = client.operationsClient.listOperationsAsync(request); + for await (const resource of iterable) { + responses.push(resource!); + } + assert.deepStrictEqual(responses, expectedResponse); + assert.deepStrictEqual( + ( + client.operationsClient.descriptor.listOperations + .asyncIterate as SinonStub + ).getCall(0).args[1], + request + ); + }); + it('uses async iteration with listOperations with error', async () => { + const client = new databaseadminModule.v1.DatabaseAdminClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new operationsProtos.google.longrunning.ListOperationsRequest() + ); + const expectedError = new Error('expected'); + client.operationsClient.descriptor.listOperations.asyncIterate = + stubAsyncIterationCall(undefined, expectedError); + const iterable = client.operationsClient.listOperationsAsync(request); + await assert.rejects(async () => { + const responses: operationsProtos.google.longrunning.ListOperationsResponse[] = + []; + for await (const resource of iterable) { + responses.push(resource!); + } + }); + assert.deepStrictEqual( + ( + client.operationsClient.descriptor.listOperations + .asyncIterate as SinonStub + ).getCall(0).args[1], + request + ); + }); + }); + describe('Path templates', () => { describe('backup', () => { const fakePath = '/rendered/path/backup'; @@ -3727,6 +4343,82 @@ describe('v1.DatabaseAdminClient', () => { }); }); + describe('databaseRole', () => { + const fakePath = '/rendered/path/databaseRole'; + const expectedParameters = { + project: 'projectValue', + instance: 'instanceValue', + database: 'databaseValue', + role: 'roleValue', + }; + const client = new databaseadminModule.v1.DatabaseAdminClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + client.pathTemplates.databaseRolePathTemplate.render = sinon + .stub() + .returns(fakePath); + client.pathTemplates.databaseRolePathTemplate.match = sinon + .stub() + .returns(expectedParameters); + + it('databaseRolePath', () => { + const result = client.databaseRolePath( + 'projectValue', + 'instanceValue', + 'databaseValue', + 'roleValue' + ); + assert.strictEqual(result, fakePath); + assert( + (client.pathTemplates.databaseRolePathTemplate.render as SinonStub) + .getCall(-1) + .calledWith(expectedParameters) + ); + }); + + it('matchProjectFromDatabaseRoleName', () => { + const result = client.matchProjectFromDatabaseRoleName(fakePath); + assert.strictEqual(result, 'projectValue'); + assert( + (client.pathTemplates.databaseRolePathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath) + ); + }); + + it('matchInstanceFromDatabaseRoleName', () => { + const result = client.matchInstanceFromDatabaseRoleName(fakePath); + assert.strictEqual(result, 'instanceValue'); + assert( + (client.pathTemplates.databaseRolePathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath) + ); + }); + + it('matchDatabaseFromDatabaseRoleName', () => { + const result = client.matchDatabaseFromDatabaseRoleName(fakePath); + assert.strictEqual(result, 'databaseValue'); + assert( + (client.pathTemplates.databaseRolePathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath) + ); + }); + + it('matchRoleFromDatabaseRoleName', () => { + const result = client.matchRoleFromDatabaseRoleName(fakePath); + assert.strictEqual(result, 'roleValue'); + assert( + (client.pathTemplates.databaseRolePathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath) + ); + }); + }); + describe('instance', () => { const fakePath = '/rendered/path/instance'; const expectedParameters = {