Merge branch 'appsubmit-ws' into 'develop'

Encrypt logs; fix responses

See merge request !148
parents 6e8cb5ec 8919db25
...@@ -5,6 +5,8 @@ namespace Drupal\epal; ...@@ -5,6 +5,8 @@ namespace Drupal\epal;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
use Exception; use Exception;
use Drupal\epal\Crypt;
/** /**
* Description of Client * Description of Client
* *
...@@ -171,30 +173,32 @@ class Client ...@@ -171,30 +173,32 @@ class Client
}, ''); }, '');
$result = $this->get($endpoint, [], $headers); // data as path params... $result = $this->get($endpoint, [], $headers); // data as path params...
try {
$crypt = new Crypt();
$val = 'call:' . print_r($endpoint, true) . ':rcv:' . print_r($result, true);
$val_enc = $crypt->encrypt($val);
$this->log(__METHOD__ . $val_enc, 'info');
} catch (\Exception $e) {
$this->log(__METHOD__ . " cannot log encrypted", 'info');
}
if ($result['success'] === false) { if ($result['success'] === false) {
$this->log(__METHOD__ . " Error while calling ws. Diagnostic: {$result['response']}. Response code: {$result['http_status']}", "error"); $this->log(__METHOD__ . " Error while calling ws. Diagnostic: {$result['response']}. Response code: {$result['http_status']}", "error");
throw new Exception("Προέκυψε λάθος κατά την άντληση των στοιχείων."); throw new Exception("Προέκυψε λάθος κατά την άντληση των στοιχείων.");
} }
// now return true/false/null ?
return $result['response']; return $result['response'];
// if (($response = json_decode($result['response'], true)) !== null) {
// return $response;
// } else {
// throw new Exception("Προέκυψε λάθος κατά την λήψη των στοιχείων. Αδυναμία άντλησης στοιχείων από το response {$result['response']}");
// }
} }
public function getStudentEpalPromotion($didactic_year_id, $lastname, $firstname, $father_firstname, $mother_firstname, $birthdate, $registry_no, $level_name) public function getStudentEpalPromotion($didactic_year_id, $lastname, $firstname, $father_firstname, $mother_firstname, $birthdate, $registry_no, $level_name)
{ {
$this->log(__METHOD__); // " $didactic_year_id, $lastname, $firstname, $father_firstname, $mother_firstname, $birthdate, $registry_no, $level_name"); $this->log(__METHOD__);
return $this->getStudentEpalPromotionOrCertification($this->_settings['ws_endpoint_studentepalpromotion'], $didactic_year_id, $lastname, $firstname, $father_firstname, $mother_firstname, $birthdate, $registry_no, $level_name); return $this->getStudentEpalPromotionOrCertification($this->_settings['ws_endpoint_studentepalpromotion'], $didactic_year_id, $lastname, $firstname, $father_firstname, $mother_firstname, $birthdate, $registry_no, $level_name);
} }
public function getStudentEpalCertification($didactic_year_id, $lastname, $firstname, $father_firstname, $mother_firstname, $birthdate, $registry_no, $level_name) public function getStudentEpalCertification($didactic_year_id, $lastname, $firstname, $father_firstname, $mother_firstname, $birthdate, $registry_no, $level_name)
{ {
$this->log(__METHOD__); // " $didactic_year_id, $lastname, $firstname, $father_firstname, $mother_firstname, $birthdate, $registry_no, $level_name"); $this->log(__METHOD__);
return $this->getStudentEpalPromotionOrCertification($this->_settings['ws_endpoint_studentepalcertification'], $didactic_year_id, $lastname, $firstname, $father_firstname, $mother_firstname, $birthdate, $registry_no, $level_name); return $this->getStudentEpalPromotionOrCertification($this->_settings['ws_endpoint_studentepalcertification'], $didactic_year_id, $lastname, $firstname, $father_firstname, $mother_firstname, $birthdate, $registry_no, $level_name);
} }
...@@ -228,6 +232,14 @@ class Client ...@@ -228,6 +232,14 @@ class Client
$result = curl_exec($ch); $result = curl_exec($ch);
// log url as appropriate
try {
$crypt = new Crypt();
$uri = $crypt->encrypt($uri);
} catch (\Exception $e) {
$uri = '-cannot encrypt-';
}
if (curl_errno($ch)) { if (curl_errno($ch)) {
$this->log(__METHOD__ . " Error calling {$uri}. Curl error: " . curl_error($ch) . " Curl info: " . var_export(curl_getinfo($ch), true), "error"); $this->log(__METHOD__ . " Error calling {$uri}. Curl error: " . curl_error($ch) . " Curl info: " . var_export(curl_getinfo($ch), true), "error");
throw new Exception("Λάθος κατά την κλήση της υπηρεσίας."); throw new Exception("Λάθος κατά την κλήση της υπηρεσίας.");
...@@ -263,6 +275,14 @@ class Client ...@@ -263,6 +275,14 @@ class Client
$result = curl_exec($ch); $result = curl_exec($ch);
// log url as appropriate
try {
$crypt = new Crypt();
$uri = $crypt->encrypt($uri);
} catch (\Exception $e) {
$uri = '-cannot encrypt-';
}
if (curl_errno($ch)) { if (curl_errno($ch)) {
$this->log(__METHOD__ . " Error calling {$uri}. Curl error: " . curl_error($ch) . " Curl info: " . var_export(curl_getinfo($ch), true), "error"); $this->log(__METHOD__ . " Error calling {$uri}. Curl error: " . curl_error($ch) . " Curl info: " . var_export(curl_getinfo($ch), true), "error");
throw new Exception("Λάθος κατά την κλήση της υπηρεσίας."); throw new Exception("Λάθος κατά την κλήση της υπηρεσίας.");
......
...@@ -266,7 +266,7 @@ class ApplicationSubmit extends ControllerBase ...@@ -266,7 +266,7 @@ class ApplicationSubmit extends ControllerBase
(checkdate($date_parts[1], $date_parts[2], $date_parts[0]) !== true)) { (checkdate($date_parts[1], $date_parts[2], $date_parts[0]) !== true)) {
return 1003; return 1003;
} }
/* $birthdate = "{$date_parts[2]}-{$date_parts[1]}-{$date_parts[0]}"; $birthdate = "{$date_parts[2]}-{$date_parts[1]}-{$date_parts[0]}";
// check as per specs: // check as per specs:
// - can't check certification prior to 2014, pass through // - can't check certification prior to 2014, pass through
...@@ -307,12 +307,12 @@ class ApplicationSubmit extends ControllerBase ...@@ -307,12 +307,12 @@ class ApplicationSubmit extends ControllerBase
$student['lastschool_registrynumber'], $student['lastschool_registrynumber'],
$level_name $level_name
); );
$pass = ($service_rv === true); $pass = ($service_rv == 'true');
if ($service_rv === true) { if ($service_rv == 'true') {
$error_code = 0; $error_code = 0;
} elseif ($service_rv === false) { } elseif ($service_rv == 'false') {
$error_code = 8002; $error_code = 8002;
} elseif ($service_rv === null) { } elseif ($service_rv == 'null') {
$error_code = 8003; $error_code = 8003;
} else { } else {
// -1 is an exception and data is already validated // -1 is an exception and data is already validated
...@@ -324,23 +324,6 @@ class ApplicationSubmit extends ControllerBase ...@@ -324,23 +324,6 @@ class ApplicationSubmit extends ControllerBase
} }
} }
// TODO REMOVE return $error_code;
$this->logger->info(
'check certification: [' . var_export($check_certification, true) . '] ' .
'check promotion: [' . var_export($check_promotion, true) . '] ' .
'pass: [' . var_export($pass, true) . '] ' .
'check: ' . print_r([
$didactic_year_id,
$student['studentsurname'],
$student['name'],
$student['fatherfirstname'],
$student['motherfirstname'],
$birthdate,
$student['lastschool_registrynumber'],
$level_name
], true));
// return 1000; // TODO stop here until all checks are finished
return $error_code; */
} }
} }
...@@ -118,10 +118,4 @@ class WSConsumer extends ControllerBase ...@@ -118,10 +118,4 @@ class WSConsumer extends ControllerBase
return $randomString; return $randomString;
} }
// private function respondWithStatus($arr, $s)
// {
// $res = new JsonResponse($arr);
// $res->setStatusCode($s);
// return $res;
// }
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment