diff --git a/ads_common/COPYING b/ads_common/COPYING old mode 100644 new mode 100755 diff --git a/ads_common/ChangeLog b/ads_common/ChangeLog old mode 100644 new mode 100755 index e727c64e9..cf2141b97 --- a/ads_common/ChangeLog +++ b/ads_common/ChangeLog @@ -1,6 +1,10 @@ -0.14.2: +1.0.0: + - Major version bump. The library has been stable and feature complete for + some time, and this is more accurately reflected by this version number. - Throw explicit warning for disabled SSL peer verification. - Small performance improvements for large requests. + - No longer include test files in the built gem. + - Removing support for multiple environments. 0.14.1: - Scrubbing an additional sensitive field present in some AdWords requests. diff --git a/ads_common/LICENSE b/ads_common/LICENSE old mode 100644 new mode 100755 diff --git a/ads_common/README.md b/ads_common/README.md old mode 100644 new mode 100755 index c23d4de20..804c1b30a --- a/ads_common/README.md +++ b/ads_common/README.md @@ -68,7 +68,7 @@ Google Ads Developers Plus page: # Copyright/License Info -Copyright 2010-2015, Google Inc. All Rights Reserved. +Copyright 2010-2017, Google Inc. All Rights Reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/ads_common/google-ads-common.gemspec b/ads_common/google-ads-common.gemspec old mode 100644 new mode 100755 index 3f515cbc9..16f818aee --- a/ads_common/google-ads-common.gemspec +++ b/ads_common/google-ads-common.gemspec @@ -34,8 +34,7 @@ Gem::Specification.new do |s| s.required_rubygems_version = '>= 1.3.6' s.rubyforge_project = 'google-ads-common' s.require_path = 'lib' - s.files = Dir.glob('{lib,test}/**/*') + %w(COPYING README.md ChangeLog) - s.test_files = Dir.glob('test/test_*.rb') + s.files = Dir.glob('lib/**/*') + %w(COPYING README.md ChangeLog) s.add_runtime_dependency('google-ads-savon', '~> 1.0', '>=1.0.2') s.add_runtime_dependency('httpi', '~> 2.3') s.add_runtime_dependency('httpclient', '~> 2.7') diff --git a/ads_common/lib/ads_common/api.rb b/ads_common/lib/ads_common/api.rb old mode 100644 new mode 100755 index 59dda7348..d1657467f --- a/ads_common/lib/ads_common/api.rb +++ b/ads_common/lib/ads_common/api.rb @@ -70,10 +70,9 @@ def api_config() def service(name, version = nil) name = name.to_sym version = (version.nil?) ? api_config.default_version : version.to_sym - environment = @config.read('service.environment') # Check if the combination is available. - validate_service_request(environment, version, name) + validate_service_request(version, name) # Try to re-use the service for this version if it was requested before. wrapper = if @wrappers.include?(version) && @wrappers[version][name] @@ -150,12 +149,11 @@ def save_oauth2_token(token) private # Auxiliary method to test parameters correctness for the service request. - def validate_service_request(environment, version, service) - # Check if the current environment supports the requested version. - unless api_config.environment_has_version(environment, version) + def validate_service_request(version, service) + # Check if the current config supports the requested version. + unless api_config.has_version(version) raise AdsCommon::Errors::Error, - "Environment '%s' does not support version '%s'" % - [environment.to_s, version.to_s] + "Version '%s' not recognized" % version.to_s end # Check if the specified version has the requested service. @@ -196,18 +194,14 @@ def create_auth_handler() raise AdsCommon::Errors::Error, 'OAuth authorization method is deprecated, use OAuth2 instead.' when :OAUTH2 - environment = @config.read('service.environment', - api_config.default_environment()) AdsCommon::Auth::OAuth2Handler.new( @config, - api_config.environment_config(environment, :oauth_scope) + api_config.config(:oauth_scope) ) when :OAUTH2_SERVICE_ACCOUNT - environment = @config.read('service.environment', - api_config.default_environment()) AdsCommon::Auth::OAuth2ServiceAccountHandler.new( @config, - api_config.environment_config(environment, :oauth_scope) + api_config.config(:oauth_scope) ) else raise AdsCommon::Errors::Error, @@ -226,15 +220,13 @@ def create_auth_handler() # - a simplified wrapper generated for the service # def prepare_wrapper(version, service) - environment = config.read('service.environment') api_config.do_require(version, service) - endpoint = api_config.endpoint(environment, version, service) + endpoint = api_config.endpoint(version, service) interface_class_name = api_config.interface_name(version, service) wrapper = class_for_path(interface_class_name).new(@config, endpoint) auth_handler = get_auth_handler() - header_ns = - api_config.environment_config(environment, :header_ns) + version.to_s + header_ns = api_config.config(:header_ns) + version.to_s soap_handler = soap_header_handler(auth_handler, version, header_ns, wrapper.namespace) wrapper.header_handler = soap_handler @@ -270,10 +262,8 @@ def init_config() provided_adapter = @config.read('connection.adapter') @config.set('connection.adapter', :httpclient) if provided_adapter.nil? - # Validating most important parameters. - ['service.environment', 'authentication.method'].each do |parameter| - symbolize_config_value(parameter) - end + # Make sure Auth param is a symbol. + symbolize_config_value('authentication.method') end # Converts value of a config key to uppercase symbol. diff --git a/ads_common/lib/ads_common/api_config.rb b/ads_common/lib/ads_common/api_config.rb old mode 100644 new mode 100755 index 68bf5363d..e823c1b40 --- a/ads_common/lib/ads_common/api_config.rb +++ b/ads_common/lib/ads_common/api_config.rb @@ -42,14 +42,13 @@ def latest_version service_config.keys.select { |service| service.is_a? Integer }.max end - # Does the given environment exist and contain the given version? + # Does the current config contain the given version? # # Returns: - # Boolean indicating whether the given environment exists and contains the - # given version + # Boolean indicating whether the current config contains the given version # - def environment_has_version(environment, version) - return !environment_config(environment, version).nil? + def has_version(version) + return !config(version).nil? end # Does the given version exist and contain the given service? @@ -94,32 +93,22 @@ def api_path return api_name.to_s.snakecase end - # Get the default environment. - # - # Returns: - # Default environment - # - def default_environment - raise NotImplementedError, 'default_environment not overriden.' - end - # Get the default filename for the config file. def default_config_filename raise NotImplementedError, 'default_config_filename not overriden.' end - # Get the endpoint for a service on a given environment and API version. + # Get the endpoint for a service on a given API version. # # Args: - # - environment: the service environment to be used # - version: the API version # - service: the name of the API service # # Returns: # The endpoint URL # - def endpoint(environment, version, service) - base = get_wsdl_base(environment, version) + def endpoint(version, service) + base = get_wsdl_base(version) # TODO(dklimkin): Unflatten subdir constants. Cross-API refactor 0.9.0. if !subdir_config().nil? base = base.to_s + subdir_config()[[version, service]].to_s @@ -142,19 +131,6 @@ def subdir(version, service) subdir_config()[[version, service]] end - # Get the authentication server details for an environment. Allows to - # override the auth URL via environmental variable. - # - # Args: - # - environment: the service environment to be used - # - # Returns: - # The full URL for the auth server - # - def auth_server(environment) - return ENV['ADSAPI_AUTH_URL'] || auth_server_config[environment] - end - # Perform the loading of the necessary source files for a version. # # Args: @@ -208,7 +184,7 @@ def interface_name(version, service) # def get_wsdls(version) res = {} - wsdl_base = get_wsdl_base(default_environment(), version) + wsdl_base = get_wsdl_base(version) postfix = wsdl_base.start_with?('http') ? '?wsdl' : '.wsdl' services(version).each do |service| path = wsdl_base @@ -226,15 +202,13 @@ def get_wsdls(version) # the base URL via environmental variable. # # Args: - # - environment: environment to use like :SANDBOX or :PRODUCTION # - version: the API version # # Returns: # String containing base URL # - def get_wsdl_base(environment, version) - return ENV['ADSAPI_BASE_URL'] || - environment_config(environment, version) + def get_wsdl_base(version) + return ENV['ADSAPI_BASE_URL'] || config(version) end end end diff --git a/ads_common/lib/ads_common/auth/base_handler.rb b/ads_common/lib/ads_common/auth/base_handler.rb old mode 100644 new mode 100755 diff --git a/ads_common/lib/ads_common/auth/oauth2_handler.rb b/ads_common/lib/ads_common/auth/oauth2_handler.rb old mode 100644 new mode 100755 diff --git a/ads_common/lib/ads_common/auth/oauth2_service_account_handler.rb b/ads_common/lib/ads_common/auth/oauth2_service_account_handler.rb old mode 100644 new mode 100755 diff --git a/ads_common/lib/ads_common/build/savon_abstract_generator.rb b/ads_common/lib/ads_common/build/savon_abstract_generator.rb old mode 100644 new mode 100755 diff --git a/ads_common/lib/ads_common/build/savon_generator.rb b/ads_common/lib/ads_common/build/savon_generator.rb old mode 100644 new mode 100755 diff --git a/ads_common/lib/ads_common/build/savon_registry.rb b/ads_common/lib/ads_common/build/savon_registry.rb old mode 100644 new mode 100755 diff --git a/ads_common/lib/ads_common/build/savon_registry_generator.rb b/ads_common/lib/ads_common/build/savon_registry_generator.rb old mode 100644 new mode 100755 diff --git a/ads_common/lib/ads_common/build/savon_service_generator.rb b/ads_common/lib/ads_common/build/savon_service_generator.rb old mode 100644 new mode 100755 diff --git a/ads_common/lib/ads_common/config.rb b/ads_common/lib/ads_common/config.rb old mode 100644 new mode 100755 diff --git a/ads_common/lib/ads_common/credential_handler.rb b/ads_common/lib/ads_common/credential_handler.rb old mode 100644 new mode 100755 diff --git a/ads_common/lib/ads_common/env_check.rb b/ads_common/lib/ads_common/env_check.rb old mode 100644 new mode 100755 diff --git a/ads_common/lib/ads_common/errors.rb b/ads_common/lib/ads_common/errors.rb old mode 100644 new mode 100755 diff --git a/ads_common/lib/ads_common/http.rb b/ads_common/lib/ads_common/http.rb old mode 100644 new mode 100755 diff --git a/ads_common/lib/ads_common/parameters_validator.rb b/ads_common/lib/ads_common/parameters_validator.rb old mode 100644 new mode 100755 diff --git a/ads_common/lib/ads_common/results_extractor.rb b/ads_common/lib/ads_common/results_extractor.rb old mode 100644 new mode 100755 diff --git a/ads_common/lib/ads_common/savon_headers/base_header_handler.rb b/ads_common/lib/ads_common/savon_headers/base_header_handler.rb old mode 100644 new mode 100755 diff --git a/ads_common/lib/ads_common/savon_headers/oauth_header_handler.rb b/ads_common/lib/ads_common/savon_headers/oauth_header_handler.rb old mode 100644 new mode 100755 diff --git a/ads_common/lib/ads_common/savon_service.rb b/ads_common/lib/ads_common/savon_service.rb old mode 100644 new mode 100755 index 0932a80f3..2a9ab4fc9 --- a/ads_common/lib/ads_common/savon_service.rb +++ b/ads_common/lib/ads_common/savon_service.rb @@ -33,7 +33,7 @@ class SavonService FALLBACK_API_ERROR_EXCEPTION = "ApiException" MAX_FAULT_LOG_LENGTH = 16000 - HEADER_PEEK_LENGTH = 1024 + REDACTED_STR = 'REDACTED' # Creates a new service. def initialize(config, endpoint, namespace, version) @@ -202,34 +202,27 @@ def do_logging(action, request, response) summary_message += ', Fault message: %s' % format_fault( response_hash[:envelope][:body][:fault][:faultstring]) logger.warn(summary_message) - logger.info(request_message) if request_message - logger.info(response_message) if response_message + logger.info(request_message) unless request_message.nil? + logger.info(response_message) unless response_message.nil? else logger.info(summary_message) - logger.debug(request_message) if request_message - logger.debug(response_message) if response_message + logger.debug(request_message) unless request_message.nil? + logger.debug(response_message) unless response_message.nil? end end # Format headers, redacting sensitive information. def format_headers(headers) return headers.map do |k, v| - v = 'REDACTED' if k == 'Authorization' + v = REDACTED_STR if k == 'Authorization' [k, v].join(': ') end.join(', ') end # Sanitize the request body, redacting sensitive information. def sanitize_request(body) - body_tail = "" - if body.length > HEADER_PEEK_LENGTH - body_tail = body[HEADER_PEEK_LENGTH, body.length] - body = body[0, HEADER_PEEK_LENGTH] - end - body = body.gsub(/developerToken>[^<]+<\//, 'developerToken>REDACTED[^<]+<\//, - 'httpAuthorizationHeader>REDACTED|httpAuthorizationHeader>)[^<]+(<\/)/, + '\1' + REDACTED_STR + '\2') end # Format the fault message by capping length and removing newlines. diff --git a/ads_common/lib/ads_common/utils.rb b/ads_common/lib/ads_common/utils.rb old mode 100644 new mode 100755 diff --git a/ads_common/lib/ads_common/version.rb b/ads_common/lib/ads_common/version.rb old mode 100644 new mode 100755 index b34b852cf..6f8a9b4f0 --- a/ads_common/lib/ads_common/version.rb +++ b/ads_common/lib/ads_common/version.rb @@ -19,6 +19,6 @@ module AdsCommon module ApiConfig - CLIENT_LIB_VERSION = '0.14.2' + CLIENT_LIB_VERSION = '1.0.0' end end diff --git a/ads_common/test/test_config.yml b/ads_common/test/test_config.yml old mode 100644 new mode 100755 diff --git a/ads_common/test/test_savon_service.rb b/ads_common/test/test_savon_service.rb index 45fb98366..05971b687 100755 --- a/ads_common/test/test_savon_service.rb +++ b/ads_common/test/test_savon_service.rb @@ -87,23 +87,37 @@ def test_sanitize_request() test1 = "ab1cdEF2GH-IJ3KL_mn4OP" + "" expected1 = "REDACTED" + assert_equal(expected1, @stub_service.sanitize_request(test1)) + test2 = "" + assert_equal(test2, @stub_service.sanitize_request(test2)) + test3 = "w-x_Y-Z_" expected3 = "REDACTED" + assert_equal(expected3, @stub_service.sanitize_request(test3)) + test4 = "Authorization: Bearer " + "1/abcdEFGH1234" expected4 = "REDACTED" + "" + assert_equal(expected4, @stub_service.sanitize_request(test4)) + test5 = "ab1cdEF2GH-IJ3KL_mn4OP" + "" test5 += "something" * 1024 + "" expected5 = "REDACTED" expected5 += "something" * 1024 + "" - assert_equal(expected1, @stub_service.sanitize_request(test1)) - assert_equal(test2, @stub_service.sanitize_request(test2)) - assert_equal(expected3, @stub_service.sanitize_request(test3)) - assert_equal(expected4, @stub_service.sanitize_request(test4)) assert_equal(expected5, @stub_service.sanitize_request(test5)) + + src6 = "abc21.deffoobar" + + "\n" + dst6 = "REDACTED" + + "\n" + test6 = "ab1cdEF2GH-IJ3KL_mn4OP" + + "" + src6 * 128 + "" + expected6 = "REDACTED" + + dst6 * 128 + "" + assert_equal(expected6, @stub_service.sanitize_request(test6)) end def test_format_fault()