gapic-generator 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (150) hide show
  1. checksums.yaml +7 -0
  2. data/.yardopts +13 -0
  3. data/CHANGELOG.md +43 -0
  4. data/CODE_OF_CONDUCT.md +43 -0
  5. data/CONTRIBUTING.md +28 -0
  6. data/LICENSE +202 -0
  7. data/README.md +72 -0
  8. data/bin/gapic-generator +103 -0
  9. data/bin/protoc-gen-ruby_gapic +33 -0
  10. data/default-rubocop.yml +10 -0
  11. data/gem_templates/binary.erb +20 -0
  12. data/gem_templates/dockerfile.erb +39 -0
  13. data/gem_templates/entrypoint.erb +24 -0
  14. data/gem_templates/gapic_sh.erb +97 -0
  15. data/gem_templates/gemfile.erb +8 -0
  16. data/gem_templates/gemspec.erb +36 -0
  17. data/gem_templates/generator.erb +37 -0
  18. data/gem_templates/gitignore.erb +10 -0
  19. data/gem_templates/rakefile.erb +29 -0
  20. data/gem_templates/readme.erb +69 -0
  21. data/gem_templates/rubocop.erb +16 -0
  22. data/gem_templates/shared/_header.erb +4 -0
  23. data/gem_templates/shared/_license.erb +13 -0
  24. data/gem_templates/shared/_warning.erb +1 -0
  25. data/gem_templates/test_generator.erb +13 -0
  26. data/gem_templates/test_helper.erb +25 -0
  27. data/gem_templates/version.erb +10 -0
  28. data/lib/gapic/file_formatter.rb +62 -0
  29. data/lib/gapic/formatting_utils.rb +109 -0
  30. data/lib/gapic/gem_builder.rb +98 -0
  31. data/lib/gapic/generator.rb +30 -0
  32. data/lib/gapic/generator/version.rb +21 -0
  33. data/lib/gapic/generators/base_generator.rb +91 -0
  34. data/lib/gapic/generators/default_generator.rb +101 -0
  35. data/lib/gapic/grpc_service_config/method_config.rb +49 -0
  36. data/lib/gapic/grpc_service_config/parser.rb +218 -0
  37. data/lib/gapic/grpc_service_config/parsing_error.rb +25 -0
  38. data/lib/gapic/grpc_service_config/retry_policy.rb +51 -0
  39. data/lib/gapic/grpc_service_config/service_config.rb +42 -0
  40. data/lib/gapic/path_template.rb +35 -0
  41. data/lib/gapic/path_template/parser.rb +83 -0
  42. data/lib/gapic/path_template/segment.rb +67 -0
  43. data/lib/gapic/resource_lookup.rb +91 -0
  44. data/lib/gapic/runner.rb +76 -0
  45. data/lib/gapic/schema.rb +17 -0
  46. data/lib/gapic/schema/api.rb +264 -0
  47. data/lib/gapic/schema/loader.rb +269 -0
  48. data/lib/gapic/schema/wrappers.rb +717 -0
  49. data/lib/google/api/annotations.pb.rb +39 -0
  50. data/lib/google/api/client.pb.rb +43 -0
  51. data/lib/google/api/field_behavior.pb.rb +51 -0
  52. data/lib/google/api/http.pb.rb +60 -0
  53. data/lib/google/api/resource.pb.rb +80 -0
  54. data/lib/google/longrunning/operations.pb.rb +115 -0
  55. data/lib/google/protobuf/any.pb.rb +40 -0
  56. data/lib/google/protobuf/compiler/plugin.pb.rb +72 -0
  57. data/lib/google/protobuf/descriptor.pb.rb +359 -0
  58. data/lib/google/protobuf/empty.pb.rb +36 -0
  59. data/lib/google/rpc/status.pb.rb +46 -0
  60. data/templates/default/gem/_version.erb +2 -0
  61. data/templates/default/gem/changelog.erb +3 -0
  62. data/templates/default/gem/gemfile.erb +4 -0
  63. data/templates/default/gem/gemspec.erb +37 -0
  64. data/templates/default/gem/gitignore.erb +20 -0
  65. data/templates/default/gem/license.erb +22 -0
  66. data/templates/default/gem/rakefile.erb +27 -0
  67. data/templates/default/gem/readme.erb +24 -0
  68. data/templates/default/gem/rubocop.erb +59 -0
  69. data/templates/default/gem/version.erb +6 -0
  70. data/templates/default/gem/yardopts.erb +12 -0
  71. data/templates/default/helpers/default_helper.rb +50 -0
  72. data/templates/default/helpers/filepath_helper.rb +38 -0
  73. data/templates/default/helpers/namespace_helper.rb +44 -0
  74. data/templates/default/helpers/presenter_helper.rb +24 -0
  75. data/templates/default/helpers/presenters/enum_presenter.rb +35 -0
  76. data/templates/default/helpers/presenters/enum_value_presenter.rb +33 -0
  77. data/templates/default/helpers/presenters/field_presenter.rb +146 -0
  78. data/templates/default/helpers/presenters/file_presenter.rb +53 -0
  79. data/templates/default/helpers/presenters/gem_presenter.rb +140 -0
  80. data/templates/default/helpers/presenters/message_presenter.rb +66 -0
  81. data/templates/default/helpers/presenters/method_presenter.rb +293 -0
  82. data/templates/default/helpers/presenters/package_presenter.rb +65 -0
  83. data/templates/default/helpers/presenters/resource_presenter.rb +92 -0
  84. data/templates/default/helpers/presenters/sample_presenter.rb +74 -0
  85. data/templates/default/helpers/presenters/service_presenter.rb +276 -0
  86. data/templates/default/layouts/_ruby.erb +20 -0
  87. data/templates/default/package.erb +6 -0
  88. data/templates/default/proto_docs/_enum.erb +13 -0
  89. data/templates/default/proto_docs/_message.erb +23 -0
  90. data/templates/default/proto_docs/_proto_file.erb +9 -0
  91. data/templates/default/proto_docs/proto_file.erb +6 -0
  92. data/templates/default/proto_docs/readme.erb +5 -0
  93. data/templates/default/service.erb +8 -0
  94. data/templates/default/service/client.erb +6 -0
  95. data/templates/default/service/client/_client.erb +137 -0
  96. data/templates/default/service/client/_config.erb +155 -0
  97. data/templates/default/service/client/_credentials.erb +21 -0
  98. data/templates/default/service/client/_helpers.erb +9 -0
  99. data/templates/default/service/client/_operations.erb +88 -0
  100. data/templates/default/service/client/_paths.erb +8 -0
  101. data/templates/default/service/client/_requires.erb +1 -0
  102. data/templates/default/service/client/_resource.erb +6 -0
  103. data/templates/default/service/client/_self_configure.erb +9 -0
  104. data/templates/default/service/client/_self_configure_defaults.erb +22 -0
  105. data/templates/default/service/client/_self_configure_retry_policy.erb +15 -0
  106. data/templates/default/service/client/method/_def.erb +21 -0
  107. data/templates/default/service/client/method/def/_options_defaults.erb +29 -0
  108. data/templates/default/service/client/method/def/_request.erb +6 -0
  109. data/templates/default/service/client/method/def/_request_normal.erb +4 -0
  110. data/templates/default/service/client/method/def/_request_streaming.erb +9 -0
  111. data/templates/default/service/client/method/def/_rescue.erb +1 -0
  112. data/templates/default/service/client/method/def/_response.erb +6 -0
  113. data/templates/default/service/client/method/def/_response_normal.erb +8 -0
  114. data/templates/default/service/client/method/def/_response_paged.erb +9 -0
  115. data/templates/default/service/client/method/docs/_error.erb +2 -0
  116. data/templates/default/service/client/method/docs/_request.erb +6 -0
  117. data/templates/default/service/client/method/docs/_request_field.erb +7 -0
  118. data/templates/default/service/client/method/docs/_request_normal.erb +20 -0
  119. data/templates/default/service/client/method/docs/_request_streaming.erb +5 -0
  120. data/templates/default/service/client/method/docs/_response.erb +6 -0
  121. data/templates/default/service/client/method/docs/_sample.erb +20 -0
  122. data/templates/default/service/client/method/docs/_sample_response.erb +24 -0
  123. data/templates/default/service/client/method/docs/_samples.erb +6 -0
  124. data/templates/default/service/client/method/docs/request_field/_arg.erb +10 -0
  125. data/templates/default/service/client/method/docs/request_field/_hash.erb +19 -0
  126. data/templates/default/service/client/method/docs/sample_response/_comment.erb +5 -0
  127. data/templates/default/service/client/method/docs/sample_response/_define.erb +2 -0
  128. data/templates/default/service/client/method/docs/sample_response/_loop.erb +12 -0
  129. data/templates/default/service/client/method/docs/sample_response/_print.erb +2 -0
  130. data/templates/default/service/client/method/docs/sample_response/_write_file.erb +2 -0
  131. data/templates/default/service/client/resource/_def.erb +6 -0
  132. data/templates/default/service/client/resource/_doc.erb +8 -0
  133. data/templates/default/service/client/resource/_multi.erb +28 -0
  134. data/templates/default/service/client/resource/_single.erb +11 -0
  135. data/templates/default/service/credentials.erb +6 -0
  136. data/templates/default/service/operations.erb +6 -0
  137. data/templates/default/service/paths.erb +6 -0
  138. data/templates/default/service/test/client.erb +24 -0
  139. data/templates/default/service/test/client_operations.erb +24 -0
  140. data/templates/default/service/test/method/_assert_response.erb +11 -0
  141. data/templates/default/service/test/method/_bidi.erb +100 -0
  142. data/templates/default/service/test/method/_client.erb +84 -0
  143. data/templates/default/service/test/method/_normal.erb +69 -0
  144. data/templates/default/service/test/method/_server.erb +85 -0
  145. data/templates/default/service/test/method/_setup.erb +21 -0
  146. data/templates/default/service/test/smoke.erb +12 -0
  147. data/templates/default/shared/_header.erb +4 -0
  148. data/templates/default/shared/_license.erb +21 -0
  149. data/templates/default/shared/_warning.erb +1 -0
  150. metadata +351 -0
