Module: Gapic::GrpcServiceConfig::Parser
- Defined in:
- lib/gapic/grpc_service_config/parser.rb
Overview
Takes a json of a GRPC service Config and parses it into the form usable by the microgenerator templates
Constant Summary collapse
- METHOD_CONFIG_JSON_KEY =
"methodConfig"- RETRY_POLICY_JSON_KEY =
"retryPolicy"- NAMES_JSON_KEY =
"name"- SERVICE_NAME_JSON_KEY =
"service"- METHOD_NAME_JSON_KEY =
"method"- TIMEOUT_JSON_KEY =
"timeout"- INITIAL_DELAY_JSON_KEY =
"initialBackoff"- MAX_DELAY_JSON_KEY =
"maxBackoff"- MULTIPLIER_JSON_KEY =
"backoffMultiplier"- STATUS_CODES_JSON_KEY =
"retryableStatusCodes"- ERROR_CODE_MAPPING =
See https://grpc.github.io/grpc/core/md_doc_statuscodes.html for a list of error codes.
[ "OK", "CANCELLED", "UNKNOWN", "INVALID_ARGUMENT", "DEADLINE_EXCEEDED", "NOT_FOUND", "ALREADY_EXISTS", "PERMISSION_DENIED", "RESOURCE_EXHAUSTED", "FAILED_PRECONDITION", "ABORTED", "OUT_OF_RANGE", "UNIMPLEMENTED", "INTERNAL", "UNAVAILABLE", "DATA_LOSS", "UNAUTHENTICATED" ].freeze
- ERROR_STRING_MAPPING =
ERROR_CODE_MAPPING.each_with_index.each_with_object({}) do |(str, num), hash| hash[str] = num end.freeze
Class Method Summary collapse
-
.get(hash, key) ⇒ Object
Look up a key including checking its underscore form.
-
.key?(hash, key) ⇒ Boolean
Determines if the key or its underscore form exists.
-
.parse(service_config_json) ⇒ Gapic::GrpcServiceConfig::ServiceConfig
Parses ServiceConfig from a json of a GRPC service config.
Class Method Details
.get(hash, key) ⇒ Object
Look up a key including checking its underscore form
236 237 238 |
# File 'lib/gapic/grpc_service_config/parser.rb', line 236 def self.get hash, key hash[key] || hash[ActiveSupport::Inflector.underscore(key)] end |
.key?(hash, key) ⇒ Boolean
Determines if the key or its underscore form exists
225 226 227 |
# File 'lib/gapic/grpc_service_config/parser.rb', line 225 def self.key? hash, key hash.key?(key) || hash.key?(ActiveSupport::Inflector.underscore(key)) end |
.parse(service_config_json) ⇒ Gapic::GrpcServiceConfig::ServiceConfig
Parses ServiceConfig from a json of a GRPC service config
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/gapic/grpc_service_config/parser.rb', line 76 def self.parse service_config_json service_level_result = {} service_method_level_result = {} if !service_config_json.nil? && key?(service_config_json, METHOD_CONFIG_JSON_KEY) method_configs_json = get service_config_json, METHOD_CONFIG_JSON_KEY method_configs_json.each do |method_config_json| method_config = parse_config method_config_json service_names = parse_service_names get(method_config_json, NAMES_JSON_KEY) service_method_names = filter_service_method_names get(method_config_json, NAMES_JSON_KEY) service_names.each do |service_name| service_level_result[service_name] = method_config end service_method_names.each do |service_method_name| service_name = get service_method_name, SERVICE_NAME_JSON_KEY method_name = get service_method_name, METHOD_NAME_JSON_KEY service_method_level_result[service_name] ||= {} service_method_level_result[service_name][method_name] = method_config end end end ServiceConfig.new service_level_result, service_method_level_result end |