« lib/Google/Ads/AdWords/RequestStats.pm
↑ Summary
lib/Google/Ads/AdWords/Utilities/BatchJobHandlerStatus.pm »
| 1 | # Copyright 2011, Google Inc. All Rights Reserved. | ||
| 2 | # | ||
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 4 | # you may not use this file except in compliance with the License. | ||
| 5 | # You may obtain a copy of the License at | ||
| 6 | # | ||
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 | ||
| 8 | # | ||
| 9 | # Unless required by applicable law or agreed to in writing, software | ||
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, | ||
| 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 12 | # See the License for the specific language governing permissions and | ||
| 13 | # limitations under the License. | ||
| 14 | |||
| 15 | package Google::Ads::AdWords::Serializer; | ||
| 16 | |||
| 17 | 2 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 18 | 2 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 19 | 2 | ▶ | use utf8; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 20 | 2 | ▶ | use version; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 21 | |||
| 22 | 2 | ▶ | use base qw(SOAP::WSDL::Serializer::XSD); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 23 | |||
| 24 | # The following needs to be on one line because CPAN uses a particularly hacky | ||
| 25 | # eval() to determine module versions. | ||
| 26 | 2 | ▶ | use Google::Ads::Common::Constants; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 27 | 2 | ▶ | use Google::Ads::AdWords::Constants; our $VERSION = ${Google::Ads::AdWords::Constants::VERSION}; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 28 | 2 | ▶ | use Google::Ads::AdWords::Logging; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 29 | |||
| 30 | 2 | ▶ | use Class::Std::Fast; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 31 | 2 | ▶ | use SOAP::WSDL::Factory::Serializer; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 32 | |||
| 33 | # A list of fields that need to be scrubbed before logging due to sensitive | ||
| 34 | # content. | ||
| 35 | 2 | ▶ | use constant SCRUBBED_FIELDS => qw(developerToken httpAuthorizationHeader); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 36 | |||
| 37 | # Class attributes used to hook this class with the AdWords client. | ||
| 38 | 1 | my %client_of : ATTR(:name<client> :default<>); | |
| 39 | |||
| 40 | # Invoked by SOAP::WSDL to serialize outgoing SOAP requests. | ||
| 41 | sub serialize { | ||
| 42 | my $self = shift; | ||
| 43 | my $client = $self->get_client(); | ||
| 44 | my $request = $self->SUPER::serialize(@_); | ||
| 45 | utf8::is_utf8 $request and utf8::encode $request; | ||
| 46 | |||
| 47 | my $sanitized_request = __scrub_request($request); | ||
| 48 | |||
| 49 | my $auth_handler = $client->_get_auth_handler(); | ||
| 50 | |||
| 51 | # The request will be logged when the response comes back in Deserializer. | ||
| 52 | $client->set_last_soap_request($sanitized_request); | ||
| 53 | |||
| 54 | return $request; | ||
| 55 | } | ||
| 56 | |||
| 57 | # Invoked by SOAP::WSDL to serialize outgoing SOAP header, AdWords header | ||
| 58 | # information is injected at this time. | ||
| 59 | sub serialize_header { | ||
| 60 | my $self = shift; | ||
| 61 | my $client = $self->get_client(); | ||
| 62 | my $client_header = $client->_get_header(); | ||
| 63 | my $adwords_header = $_[1]; | ||
| 64 | |||
| 65 | $adwords_header->set_clientCustomerId($client_header->{clientCustomerId}); | ||
| 66 | $adwords_header->set_developerToken($client_header->{developerToken}); | ||
| 67 | $adwords_header->set_userAgent($client_header->{userAgent}); | ||
| 68 | $adwords_header->set_validateOnly($client_header->{validateOnly}); | ||
| 69 | if ($adwords_header->can("set_partialFailure")) { | ||
| 70 | $adwords_header->set_partialFailure($client_header->{partialFailure}); | ||
| 71 | } | ||
| 72 | |||
| 73 | # Serialize the header. | ||
| 74 | my $header = $self->SUPER::serialize_header(@_); | ||
| 75 | |||
| 76 | # Hack the header inner elements to correctly include the namespaces. | ||
| 77 | my $xmlns = | ||
| 78 | "https://adwords.google.com/api/adwords/cm/" . $client->get_version; | ||
| 79 | $header =~ s/<developerToken>/<developerToken xmlns="$xmlns">/; | ||
| 80 | $header =~ s/<userAgent>/<userAgent xmlns="$xmlns">/; | ||
| 81 | $header =~ s/<validateOnly>/<validateOnly xmlns="$xmlns">/; | ||
| 82 | $header =~ s/<clientCustomerId>/<clientCustomerId xmlns="$xmlns">/; | ||
| 83 | $header =~ s/<partialFailure>/<partialFailure xmlns="$xmlns">/; | ||
| 84 | |||
| 85 | return $header; | ||
| 86 | } | ||
| 87 | |||
| 88 | # Private method to redact sensitive information from requests before logging. | ||
| 89 | sub __scrub_request { | ||
| 90 | my ($request) = @_; | ||
| 91 | my $scrubbed_request = $request; | ||
| 92 | foreach my $header (SCRUBBED_FIELDS) { | ||
| 93 | $scrubbed_request =~ | ||
| 94 | s!<$header([^>]*)>.+?</$header>!<$header$1>REDACTED</$header>!; | ||
| 95 | } | ||
| 96 | return $scrubbed_request; | ||
| 97 | } | ||
| 98 | |||
| 99 | 1 | return 1; | |
| 100 | |||
| 101 | =pod | ||
| 102 | |||
| 103 | =head1 NAME | ||
| 104 | |||
| 105 | Google::Ads::AdWords::Serializer | ||
| 106 | |||
| 107 | =head1 DESCRIPTION | ||
| 108 | |||
| 109 | Google::Ads::AdWords::Deserializer extends the | ||
| 110 | L<SOAP::WSDL::Serializer::XSD|SOAP::WSDL::Serializer::XSD> module. Above the | ||
| 111 | normal functionality of | ||
| 112 | L<SOAP::WSDL::Serializer::XSD|SOAP::WSDL::Serializer::XSD>, this module | ||
| 113 | implements hooks into | ||
| 114 | L<Google::Ads::AdWords::Client|Google::Ads::AdWords::Client> to inject AdWords | ||
| 115 | API Header parameters as well as hooks into | ||
| 116 | L<Google::Ads::AdWords::Client|Google::Ads::AdWords::Logging> to log SOAP | ||
| 117 | request XML. | ||
| 118 | |||
| 119 | =head1 METHODS | ||
| 120 | |||
| 121 | =head2 serialize | ||
| 122 | |||
| 123 | A method automatically invoked by SOAP::WSDL when an outgoing request needs to | ||
| 124 | be serialized into SOAP XML. SOAP XML request is logged by this method. | ||
| 125 | |||
| 126 | =head3 Parameters | ||
| 127 | |||
| 128 | The SOAP request. | ||
| 129 | |||
| 130 | =head3 Returns | ||
| 131 | |||
| 132 | The SOAP XML string representing the request. | ||
| 133 | |||
| 134 | =head2 serialize_header | ||
| 135 | |||
| 136 | A method automatically invoked by SOAP::WSDL when an outgoing request header | ||
| 137 | needs to be serialized into SOAP XML. At this time API headers are injected in | ||
| 138 | the message. | ||
| 139 | |||
| 140 | =head3 Parameters | ||
| 141 | |||
| 142 | The SOAP request. | ||
| 143 | |||
| 144 | =head3 Returns | ||
| 145 | |||
| 146 | The SOAP XML string representing the request. | ||
| 147 | |||
| 148 | =head2 __scrub_request (Private) | ||
| 149 | |||
| 150 | Scrubs sensitive information from the request before it's logged. | ||
| 151 | |||
| 152 | =head3 Parameters | ||
| 153 | |||
| 154 | The serialized SOAP request XML string. | ||
| 155 | |||
| 156 | =head3 Returns | ||
| 157 | |||
| 158 | A redacted version of the string. | ||
| 159 | |||
| 160 | =head1 LICENSE AND COPYRIGHT | ||
| 161 | |||
| 162 | Copyright 2011 Google Inc. | ||
| 163 | |||
| 164 | Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 165 | you may not use this file except in compliance with the License. | ||
| 166 | You may obtain a copy of the License at | ||
| 167 | |||
| 168 | http://www.apache.org/licenses/LICENSE-2.0 | ||
| 169 | |||
| 170 | Unless required by applicable law or agreed to in writing, software | ||
| 171 | distributed under the License is distributed on an "AS IS" BASIS, | ||
| 172 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 173 | See the License for the specific language governing permissions and | ||
| 174 | limitations under the License. | ||
| 175 | |||
| 176 | =head1 REPOSITORY INFORMATION | ||
| 177 | |||
| 178 | $Rev: $ | ||
| 179 | $LastChangedBy: $ | ||
| 180 | $Id: $ | ||
| 181 | |||
| 182 | =cut | ||