@@ -70,6 +70,21 @@ export type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
70
70
71
71
export interface ClientConfig extends gax . GrpcClientOptions {
72
72
apiEndpoint ?: string ;
73
+
74
+ /**
75
+ * Configures the emulator mode behaviour:
76
+ * - If false, disable emulator mode always
77
+ * - If true, enable emulator mode always
78
+ * - If unset, use heuristics to decide
79
+ * Emulator mode notably sets insecure SSL authentication so that you can
80
+ * try the library out without needing a cert.
81
+ *
82
+ * Also notably, if a TPC universeDomain is set, then this will be counted
83
+ * as !emulatorMode for the purposes of the heuristics. If you want emulator
84
+ * mode but with a TPC universe domain set, set this to true as well.
85
+ */
86
+ emulatorMode ?: boolean ;
87
+
73
88
servicePath ?: string ;
74
89
port ?: string | number ;
75
90
sslCreds ?: gax . grpc . ChannelCredentials ;
@@ -798,9 +813,16 @@ export class PubSub {
798
813
// If this looks like a GCP URL of some kind, don't go into emulator
799
814
// mode. Otherwise, supply a fake SSL provider so a real cert isn't
800
815
// required for running the emulator.
816
+ //
817
+ // Note that users can provide their own URL here, especially with
818
+ // TPC, so the emulatorMode flag lets them override this behaviour.
801
819
const officialUrlMatch =
802
- this . options . servicePath ! . endsWith ( '.googleapis.com' ) ;
803
- if ( ! officialUrlMatch ) {
820
+ this . options . servicePath ! . endsWith ( '.googleapis.com' ) ||
821
+ this . options . universeDomain ;
822
+ if (
823
+ ( ! officialUrlMatch && this . options . emulatorMode !== false ) ||
824
+ this . options . emulatorMode === true
825
+ ) {
804
826
const grpcInstance = this . options . grpc || gax . grpc ;
805
827
this . options . sslCreds = grpcInstance . credentials . createInsecure ( ) ;
806
828
this . isEmulator = true ;
0 commit comments