feat: Support custom quota_project in request options
This commit is contained in:
1 parent
ddf80e2dc9
commit
197286a8a7
3 files changed
+25
-9
No files matched your search
@@ -52,12 +52,9 @@ module Google
|
||||
#
|
||||
# @return [void]
|
||||
def prepare!
|
||||
set_xgac
|
||||
if options&.authorization.respond_to? :quota_project_id
|
||||
quota_project_id = options.authorization.quota_project_id
|
||||
header['X-Goog-User-Project'] = quota_project_id if quota_project_id
|
||||
end
|
||||
if options && options.api_format_version
|
||||
set_api_client_header
|
||||
set_user_project_header
|
||||
if options&.api_format_version
|
||||
header['X-Goog-Api-Format-Version'] = options.api_format_version.to_s
|
||||
end
|
||||
query[FIELDS_PARAM] = normalize_fields_param(query[FIELDS_PARAM]) if query.key?(FIELDS_PARAM)
|
||||
@@ -130,7 +127,7 @@ module Google
|
||||
|
||||
private
|
||||
|
||||
def set_xgac
|
||||
def set_api_client_header
|
||||
old_xgac = header
|
||||
.find_all { |k, v| k.downcase == 'x-goog-api-client' }
|
||||
.map { |(a, b)| b }
|
||||
@@ -144,6 +141,14 @@ module Google
|
||||
header['X-Goog-Api-Client'] = xgac
|
||||
end
|
||||
|
||||
def set_user_project_header
|
||||
quota_project_id = options.quota_project
|
||||
if !quota_project_id && options&.authorization.respond_to?(:quota_project_id)
|
||||
quota_project_id = options.authorization.quota_project_id
|
||||
end
|
||||
header['X-Goog-User-Project'] = quota_project_id if quota_project_id
|
||||
end
|
||||
|
||||
# Attempt to parse a JSON error message
|
||||
# @param [String] body
|
||||
# HTTP response body
|
||||
|
||||
@@ -33,7 +33,8 @@ module Google
|
||||
:skip_serialization,
|
||||
:skip_deserialization,
|
||||
:api_format_version,
|
||||
:use_opencensus)
|
||||
:use_opencensus,
|
||||
:quota_project)
|
||||
|
||||
# General client options
|
||||
class ClientOptions
|
||||
@@ -76,6 +77,8 @@ module Google
|
||||
# @return [Fixnum] Version of the error format to request/expect.
|
||||
# @!attribute [rw] use_opencensus
|
||||
# @return [Boolean] Whether OpenCensus spans should be generated for requests. Default is true.
|
||||
# @!attribute [rw] quota_project
|
||||
# @return [String] Project ID to charge quota, or `nil` to default to the credentials-specified project.
|
||||
|
||||
# Get the default options
|
||||
# @return [Google::Apis::RequestOptions]
|
||||
@@ -105,5 +108,6 @@ module Google
|
||||
RequestOptions.default.skip_deserialization = false
|
||||
RequestOptions.default.api_format_version = nil
|
||||
RequestOptions.default.use_opencensus = true
|
||||
RequestOptions.default.quota_project = nil
|
||||
end
|
||||
end
|
||||
Reference in new issue
Block a user