diff --git a/app/Controllers/BaseController.php b/app/Controllers/BaseController.php index ebadacc..0cabcf7 100644 --- a/app/Controllers/BaseController.php +++ b/app/Controllers/BaseController.php @@ -168,67 +168,33 @@ abstract class BaseController extends Controller $result = "Unhandled exception"; $base_url = "http://172.16.4.90:3000"; $PROJECT_ID= 8; + $cookies = tempnam('/tmp','cookie.txt'); + # 1. Login $url = $base_url . "/api/project/$PROJECT_ID/tasks"; - $headers = [ - 'Content-Type:application/json', - 'Accept: application/json', - 'Authorization: Bearer ' . $ansibleToken - ]; + log_message('critical', "***** ***** ansibleProvision CALL::URL ". $url); $ch = curl_init( $url ); + # Setup request to send json via POST. $payload = json_encode( $params ); - //$payload = json_encode( array( "template_id"=> 1, "debug" => false, "dry_run" => false, "playbook" => "first-playbook.yml", "environment" => "{}" ) ); + $authorization = "Authorization: Bearer ".$ansibleToken; // Prepare the authorisation token curl_setopt( $ch, CURLOPT_POSTFIELDS, $payload ); - curl_setopt( $ch, CURLOPT_HTTPHEADER, $headers ); + curl_setopt( $ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json',$authorization)); + # Return response instead of printing. curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true ); - $res = curl_exec($ch); + # Fetch the headers, not the body content: + + # Send request. + $result = curl_exec($ch); $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE); - $result .= "\n" . 'Launch task HTTP code: ' . $httpcode; + $result = 'HTTP code: ' . $httpcode; curl_close($ch); - # 4. Get tasks - $url = $base_url . "/api/project/$PROJECT_ID/tasks"; - $ch = curl_init( $url ); - curl_setopt( $ch, CURLOPT_HTTPHEADER, $headers ); - curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true ); - $res = curl_exec($ch); - $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE); - $result .= "\n" . 'Get tasks HTTP code: ' . $httpcode; - - curl_close($ch); log_message('critical', "***** ***** Provision :: ansibleProvision($httpcode) ".$httpcode); - ob_start(); - var_dump($headers); - var_dump($res); - $result .= "\n" . ob_get_clean(); -// $cookies = tempnam('/tmp','cookie.txt'); -// -// # 1. Login -// $url = $base_url . "/api/project/$PROJECT_ID/tasks"; -// log_message('critical', "***** ***** ansibleProvision CALL::URL ". $url); -// $ch = curl_init( $url ); -// # Setup request to send json via POST. -// $payload = json_encode( $params ); -// $authorization = "Authorization: Bearer ".$ansibleToken; // Prepare the authorisation token -// curl_setopt( $ch, CURLOPT_POSTFIELDS, $payload ); -// curl_setopt( $ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json',$authorization)); -// # Return response instead of printing. -// curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true ); -// # Fetch the headers, not the body content: -// -// # Send request. -// $result = curl_exec($ch); -// $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE); -// $result = 'HTTP code: ' . $httpcode; -// -// curl_close($ch); -// -// log_message('critical', "***** ***** Provision :: ansibleProvision($httpcode) ".$httpcode); -// -// if ($httpcode != "204") { -// return "Login failed! $result"; -// } + + if ($httpcode != "204") { + return "Login failed! $result"; + } return 0;