Google-Ads-GoogleAds-Client

 view release on metacpan or  search on metacpan

lib/Google/Ads/GoogleAds/Logging/DetailStats.pm  view on Meta::CPAN


  # Scrub the sensitive fields in the HTTP request and response.
  $request_content  = _scrub_content($request_content);
  $request_content  = _scrub_gaql($request_content);
  $response_content = _scrub_content($response_content) if $response_content;

  my $json_coder     = JSON::XS->new->utf8->pretty;
  my $detail_message = sprintf(
    "Request\n" .
      "-------\n" . "MethodName: %s\n" . "Host: %s\n" . "Headers: %s\n" .
      "Request: %s\n" . "\nResponse\n" . "-------\n" . "Headers: %s\n",
    $method,          $host, $json_coder->encode({%$request_headers}),
    $request_content, $json_coder->encode({%$response_headers}));

  $detail_message .= "Response: ${response_content}\n" if $response_content;
  $detail_message .= "Fault: ${fault}\n"               if $fault;

  return $detail_message;
}

# Scrubs the sensitive fields in HTTP content.
sub _scrub_content {
  my $content = shift;
  foreach my $field (SCRUBBED_CONTENT_FIELDS) {
    $content =~ s/("$field"\s?:\s?)".+?"/$1"${\REDACTED_STRING}"/g;
  }

  return $content;
}

# Scrubs the sensitive fields in GAQL statement.
sub _scrub_gaql {
  my $content = shift;

  return $content if $content !~ /"query"/;
  foreach my $field (SCRUBBED_GAQL_FIELDS) {
    $content =~
      s/(SELECT.+WHERE.+$field.+?['"])\S+?(['"])/$1${\REDACTED_STRING}$2/i;
  }

  return $content;
}

return 1;

=pod

=head1 NAME

Google::Ads::GoogleAds::Logging::DetailStats

=head1 DESCRIPTION

Class that wraps the detailed HTTP request and response like host, method,
headers, payload.

=head1 ATTRIBUTES

=head2 host

The Google Ads API server endpoint.

=head2 method

The name of the service method that was called.

=head2 request_headers

The REST HTTP request headers.

=head2 request_content

The REST HTTP request payload.

=head2 response_headers

The REST HTTP response headers.

=head2 response_content

The REST HTTP response payload.

=head2 fault

The stack trace of up to 16K characters if a fault occurs.

=head1 LICENSE AND COPYRIGHT

Copyright 2019 Google LLC

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

=head1 REPOSITORY INFORMATION

 $Rev: $
 $LastChangedBy: $
 $Id: $

=cut



( run in 4.613 seconds using v1.01-cache-2.11-cpan-99c4e6809bf )