Skip to content

Commit a9c62e6

Browse files
feat: publish networksecurity v1beta1 api (#32232)
* feat: publish networksecurity v1beta1 api PiperOrigin-RevId: 838919865 Source-Link: googleapis/googleapis@586e752 Source-Link: googleapis/googleapis-gen@afa9f74 Copy-Tag: eyJwIjoiZ29vZ2xlLWNsb3VkLW5ldHdvcmtfc2VjdXJpdHkvLk93bEJvdC55YW1sIiwiaCI6ImFmYTlmNzQ0NzhiOTZkYjU0Y2FmNDE2ZmY5NDU2MzEzMTIzYzc1ODUifQ== * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --------- Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
1 parent 407d134 commit a9c62e6

5 files changed

Lines changed: 99 additions & 8 deletions

File tree

google-cloud-network_security/AUTHENTICATION.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ To configure a credentials file for an individual client initialization:
5656
```ruby
5757
require "google/cloud/network_security"
5858

59-
client = Google::Cloud::NetworkSecurity.network_security do |config|
59+
client = Google::Cloud::NetworkSecurity.dns_threat_detector_service do |config|
6060
config.credentials = "path/to/credentialfile.json"
6161
end
6262
```
@@ -70,7 +70,7 @@ Google::Cloud::NetworkSecurity.configure do |config|
7070
config.credentials = "path/to/credentialfile.json"
7171
end
7272

73-
client = Google::Cloud::NetworkSecurity.network_security
73+
client = Google::Cloud::NetworkSecurity.dns_threat_detector_service
7474
```
7575

7676
### Environment Variables
@@ -100,7 +100,7 @@ require "google/cloud/network_security"
100100

101101
ENV["GOOGLE_APPLICATION_CREDENTIALS"] = "path/to/credentialfile.json"
102102

103-
client = Google::Cloud::NetworkSecurity.network_security
103+
client = Google::Cloud::NetworkSecurity.dns_threat_detector_service
104104
```
105105

106106
### Local ADC file

google-cloud-network_security/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ In order to use this library, you first need to go through the following steps:
3737
```ruby
3838
require "google/cloud/network_security"
3939

40-
client = Google::Cloud::NetworkSecurity.network_security
41-
request = ::Google::Cloud::NetworkSecurity::V1beta1::ListAuthorizationPoliciesRequest.new # (request fields as keyword arguments...)
42-
response = client.list_authorization_policies request
40+
client = Google::Cloud::NetworkSecurity.dns_threat_detector_service
41+
request = ::Google::Cloud::NetworkSecurity::V1beta1::ListDnsThreatDetectorsRequest.new # (request fields as keyword arguments...)
42+
response = client.list_dns_threat_detectors request
4343
```
4444

4545
## Debug Logging

google-cloud-network_security/Rakefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ task :acceptance, :project, :keyfile do |t, args|
5757
if project.nil? || keyfile.nil?
5858
fail "You must provide a project and keyfile. e.g. rake acceptance[test123, /path/to/keyfile.json] or GOOGLE_CLOUD_TEST_PROJECT=test123 GOOGLE_CLOUD_TEST_KEYFILE=/path/to/keyfile.json rake acceptance"
5959
end
60-
require "google/cloud/network_security/v1beta1/network_security/credentials"
61-
::Google::Cloud::NetworkSecurity::V1beta1::NetworkSecurity::Credentials.env_vars.each do |path|
60+
require "google/cloud/network_security/v1beta1/dns_threat_detector_service/credentials"
61+
::Google::Cloud::NetworkSecurity::V1beta1::DnsThreatDetectorService::Credentials.env_vars.each do |path|
6262
ENV[path] = nil
6363
end
6464
ENV["GOOGLE_CLOUD_PROJECT"] = project

google-cloud-network_security/lib/google/cloud/network_security.rb

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,76 @@
4545
module Google
4646
module Cloud
4747
module NetworkSecurity
48+
##
49+
# Create a new client object for DnsThreatDetectorService.
50+
#
51+
# By default, this returns an instance of
52+
# [Google::Cloud::NetworkSecurity::V1beta1::DnsThreatDetectorService::Client](https://cloud.google.com/ruby/docs/reference/google-cloud-network_security-v1beta1/latest/Google-Cloud-NetworkSecurity-V1beta1-DnsThreatDetectorService-Client)
53+
# for a gRPC client for version V1beta1 of the API.
54+
# However, you can specify a different API version by passing it in the
55+
# `version` parameter. If the DnsThreatDetectorService service is
56+
# supported by that API version, and the corresponding gem is available, the
57+
# appropriate versioned client will be returned.
58+
# You can also specify a different transport by passing `:rest` or `:grpc` in
59+
# the `transport` parameter.
60+
#
61+
# Raises an exception if the currently installed versioned client gem for the
62+
# given API version does not support the given transport of the DnsThreatDetectorService service.
63+
# You can determine whether the method will succeed by calling
64+
# {Google::Cloud::NetworkSecurity.dns_threat_detector_service_available?}.
65+
#
66+
# ## About DnsThreatDetectorService
67+
#
68+
# The Network Security API for DNS Threat Detectors.
69+
#
70+
# @param version [::String, ::Symbol] The API version to connect to. Optional.
71+
# Defaults to `:v1beta1`.
72+
# @param transport [:grpc, :rest] The transport to use. Defaults to `:grpc`.
73+
# @return [::Object] A client object for the specified version.
74+
#
75+
def self.dns_threat_detector_service version: :v1beta1, transport: :grpc, &block
76+
require "google/cloud/network_security/#{version.to_s.downcase}"
77+
78+
package_name = Google::Cloud::NetworkSecurity
79+
.constants
80+
.select { |sym| sym.to_s.downcase == version.to_s.downcase.tr("_", "") }
81+
.first
82+
service_module = Google::Cloud::NetworkSecurity.const_get(package_name).const_get(:DnsThreatDetectorService)
83+
service_module = service_module.const_get(:Rest) if transport == :rest
84+
service_module.const_get(:Client).new(&block)
85+
end
86+
87+
##
88+
# Determines whether the DnsThreatDetectorService service is supported by the current client.
89+
# If true, you can retrieve a client object by calling {Google::Cloud::NetworkSecurity.dns_threat_detector_service}.
90+
# If false, that method will raise an exception. This could happen if the given
91+
# API version does not exist or does not support the DnsThreatDetectorService service,
92+
# or if the versioned client gem needs an update to support the DnsThreatDetectorService service.
93+
#
94+
# @param version [::String, ::Symbol] The API version to connect to. Optional.
95+
# Defaults to `:v1beta1`.
96+
# @param transport [:grpc, :rest] The transport to use. Defaults to `:grpc`.
97+
# @return [boolean] Whether the service is available.
98+
#
99+
def self.dns_threat_detector_service_available? version: :v1beta1, transport: :grpc
100+
require "google/cloud/network_security/#{version.to_s.downcase}"
101+
package_name = Google::Cloud::NetworkSecurity
102+
.constants
103+
.select { |sym| sym.to_s.downcase == version.to_s.downcase.tr("_", "") }
104+
.first
105+
return false unless package_name
106+
service_module = Google::Cloud::NetworkSecurity.const_get package_name
107+
return false unless service_module.const_defined? :DnsThreatDetectorService
108+
service_module = service_module.const_get :DnsThreatDetectorService
109+
if transport == :rest
110+
return false unless service_module.const_defined? :Rest
111+
service_module = service_module.const_get :Rest
112+
end
113+
service_module.const_defined? :Client
114+
rescue ::LoadError
115+
false
116+
end
117+
48118
##
49119
# Create a new client object for NetworkSecurity.
50120
#

google-cloud-network_security/test/google/cloud/network_security/client_test.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,27 @@ def logger
4141
end
4242
end
4343

44+
def test_dns_threat_detector_service_grpc
45+
skip unless Google::Cloud::NetworkSecurity.dns_threat_detector_service_available? transport: :grpc
46+
Gapic::ServiceStub.stub :new, DummyStub.new do
47+
grpc_channel = GRPC::Core::Channel.new "localhost:8888", nil, :this_channel_is_insecure
48+
client = Google::Cloud::NetworkSecurity.dns_threat_detector_service transport: :grpc do |config|
49+
config.credentials = grpc_channel
50+
end
51+
assert_kind_of Google::Cloud::NetworkSecurity::V1beta1::DnsThreatDetectorService::Client, client
52+
end
53+
end
54+
55+
def test_dns_threat_detector_service_rest
56+
skip unless Google::Cloud::NetworkSecurity.dns_threat_detector_service_available? transport: :rest
57+
Gapic::Rest::ClientStub.stub :new, DummyStub.new do
58+
client = Google::Cloud::NetworkSecurity.dns_threat_detector_service transport: :rest do |config|
59+
config.credentials = :dummy_credentials
60+
end
61+
assert_kind_of Google::Cloud::NetworkSecurity::V1beta1::DnsThreatDetectorService::Rest::Client, client
62+
end
63+
end
64+
4465
def test_network_security_grpc
4566
skip unless Google::Cloud::NetworkSecurity.network_security_available? transport: :grpc
4667
Gapic::ServiceStub.stub :new, DummyStub.new do

0 commit comments

Comments
 (0)