|
| 1 | +// Copyright 2026 Google LLC |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// https://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +package pubsub |
| 16 | + |
| 17 | +import ( |
| 18 | + "context" |
| 19 | + "os" |
| 20 | + |
| 21 | + "google.golang.org/api/option" |
| 22 | + "google.golang.org/api/option/internaloption" |
| 23 | + "google.golang.org/grpc" |
| 24 | + "google.golang.org/grpc/credentials/insecure" |
| 25 | +) |
| 26 | + |
| 27 | +func init() { |
| 28 | + newTopicAdminClientHook = emulatorHook |
| 29 | + newSubscriptionAdminClientHook = emulatorHook |
| 30 | + newSchemaClientHook = emulatorHook |
| 31 | +} |
| 32 | + |
| 33 | +func emulatorHook(ctx context.Context, params clientHookParams) ([]option.ClientOption, error) { |
| 34 | + if addr := os.Getenv("PUBSUB_EMULATOR_HOST"); addr != "" { |
| 35 | + return []option.ClientOption{ |
| 36 | + option.WithEndpoint(addr), |
| 37 | + option.WithGRPCDialOption(grpc.WithTransportCredentials(insecure.NewCredentials())), |
| 38 | + option.WithoutAuthentication(), |
| 39 | + option.WithTelemetryDisabled(), |
| 40 | + internaloption.SkipDialSettingsValidation(), |
| 41 | + }, nil |
| 42 | + } |
| 43 | + return nil, nil |
| 44 | +} |
0 commit comments