import * as gax from 'google-gax' ; import { Callback , CallOptions , Descriptors , ClientOptions , LROperation , } from 'google-gax' ; import * as protos from '../../protos/protos' ; import jsonProtos = require ( '../../protos/protos.json' ) ; /**
 * Client JSON configuration object, loaded from
 * `src/v1p4beta1/asset_service_client_config.json`.
 * This file defines retry strategy and timeouts for all API methods in this library.
 */ import * as gapicConfig from './asset_service_client_config.json' ; import { operationsProtos } from 'google-gax' ; const version = require ( '../../../package.json' ) . version ; class memberof export class AssetServiceClient { private _terminated = false ; private _opts : ClientOptions ; private _providedCustomServicePath : boolean ; private _gaxModule : typeof gax | typeof gax . fallback ; private _gaxGrpc : gax . GrpcClient | gax . fallback . GrpcClient ; private _protos : { } ; private _defaults : { [ method ] : gax . CallSettings ; } ; auth : gax . GoogleAuth ; descriptors : Descriptors = { page : { } , stream : { } , longrunning : { } , batching : { } , } ; warn : ( code : string , message : string , warnType ? : string ) => void ; innerApiCalls : { [ name ] : Function ; } ; operationsClient : gax . OperationsClient ; assetServiceStub ? : Promise < { [ name ] : Function ; } > ; param options param options . credentials param { string } options . credentials . client_email param { string } options . credentials . private_key param { string } options . email param { string } options . keyFilename param { number } options . port 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
     *      https ,
     *     your project ID will be detected automatically.
     *  param { string } options . apiEndpoint param { gax . ClientConfig } options . clientConfig - Client configuration override.
     *     Follows the structure of  gapicConfig .
     *  param { boolean } options . fallback constructor ( opts ? ) { const staticMembers = this . constructor as typeof AssetServiceClient ; const servicePath = opts ?. servicePath || opts ?. apiEndpoint || staticMembers . servicePath ; this . _providedCustomServicePath = ! ! ( opts ?. servicePath || opts ?. apiEndpoint ) ; const port = opts ?. port || staticMembers . port ; const clientConfig = opts ?. clientConfig ?? { } ; const fallback = opts ?. fallback ?? ( typeof window !== 'undefined' && typeof window ?. fetch === 'function' ) ; opts = Object . assign ( { servicePath , port , clientConfig , fallback } , opts ) ; if ( servicePath !== staticMembers . servicePath && ! ( 'scopes' in opts ) ) { opts [ 'scopes' ] = staticMembers . scopes ; } this . _gaxModule = opts . fallback ? gax . fallback : gax ; this . _gaxGrpc = new this . _gaxModule . GrpcClient ( opts ) ; this . _opts = opts ; this . auth = this . _gaxGrpc . auth as gax . GoogleAuth ; this . auth . useJWTAccessWithScope = true ; this . auth . defaultServicePath = staticMembers . servicePath ; if ( servicePath === staticMembers . servicePath ) { this . auth . defaultScopes = staticMembers . scopes ; } const clientHeader = [ `gax/${ this . _gaxModule . version }` , `gapic/${ version }` ] ; if ( typeof process !== 'undefined' && 'versions' in process ) { clientHeader . push ( `gl-node/${ process . versions . node }` ) ; } else { clientHeader . push ( `gl-web/${ this . _gaxModule . version }` ) ; } if ( ! opts . fallback ) { clientHeader . push ( `grpc/${ this . _gaxGrpc . grpcVersion }` ) ; } else if ( opts . fallback === 'rest' ) { clientHeader . push ( `rest/${ this . _gaxGrpc . grpcVersion }` ) ; } if ( opts . libName && opts . libVersion ) { clientHeader . push ( `${ opts . libName }/${ opts . libVersion }` ) ; } this . _protos = this . _gaxGrpc . loadProtoJSON ( jsonProtos ) ; const protoFilesRoot = this . _gaxModule . protobuf . Root . fromJSON ( jsonProtos ) ; this . operationsClient = this . _gaxModule . lro ( { auth : this . auth , grpc : 'grpc' in this . _gaxGrpc ? this . _gaxGrpc . grpc : undefined , } ) . operationsClient ( opts ) ; const exportIamPolicyAnalysisResponse = protoFilesRoot . lookup ( '.google.cloud.asset.v1p4beta1.ExportIamPolicyAnalysisResponse' ) as gax . protobuf . Type ; const exportIamPolicyAnalysisMetadata = protoFilesRoot . lookup ( '.google.cloud.asset.v1p4beta1.ExportIamPolicyAnalysisRequest' ) as gax . protobuf . Type ; this . descriptors . longrunning = { exportIamPolicyAnalysis : new this . _gaxModule . LongrunningDescriptor ( this . operationsClient , exportIamPolicyAnalysisResponse . decode . bind ( exportIamPolicyAnalysisResponse ) , exportIamPolicyAnalysisMetadata . decode . bind ( exportIamPolicyAnalysisMetadata ) ) , } ; this . _defaults = this . _gaxGrpc . constructSettings ( 'google.cloud.asset.v1p4beta1.AssetService' , gapicConfig as gax . ClientConfig , opts . clientConfig || { } , { 'x-goog-api-client' : clientHeader . join ( ' ' ) } ) ; this . innerApiCalls = { } ; this . warn = gax . warn ; } returns { Promise } initialize ( ) { if ( this . assetServiceStub ) { return this . assetServiceStub ; } this . assetServiceStub = this . _gaxGrpc . createStub ( this . _opts . fallback ? ( this . _protos as protobuf . Root ) . lookupService ( 'google.cloud.asset.v1p4beta1.AssetService' ) : ( this . _protos as any ) . google . cloud . asset . v1p4beta1 . AssetService , this . _opts , this . _providedCustomServicePath ) as Promise < { [ method ] : Function ; } > ; const assetServiceStubMethods = [ 'analyzeIamPolicy' , 'exportIamPolicyAnalysis' , ] ; for ( const methodName of assetServiceStubMethods ) { const callPromise = this . assetServiceStub . then ( stub => ( ... args ) => { if ( this . _terminated ) { return Promise . reject ( 'The client has already been closed.' ) ; } const func = stub [ methodName ] ; return func . apply ( stub , args ) ; } , ( err ) => ( ) => { throw err ; } ) ; const descriptor = this . descriptors . longrunning [ methodName ] || undefined ; const apiCall = this . _gaxModule . createApiCall ( callPromise , this . _defaults [ methodName ] , descriptor ) ; this . innerApiCalls [ methodName ] = apiCall ; } return this . assetServiceStub ; } returns { string } static get servicePath ( ) { return 'cloudasset.googleapis.com' ; } returns { string } static get apiEndpoint ( ) { return 'cloudasset.googleapis.com' ; } returns { number } static get port ( ) { return 443 ; } returns { string [ ] } static get scopes ( ) { return [ 'https://www.googleapis.com/auth/cloud-platform' ] ; } getProjectId ( ) ; getProjectId ( callback ) ; returns { Promise } getProjectId ( callback ? ) { if ( callback ) { this . auth . getProjectId ( callback ) ; return ; } return this . auth . getProjectId ( ) ; } /**
     * Analyzes IAM policies based on the specified request. Returns
     * a list of  google . cloud . asset . v1p4beta1 . IamPolicyAnalysisResult matching the request.
     *
     *  param request param { google . cloud . asset . v1p4beta1 . IamPolicyAnalysisQuery } request . analysisQuery param { google . cloud . asset . v1p4beta1 . AnalyzeIamPolicyRequest . Options } request . options param { object } options Call options. See  https for more details.
     *  returns { Promise } - The promise which resolves to an array.
     *   The first element of the array is an object representing [AnalyzeIamPolicyResponse] google . cloud . asset . v1p4beta1 . AnalyzeIamPolicyResponse .
     *   Please see the
     *   [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods)
     *   for more details and examples.
     *  example analyzeIamPolicy ( request ? , options ? ) ; analyzeIamPolicy ( request , options , callback ) ; analyzeIamPolicy ( request , callback ) ; analyzeIamPolicy ( request ? , optionsOrCallback ? , callback ? ) { request = request || { } ; let options ; 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 ( { 'analysis_query.parent' : request . analysisQuery ! . parent || '' , } ) ; this . initialize ( ) ; return this . innerApiCalls . analyzeIamPolicy ( request , options , callback ) ; } /**
     * Exports IAM policy analysis based on the specified request. This API
     * implements the  google . longrunning . Operation API allowing you to keep
     * track of the export. The metadata contains the request to help callers to
     * map responses to requests.
     *
     *  param request param { google . cloud . asset . v1p4beta1 . IamPolicyAnalysisQuery } request . analysisQuery param { google . cloud . asset . v1p4beta1 . ExportIamPolicyAnalysisRequest . Options } request . options param { google . cloud . asset . v1p4beta1 . IamPolicyAnalysisOutputConfig } request . outputConfig param { object } options Call options. See  https for more details.
     *  returns { Promise } example exportIamPolicyAnalysis ( request ? , options ? ) ; exportIamPolicyAnalysis ( request , options , callback ) ; exportIamPolicyAnalysis ( request , callback ) ; exportIamPolicyAnalysis ( request ? , optionsOrCallback ? , callback ? ) { request = request || { } ; let options ; 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 ( { 'analysis_query.parent' : request . analysisQuery ! . parent || '' , } ) ; this . initialize ( ) ; return this . innerApiCalls . exportIamPolicyAnalysis ( request , options , callback ) ; } param { String } name returns { Promise } example async checkExportIamPolicyAnalysisProgress ( name ) { const request = new operationsProtos . google . longrunning . GetOperationRequest ( { name } ) ; const [ operation ] = await this . operationsClient . getOperation ( request ) ; const decodeOperation = new gax . Operation ( operation , this . descriptors . longrunning . exportIamPolicyAnalysis , gax . createDefaultBackoffSettings ( ) ) ; return decodeOperation as LROperation < protos . google . cloud . asset . v1p4beta1 . ExportIamPolicyAnalysisResponse , protos . google . cloud . asset . v1p4beta1 . ExportIamPolicyAnalysisRequest > ; } returns { Promise } close ( ) { this . initialize ( ) ; if ( ! this . _terminated ) { return this . assetServiceStub ! . then ( stub => { this . _terminated = true ; stub . close ( ) ; this . operationsClient . close ( ) ; } ) ; } return Promise . resolve ( ) ; } }