@@ -0,0 +1,20 @@
1
+ <%- assert_locals namespace -%>
2
+ <%= render partial: "shared/header" -%>
3
+ <%- if instance_variable_defined? :@requires -%>
4
+
5
+ <%= @requires -%>
6
+ <%- end -%>
7
+ <%- # Two newlines here so YARD won't use the header as documentation -%>
8
+
9
+
10
+ <%- namespace.split("::").each_with_index do |ns, i| -%>
11
+ <%= indent "module #{ns}", i*2 %>
12
+ <%- end -%>
13
+ <%= indent yield, namespace.split("::").count*2 %>
14
+ <%- namespace.split("::").count.times do |i| -%>
15
+ <%= indent "end", (namespace.split("::").count-1-i)*2 %>
16
+ <%- end -%>
17
+ <%- if instance_variable_defined? :@footer -%>
18
+
19
+ <%= @footer -%>
20
+ <%- end -%>
@@ -0,0 +1,6 @@
1
+ <%- assert_locals package -%>
2
+ <%= render partial: "shared/header" -%>
3
+
4
+ <% package.services.each do |service| %>
5
+ require "<%= service.service_require %>"
6
+ <% end %>
@@ -0,0 +1,13 @@
1
+ <%- assert_locals enum -%>
2
+ <%- if enum.doc_description -%>
3
+ <%= indent enum.doc_description, "# " %>
4
+ <%- end -%>
5
+ module <%= enum.name %>
6
+ <%- enum.values.each do |value| -%>
7
+
8
+ <%- if value.doc_description -%>
9
+ <%= indent value.doc_description, " # " %>
10
+ <%- end -%>
11
+ <%= value.name %> = <%= value.number %>
12
+ <%- end -%>
13
+ end
@@ -0,0 +1,23 @@
1
+ <%- assert_locals message -%>
2
+ <%- if message.doc_description -%>
3
+ <%= indent message.doc_description, "# " %>
4
+ <%- end -%>
5
+ <%- message.fields.each do |field| -%>
6
+ <%= indent field.doc_attribute_type, "# " %>
7
+ # @return [<%= field.output_doc_types %>]
8
+ <%- if field.doc_description -%>
9
+ <%= indent field.doc_description, "# " %>
10
+ <%- end -%>
11
+ <%- end -%>
12
+ class <%= message.name %>
13
+ include Google::Protobuf::MessageExts
14
+ extend Google::Protobuf::MessageExts::ClassMethods
15
+ <%- message.nested_messages.each do |submsg| -%>
16
+
17
+ <%= indent_tail render(partial: "proto_docs/message", locals: { message: submsg }), 2 %>
18
+ <%- end -%>
19
+ <%- message.nested_enums.each do |enum| -%>
20
+
21
+ <%= indent_tail render(partial: "proto_docs/enum", locals: { enum: enum }), 2 %>
22
+ <%- end -%>
23
+ end
@@ -0,0 +1,9 @@
1
+ <%- assert_locals file -%>
2
+ <%- file.messages.each do |message| -%>
3
+
4
+ <%= render(partial: "proto_docs/message", locals: { message: message }) -%>
5
+ <%- end -%>
6
+ <%- file.enums.each do |enum| -%>
7
+
8
+ <%= render(partial: "proto_docs/enum", locals: { enum: enum }) -%>
9
+ <%- end -%>
@@ -0,0 +1,6 @@
1
+ <%- assert_locals file -%>
2
+ <%= render partial: "proto_docs/proto_file",
3
+ layout: "layouts/ruby",
4
+ locals: { file: file,
5
+ namespace: file.namespace }
6
+ %>
@@ -0,0 +1,5 @@
1
+ <%- assert_locals gem -%>
2
+ # <%= gem.title %> Protocol Buffer Documentation
3
+
4
+ These files are for the YARD documentation of the generated protobuf files.
5
+ They are not intended to be required or loaded at runtime.
@@ -0,0 +1,8 @@
1
+ <%- assert_locals service -%>
2
+ <%= render partial: "shared/header" -%>
3
+
4
+ require "<%= service.client_require %>"
5
+ <%- if service.lro? -%>
6
+ require "<%= service.operations_require %>"
7
+ <%- end -%>
8
+ require "<%= service.credentials_require %>"
@@ -0,0 +1,6 @@
1
+ <%- assert_locals service -%>
2
+ <%= render partial: "service/client/client",
3
+ layout: "layouts/ruby",
4
+ locals: { service: service,
5
+ namespace: service.proto_service_name_full }
6
+ %>
@@ -0,0 +1,137 @@
1
+ <%- assert_locals service -%>
2
+ <% @requires = capture do %>
3
+ require "gapic/common"
4
+ require "gapic/config"
5
+ require "gapic/config/method"
6
+
7
+ <%= render partial: "service/client/requires", locals: { service: service} -%>
8
+ require "<%= service.gem.version_require %>"
9
+ require "<%= service.proto_service_require %>"
10
+ require "<%= service.credentials_require %>"
11
+ <%- if service.paths? -%>
12
+ require "<%= service.paths_require %>"
13
+ <%- end -%>
14
+ <%- if service.lro? -%>
15
+ require "<%= service.operations_require %>"
16
+ <%- end -%>
17
+ <% end %>
18
+ # Service that implements <%= service.name %> API.
19
+ class <%= service.client_name %>
20
+ <%- if service.paths? -%>
21
+ include <%= service.paths_name %>
22
+
23
+ <%- end -%>
24
+ # @private
25
+ attr_reader :<%= service.stub_name %>
26
+
27
+ ##
28
+ # Configure the <%= service.name %> <%= service.client_name %> class.
29
+ #
30
+ # See {<%= service.client_name_full %>::Configuration}
31
+ # for a description of the configuration fields.
32
+ #
33
+ # ## Example
34
+ #
35
+ # To modify the configuration for all <%= service.name %> clients:
36
+ #
37
+ # <%= service.client_name_full %>.configure do |config|
38
+ # config.timeout = 10_000
39
+ # end
40
+ #
41
+ # @yield [config] Configure the <%= service.client_name %> client.
42
+ # @yieldparam config [<%= service.client_name %>::Configuration]
43
+ #
44
+ # @return [<%= service.client_name %>::Configuration]
45
+ #
46
+ def self.configure
47
+ <%= indent render(partial: "service/client/self_configure", locals: { service: service }), 4 %>
48
+ end
49
+
50
+ ##
51
+ # Configure the <%= service.name %> <%= service.client_name %> instance.
52
+ #
53
+ # The configuration is set to the derived mode, meaning that values can be changed,
54
+ # but structural changes (adding new fields, etc.) are not allowed. Structural changes
55
+ # should be made on {<%= service.client_name %>.configure}.
56
+ #
57
+ # See {<%= service.client_name_full %>::Configuration}
58
+ # for a description of the configuration fields.
59
+ #
60
+ # @yield [config] Configure the <%= service.client_name %> client.
61
+ # @yieldparam config [<%= service.client_name %>::Configuration]
62
+ #
63
+ # @return [<%= service.client_name %>::Configuration]
64
+ #
65
+ def configure
66
+ yield @config if block_given?
67
+ @config
68
+ end
69
+
70
+ ##
71
+ # Create a new <%= service.name %> client object.
72
+ #
73
+ # ## Examples
74
+ #
75
+ # To create a new <%= service.name %> client with the default
76
+ # configuration:
77
+ #
78
+ # client = <%= service.client_name_full %>.new
79
+ #
80
+ # To create a new <%= service.name %> client with a custom
81
+ # configuration:
82
+ #
83
+ # client = <%= service.client_name_full %>.new do |config|
84
+ # config.timeout = 10_000
85
+ # end
86
+ #
87
+ # @yield [config] Configure the <%= service.name %> client.
88
+ # @yieldparam config [<%= service.client_name %>::Configuration]
89
+ #
90
+ def initialize
91
+ # These require statements are intentionally placed here to initialize
92
+ # the gRPC module only when it's required.
93
+ # See https://github.com/googleapis/toolkit/issues/446
94
+ require "gapic/grpc"
95
+ require "<%= service.proto_services_require %>"
96
+
97
+ # Create the configuration object
98
+ @config = Configuration.new <%= service.client_name %>.configure
99
+
100
+ # Yield the configuration if needed
101
+ yield @config if block_given?
102
+
103
+ # Create credentials
104
+ credentials = @config.credentials
105
+ credentials ||= Credentials.default scope: @config.scope
106
+ if credentials.is_a?(String) || credentials.is_a?(Hash)
107
+ credentials = Credentials.new credentials, scope: @config.scope
108
+ end
109
+ @quota_project_id = credentials.respond_to?(:quota_project_id) ? credentials.quota_project_id : nil
110
+
111
+ <%- if service.lro? -%>
112
+ <%= service.lro_client_ivar %> = <%= service.operations_name %>.new do |config|
113
+ config.credentials = credentials
114
+ end
115
+
116
+ <%- end -%>
117
+ @<%= service.stub_name %> = Gapic::ServiceStub.new(
118
+ <%= service.proto_service_stub_name_full %>,
119
+ credentials: credentials,
120
+ endpoint: @config.endpoint,
121
+ channel_args: @config.channel_args,
122
+ interceptors: @config.interceptors
123
+ )
124
+ end
125
+
126
+ # Service calls
127
+ <%- service.methods.each do |method| -%>
128
+
129
+ <%= indent_tail render(partial: "service/client/method/def", locals: { method: method }), 2 %>
130
+ <%- end %>
131
+
132
+ <%= indent_tail render(partial: "service/client/config", locals: { service: service }), 2 %>
133
+ end
134
+
135
+ <% @footer = capture do %>
136
+ <%= render partial: "service/client/helpers", locals: { service: service} %>
137
+ <% end %>
@@ -0,0 +1,155 @@
1
+ <%- assert_locals service -%>
2
+ <%- method_service ||= service -%>
3
+ ##
4
+ # Configuration class for the <%= service.name %> API.
5
+ #
6
+ # This class represents the configuration for <%= service.name %>,
7
+ # providing control over timeouts, retry behavior, logging, transport
8
+ # parameters, and other low-level controls. Certain parameters can also be
9
+ # applied individually to specific RPCs. See
10
+ # {<%= service.client_name_full %>::Configuration::Rpcs}
11
+ # for a list of RPCs that can be configured independently.
12
+ #
13
+ # Configuration can be applied globally to all clients, or to a single client
14
+ # on construction.
15
+ #
16
+ <%- unless method_service.methods.empty? -%>
17
+ # # Examples
18
+ #
19
+ # To modify the global config, setting the timeout for <%= method_service.methods.first.name %>
20
+ # to 20 seconds, and all remaining timeouts to 10 seconds:
21
+ #
22
+ # <%= service.client_name_full %>.configure do |config|
23
+ # config.timeout = 10_000
24
+ # config.rpcs.<%= method_service.methods.first.name %>.timeout = 20_000
25
+ # end
26
+ #
27
+ # To apply the above configuration only to a new client:
28
+ #
29
+ # client = <%= service.client_name_full %>.new do |config|
30
+ # config.timeout = 10_000
31
+ # config.rpcs.<%= method_service.methods.first.name %>.timeout = 20_000
32
+ # end
33
+ #
34
+ <%- end -%>
35
+ # @!attribute [rw] endpoint
36
+ # The hostname or hostname:port of the service endpoint.
37
+ # Defaults to `<%= service.client_endpoint.inspect %>`.
38
+ # @return [String]
39
+ # @!attribute [rw] credentials
40
+ # Credentials to send with calls. You may provide any of the following types:
41
+ # * (`String`) The path to a service account key file in JSON format
42
+ # * (`Hash`) A service account key as a Hash
43
+ # * (`Google::Auth::Credentials`) A googleauth credentials object
44
+ # (see the [googleauth docs](https://googleapis.dev/ruby/googleauth/latest/index.html))
45
+ # * (`Signet::OAuth2::Client`) A signet oauth2 client object
46
+ # (see the [signet docs](https://googleapis.dev/ruby/signet/latest/Signet/OAuth2/Client.html))
47
+ # * (`GRPC::Core::Channel`) a gRPC channel with included credentials
48
+ # * (`GRPC::Core::ChannelCredentials`) a gRPC credentails object
49
+ # * (`nil`) indicating no credentials
50
+ # @return [Object]
51
+ # @!attribute [rw] scope
52
+ # The OAuth scopes
53
+ # @return [Array<String>]
54
+ # @!attribute [rw] lib_name
55
+ # The library name as recorded in instrumentation and logging
56
+ # @return [String]
57
+ # @!attribute [rw] lib_version
58
+ # The library version as recorded in instrumentation and logging
59
+ # @return [String]
60
+ # @!attribute [rw] channel_args
61
+ # Extra parameters passed to the gRPC channel. Note: this is ignored if a
62
+ # `GRPC::Core::Channel` object is provided as the credential.
63
+ # @return [Hash]
64
+ # @!attribute [rw] interceptors
65
+ # An array of interceptors that are run before calls are executed.
66
+ # @return [Array<GRPC::ClientInterceptor>]
67
+ # @!attribute [rw] timeout
68
+ # The call timeout in milliseconds.
69
+ # @return [Numeric]
70
+ # @!attribute [rw] metadata
71
+ # Additional gRPC headers to be sent with the call.
72
+ # @return [Hash{Symbol=>String}]
73
+ # @!attribute [rw] retry_policy
74
+ # The retry policy. The value is a hash with the following keys:
75
+ # * `:initial_delay` (*type:* `Numeric`) - The initial delay in seconds.
76
+ # * `:max_delay` (*type:* `Numeric`) - The max delay in seconds.
77
+ # * `:multiplier` (*type:* `Numeric`) - The incremental backoff multiplier.
78
+ # * `:retry_codes` (*type:* `Array<String>`) - The error codes that should
79
+ # trigger a retry.
80
+ # @return [Hash]
81
+ #
82
+ class Configuration
83
+ extend Gapic::Config
84
+
85
+ config_attr :endpoint, <%= service.client_endpoint.inspect %>, String
86
+ config_attr :credentials, nil do |value|
87
+ allowed = [::String, ::Hash, ::Proc, ::Google::Auth::Credentials, ::Signet::OAuth2::Client, nil]
88
+ allowed += [::GRPC::Core::Channel, ::GRPC::Core::ChannelCredentials] if defined? ::GRPC
89
+ allowed.any? { |klass| klass === value }
90
+ end
91
+ config_attr :scope, nil, String, Array, nil
92
+ config_attr :lib_name, nil, String, nil
93
+ config_attr :lib_version, nil, String, nil
94
+ config_attr(:channel_args, <%= service.config_channel_args.inspect %>, Hash, nil)
95
+ config_attr :interceptors, nil, Array, nil
96
+ config_attr :timeout, nil, Numeric, nil
97
+ config_attr :metadata, nil, Hash, nil
98
+ config_attr :retry_policy, nil, Hash, Proc, nil
99
+
100
+ # @private
101
+ def initialize parent_config = nil
102
+ @parent_config = parent_config unless parent_config.nil?
103
+
104
+ yield self if block_given?
105
+ end
106
+
107
+ ##
108
+ # Configurations for individual RPCs
109
+ # @return [Rpcs]
110
+ #
111
+ def rpcs
112
+ @rpcs ||= begin
113
+ parent_rpcs = nil
114
+ parent_rpcs = @parent_config.rpcs if @parent_config&.respond_to? :rpcs
115
+ Rpcs.new parent_rpcs
116
+ end
117
+ end
118
+
119
+ ##
120
+ # Configuration RPC class for the <%= service.name %> API.
121
+ #
122
+ # Includes fields providing the configuration for each RPC in this service.
123
+ # Each configuration object is of type `Gapic::Config::Method` and includes
124
+ # the following configuration fields:
125
+ #
126
+ # * `timeout` (*type:* `Numeric`) - The call timeout in milliseconds
127
+ # * `metadata` (*type:* `Hash{Symbol=>String}`) - Additional gRPC headers
128
+ # * `retry_policy (*type:* `Hash`) - The retry policy. The policy fields
129
+ # include the following keys:
130
+ # * `:initial_delay` (*type:* `Numeric`) - The initial delay in seconds.
131
+ # * `:max_delay` (*type:* `Numeric`) - The max delay in seconds.
132
+ # * `:multiplier` (*type:* `Numeric`) - The incremental backoff multiplier.
133
+ # * `:retry_codes` (*type:* `Array<String>`) - The error codes that should
134
+ # trigger a retry.
135
+ #
136
+ class Rpcs
137
+ <%- method_service.methods.each do |method| -%>
138
+ ##
139
+ # RPC-specific configuration for `<%= method.name %>`
140
+ # @return [Gapic::Config::Method]
141
+ #
142
+ attr_reader :<%= method.name %>
143
+ <%- end -%>
144
+
145
+ # @private
146
+ def initialize parent_rpcs = nil
147
+ <%- method_service.methods.each do |method| -%>
148
+ <%= method.name %>_config = parent_rpcs&.<%= method.name %> if parent_rpcs&.respond_to? :<%= method.name %>
149
+ @<%= method.name %> = Gapic::Config::Method.new <%= method.name %>_config
150
+ <%- end -%>
151
+
152
+ yield self if block_given?
153
+ end
154
+ end
155
+ end
@@ -0,0 +1,21 @@
1
+ <%- assert_locals service -%>
2
+ <% @requires = capture do %>
3
+ require "googleauth"
4
+ <% end %>
5
+ # Credentials for the <%= service.name %> API.
6
+ class <%= service.credentials_name %> < Google::Auth::Credentials
7
+ <%- if service.client_scopes.any? -%>
8
+ self.scope = [
9
+ <%- service.client_scopes.each_with_index do |client_scope, index| -%>
10
+ <%- comma = index == service.client_scopes.count - 1 ? "" : "," -%>
11
+ <%= client_scope.inspect %><%= comma %>
12
+ <%- end -%>
13
+ ]
14
+ <%- end -%>
15
+ self.env_vars = [
16
+ "<%= service.gem.env_prefix %>_CREDENTIALS",
17
+ "<%= service.gem.env_prefix %>_KEYFILE",
18
+ "<%= service.gem.env_prefix %>_CREDENTIALS_JSON",
19
+ "<%= service.gem.env_prefix %>_KEYFILE_JSON"
20
+ ]
21
+ end
@@ -0,0 +1,9 @@
1
+ # rubocop:disable Lint/HandleExceptions
2
+
3
+ # Once client is loaded, load helpers.rb if it exists.
4
+ begin
5
+ require "<%= service.helpers_require %>"
6
+ rescue LoadError
7
+ end
8
+
9
+ # rubocop:enable Lint/HandleExceptions
@@ -0,0 +1,88 @@
1
+ <%- assert_locals service -%>
2
+ <% @requires = capture do %>
3
+ require "gapic/common"
4
+ require "gapic/operation"
5
+
6
+ require "<%= service.gem.version_require %>"
7
+ require "<%= service.client_require %>"
8
+ require "<%= service.lro_service.proto_service_require %>"
9
+ <% end %>
10
+ # Service that implements Longrunning Operations API.
11
+ class <%= service.operations_name %>
12
+ # @private
13
+ attr_reader :<%= service.lro_service.stub_name %>
14
+
15
+ ##
16
+ # Configuration for the <%= service.name %> Operations API.
17
+ #
18
+ # @yield [config] Configure the <%= service.operations_name %> client.
19
+ # @yieldparam config [<%= service.operations_name %>::Configuration]
20
+ #
21
+ # @return [<%= service.operations_name %>::Configuration]
22
+ #
23
+ def self.configure
24
+ @configure ||= <%= service.operations_name %>::Configuration.new
25
+ yield @configure if block_given?
26
+ @configure
27
+ end
28
+
29
+ ##
30
+ # Configure the <%= service.name %> <%= service.operations_name %> instance.
31
+ #
32
+ # The configuration is set to the derived mode, meaning that values can be changed,
33
+ # but structural changes (adding new fields, etc.) are not allowed. Structural changes
34
+ # should be made on {<%= service.operations_name %>.configure}.
35
+ #
36
+ # @yield [config] Configure the <%= service.operations_name %> client.
37
+ # @yieldparam config [<%= service.operations_name %>::Configuration]
38
+ #
39
+ # @return [<%= service.operations_name %>::Configuration]
40
+ #
41
+ def configure
42
+ yield @config if block_given?
43
+ @config
44
+ end
45
+
46
+ ##
47
+ # Create a new <%= service.operations_name %> client object.
48
+ #
49
+ # @yield [config] Configure the <%= service.client_name %> client.
50
+ # @yieldparam config [<%= service.operations_name %>::Configuration]
51
+ #
52
+ def initialize
53
+ # These require statements are intentionally placed here to initialize
54
+ # the gRPC module only when it's required.
55
+ # See https://github.com/googleapis/toolkit/issues/446
56
+ require "gapic/grpc"
57
+ require "<%= service.lro_service.proto_services_require %>"
58
+
59
+ # Create the configuration object
60
+ @config = Configuration.new <%= service.operations_name %>.configure
61
+
62
+ # Yield the configuration if needed
63
+ yield @config if block_given?
64
+
65
+ # Create credentials
66
+ credentials = @config.credentials
67
+ credentials ||= Credentials.default scope: @config.scope
68
+ if credentials.is_a?(String) || credentials.is_a?(Hash)
69
+ credentials = Credentials.new credentials, scope: @config.scope
70
+ end
71
+
72
+ @<%= service.lro_service.stub_name %> = Gapic::ServiceStub.new(
73
+ <%= service.lro_service.proto_service_stub_name_full %>,
74
+ credentials: credentials,
75
+ endpoint: @config.endpoint,
76
+ channel_args: @config.channel_args,
77
+ interceptors: @config.interceptors
78
+ )
79
+ end
80
+
81
+ # Service calls
82
+ <%- service.lro_service.methods.each do |method| -%>
83
+
84
+ <%= indent_tail render(partial: "service/client/method/def", locals: { method: method }), 2 %>
85
+ <%- end %>
86
+
87
+ <%= indent_tail render(partial: "service/client/config", locals: { service: service.lro_service }), 2 %>
88
+ end