Advertisement
Guest User

GIS admin

a guest
Jul 16th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 7.69 KB | None | 0 0
  1. diff --git a/configuration/shared/rpc.tmpl b/configuration/shared/rpc.tmpl
  2. index b7c625a..62e232a 100644
  3. --- a/configuration/shared/rpc.tmpl
  4. +++ b/configuration/shared/rpc.tmpl
  5. @@ -182,6 +182,13 @@
  6.                  method => 'getPersonDetailsRPC',
  7.                  encoder => 'Cpanel::JSON::XS',
  8.              },
  9. +            'service.agent.token.get_device_data' => {
  10. +                state => 'content',
  11. +                type => 'method',
  12. +                subpack => 'Service::Agent::Session_v1_0',
  13. +                method => 'getBrandAndStoreFromDeviceID',
  14. +                encoder => 'Cpanel::JSON::XS',
  15. +            },
  16.  
  17. diff --git a/server/generic/Generic/Service/Agent/Applications.pm b/server/generic/Generic/Service/Agent/Applications.pm
  18. index a08aaa7..eb2a99c 100644
  19. --- a/server/generic/Generic/Service/Agent/Applications.pm
  20. +++ b/server/generic/Generic/Service/Agent/Applications.pm
  21. @@ -24,7 +24,7 @@ sub serviceGet {
  22.      }
  23.  
  24.      # Parse store id from passed in device id, we will use this to filter the applications returned
  25. -    my $store_info = $self->getBrandAndStoreFromDeviceID($args->{device_id});
  26. +    my $store_info = $self->getBrandAndStoreFromDeviceID({ 'device_id' => $args->{device_id}});
  27.  
  28.      my $allowed_apps_for_store = $self->_getApplicationsForStoreId({store_id => $store_info->{store_id}});
  29.  
  30. diff --git a/server/generic/Generic/Service/Agent/Session_v1_0.pm b/server/generic/Generic/Service/Agent/Session_v1_0.pm
  31. index c6edde3..d608098 100644
  32. --- a/server/generic/Generic/Service/Agent/Session_v1_0.pm
  33. +++ b/server/generic/Generic/Service/Agent/Session_v1_0.pm
  34. @@ -17,7 +17,9 @@ sub jsonSchemaOutPost
  35.  }
  36.  
  37.  sub getDeviceDataFromDB {
  38. -    my ( $self, $device_id ) = @_;
  39. +    my ( $self, $args ) = @_;
  40. +    my $device_id = $args->{device_id};
  41. +    my $show_debug = $args->{show_debug};
  42.  
  43.      my $db = $self->get('DB');
  44.      my $prefix = $db->prefix;
  45. @@ -36,14 +38,59 @@ sub getDeviceDataFromDB {
  46.      my $agent_config = $self->get('Configuration')->appConfig('agent_api');
  47.      my $gis_brand_mapping = $$agent_config{'%gis_brand_mapping'};
  48.  
  49. -    return {
  50. +    my $store_info = {
  51.          brand_id => $gis_brand_mapping->{$row[0]},
  52.          store_id => $store_id,
  53.      };
  54. +    if ($show_debug) {
  55. +        $store_info->{data_source} = 'DB Cache';
  56. +        $store_info->{brand_id_raw} = $row[0];
  57. +    }
  58. +    return $store_info;
  59. +}
  60. +
  61. +sub getDeviceDataFromGis {
  62. +    my ( $self, $args ) = @_;
  63. +    my $device_id = $args->{device_id};
  64. +    my $show_debug = $args->{show_debug};
  65. +    my $store_info = {};
  66. +    my $env_config = Generic::Environment::extract(['gis_device_service']);
  67. +    my $agent_config = $self->get('Configuration')->appConfig('agent_api');
  68. +    my $query_url = $env_config->{server_url} . '?serialnumber=' . $device_id;
  69. +    my $req = HTTP::Request->new( 'POST', $query_url);
  70. +    $req->header('Accept' => 'application/json');
  71. +    my $lwp =  LWP::UserAgent->new;
  72. +
  73. +    $req->authorization_basic($env_config->{username}, $env_config->{password});
  74. +    my $res = $lwp->request($req);
  75. +    if ($res->is_success) {
  76. +        my $response = $res->decoded_content((charset => 'utf8'));
  77. +        my $json = $self->get('Util::JSON');
  78. +        $json->fromJson($response);
  79. +        $response = $json->asJson;
  80. +        $store_info->{store_id} = $response->{'mdmRequestOutput'}{'Door'};
  81. +        # GIS returns brands in an invalid format, we need to translate them per OAB-1843
  82. +        my $gis_brand_mapping = $$agent_config{'%gis_brand_mapping'};
  83. +         if ($show_debug) {
  84. +            $store_info->{data_source} = 'GIS Api';
  85. +            $store_info->{brand_id_raw} = $response->{'mdmRequestOutput'}{'Brand'};
  86. +        }
  87. +        $store_info->{brand_id} = $gis_brand_mapping->{$response->{'mdmRequestOutput'}{'Brand'}};
  88. +    } else {
  89. +        my $error_info = "getDeviceDataFromGis error: \nquery_url: " .$query_url."\nbase url: ". $res->base ."\n".  $res->code ."\n". $res->message ."
  90. \n". $res->as_string();
  91. +        $self->rlog->warn($error_info);
  92. +        if ($show_debug) {
  93. +            $store_info->{gis_error} = $error_info;
  94. +        }
  95. +    }
  96. +
  97. +    return $store_info;
  98.  }
  99.  
  100.  sub getBrandAndStoreFromDeviceID {
  101. -    my ( $self, $device_id ) = @_;
  102. +    my ( $self, $args ) = @_;
  103. +    my $device_id = $args->{device_id};
  104. +    my $show_debug = $args->{show_debug};
  105.      my $store_info = {};
  106.      # Need to support the old method of getting brand and store directly from the device id
  107.      if (length($device_id) > 20) {
  108. @@ -52,33 +99,11 @@ sub getBrandAndStoreFromDeviceID {
  109.          $store_info->{brand_id} =~ s/^\s+|\s+$//g;
  110.      } else {
  111.          # First, try to get the data from the DB (cached data from GIS)
  112. -        $store_info = $self->getDeviceDataFromDB($device_id);
  113. +        $store_info = $self->getDeviceDataFromDB({ 'device_id' => $device_id, 'show_debug' => $show_debug});
  114.          unless ($store_info) {
  115. -            my $env_config = Generic::Environment::extract(['gis_device_service']);
  116. -            my $agent_config = $self->get('Configuration')->appConfig('agent_api');
  117. -            my $query_url = $env_config->{server_url} . '?serialnumber=' . $device_id;
  118. -            my $req = HTTP::Request->new( 'POST', $query_url);
  119. -            $req->header('Accept' => 'application/json');
  120. -            my $lwp =  LWP::UserAgent->new;
  121. -
  122. -            $req->authorization_basic($env_config->{username}, $env_config->{password});
  123. -            my $res = $lwp->request($req);
  124. -            if ($res->is_success) {
  125. -                my $response = $res->decoded_content((charset => 'utf8'));
  126. -                my $json = $self->get('Util::JSON');
  127. -                $json->fromJson($response);
  128. -                $response = $json->asJson;
  129. -                $store_info->{store_id} = $response->{'mdmRequestOutput'}{'Door'};
  130. -                # GIS returns brands in an invalid format, we need to translate them per OAB-1843
  131. -                my $gis_brand_mapping = $$agent_config{'%gis_brand_mapping'};
  132. -                $store_info->{brand_id} = $gis_brand_mapping->{$response->{'mdmRequestOutput'}{'Brand'}};
  133. -            } else {
  134. -                my $error_info = "_getBrandAndStoreFromDeviceID error: \nquery_url: " .$query_url."\nbase url: ". $res->base ."\n".  $res->code ."\n".
  135.  $res->message ."\n". $res->as_string();
  136. -                $self->rlog->warn($error_info);
  137. -            }
  138. +            $store_info = $self->getDeviceDataFromGis({ 'device_id' => $device_id, 'show_debug' => $show_debug});
  139.          }
  140.      }
  141. -
  142.      return $store_info;
  143.  }
  144.  
  145. diff --git a/server/generic/Generic/Service/Agent/Token.pm b/server/generic/Generic/Service/Agent/Token.pm
  146. index 2445584..308141d 100644
  147. --- a/server/generic/Generic/Service/Agent/Token.pm
  148. +++ b/server/generic/Generic/Service/Agent/Token.pm
  149. @@ -20,7 +20,7 @@ sub servicePost {
  150.  
  151.      my $device_id = $args->{'device_id'};
  152.  
  153. -    my $store_info = $self->getBrandAndStoreFromDeviceID($device_id);
  154. +    my $store_info = $self->getBrandAndStoreFromDeviceID({'device_id' => $device_id});
  155.  
  156.      # Set up JSON stuff to validate
  157.      my $validation_schema = $self->get( 'JSON::Schema::ValidationObject', {
  158. diff --git a/server/generic/Generic/Service/CSAPP/Authorize_v1_1.pm b/server/generic/Generic/Service/CSAPP/Authorize_v1_1.pm
  159. index ad16c38..6b3ba98 100644
  160. --- a/server/generic/Generic/Service/CSAPP/Authorize_v1_1.pm
  161. +++ b/server/generic/Generic/Service/CSAPP/Authorize_v1_1.pm
  162. @@ -118,7 +118,7 @@ sub _servicePostPassword {
  163.  
  164.      # get info on device_id
  165.      my $device_id = $args->{device_id};
  166. -    my $store_info = $ts->getBrandAndStoreFromDeviceID($device_id);
  167. +    my $store_info = $ts->getBrandAndStoreFromDeviceID({'device_id' => $device_id});
  168.  
  169.      my $device_id_messaging = '';
  170.      unless ($device_id) {
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement