Task submission example
This commit is contained in:
@@ -335,6 +335,7 @@ class Provision extends BaseController
|
|||||||
|
|
||||||
public function demo():string {
|
public function demo():string {
|
||||||
|
|
||||||
|
$PROJECT_ID = 8;
|
||||||
$result = "Unhandled exception";
|
$result = "Unhandled exception";
|
||||||
$base_url = "http://172.16.4.90:3000";
|
$base_url = "http://172.16.4.90:3000";
|
||||||
$cookies = tempnam('/tmp','cookie.txt');
|
$cookies = tempnam('/tmp','cookie.txt');
|
||||||
@@ -372,12 +373,12 @@ class Provision extends BaseController
|
|||||||
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
|
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
|
||||||
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookies);
|
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookies);
|
||||||
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookies);
|
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookies);
|
||||||
$result = curl_exec($ch);
|
$res = curl_exec($ch);
|
||||||
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||||
curl_close($ch);
|
curl_close($ch);
|
||||||
|
|
||||||
$token = null;
|
$token = null;
|
||||||
$arr = json_decode($result, true);
|
$arr = json_decode($res, true);
|
||||||
foreach ($arr as $item) {
|
foreach ($arr as $item) {
|
||||||
if ($item["expired"]===false) {
|
if ($item["expired"]===false) {
|
||||||
$token = $item["id"];
|
$token = $item["id"];
|
||||||
@@ -387,6 +388,41 @@ class Provision extends BaseController
|
|||||||
}
|
}
|
||||||
$result = "Found token: $token";
|
$result = "Found token: $token";
|
||||||
|
|
||||||
|
# 3. Lauch task
|
||||||
|
$PROJECT_ID = 7;
|
||||||
|
$url = $base_url . "/api/project/$PROJECT_ID/tasks";
|
||||||
|
$headers = [
|
||||||
|
'Content-Type:application/json',
|
||||||
|
'Accept: application/json',
|
||||||
|
'Authorization: Bearer ' . $token
|
||||||
|
];
|
||||||
|
$ch = curl_init( $url );
|
||||||
|
$payload = json_encode( array( "template_id"=> 1, "debug" => false, "dry_run" => false, "playbook" => "first-playbook.yml", "environment" => "{}" ) );
|
||||||
|
curl_setopt( $ch, CURLOPT_POSTFIELDS, $payload );
|
||||||
|
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" . 'Launch task 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);
|
||||||
|
|
||||||
|
ob_start();
|
||||||
|
var_dump($headers);
|
||||||
|
var_dump($res);
|
||||||
|
$result .= "\n" . ob_get_clean();
|
||||||
|
|
||||||
# Print response.
|
# Print response.
|
||||||
return "<pre>$result</pre>";
|
return "<pre>$result</pre>";
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user