1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
namespace Lookyman\Rundeck\Api\Endpoints\System; |
5
|
|
|
|
6
|
|
|
use GuzzleHttp\Promise\PromiseInterface; |
7
|
|
|
use Lookyman\Rundeck\Api\Client; |
8
|
|
|
use GuzzleHttp\Psr7\Request; |
9
|
|
|
|
10
|
|
|
class Execution |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* @var Client |
14
|
|
|
*/ |
15
|
|
|
private $client; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @param Client $client |
19
|
|
|
*/ |
20
|
|
|
public function __construct(Client $client) |
21
|
|
|
{ |
22
|
|
|
$this->client = $client; |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @param string $id |
27
|
|
|
* @return PromiseInterface |
28
|
|
|
*/ |
29
|
|
|
public function info(string $id): PromiseInterface |
30
|
|
|
{ |
31
|
|
|
return $this->client->getConfiguration()->getGuzzle()->sendAsync( |
32
|
|
|
new Request('GET', $this->client->getConfiguration()->getBaseUri() . sprintf('/execution/%s', urlencode($id))) |
33
|
|
|
); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @param string $id |
38
|
|
|
* @return PromiseInterface |
39
|
|
|
*/ |
40
|
|
|
public function delete(string $id): PromiseInterface |
41
|
|
|
{ |
42
|
|
|
return $this->client->getConfiguration()->getGuzzle()->sendAsync( |
43
|
|
|
new Request('DELETE', $this->client->getConfiguration()->getBaseUri() . sprintf('/execution/%s', urlencode($id))) |
44
|
|
|
); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @param int[] $ids |
49
|
|
|
* @return PromiseInterface |
50
|
|
|
*/ |
51
|
|
|
public function bulkDelete(array $ids): PromiseInterface |
52
|
|
|
{ |
53
|
|
|
return $this->client->getConfiguration()->getGuzzle()->sendAsync( |
54
|
|
|
new Request('POST', $this->client->getConfiguration()->getBaseUri() . '/executions/delete', [], $this->client->getConfiguration()->getFormat()->formatParams(['ids' => $ids])) |
55
|
|
|
); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @param string $id |
60
|
|
|
* @return PromiseInterface |
61
|
|
|
*/ |
62
|
|
|
public function state(string $id): PromiseInterface |
63
|
|
|
{ |
64
|
|
|
return $this->client->getConfiguration()->getGuzzle()->sendAsync( |
65
|
|
|
new Request('GET', $this->client->getConfiguration()->getBaseUri() . sprintf('/execution/%s/state', urlencode($id))) |
66
|
|
|
); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @param string $id |
71
|
|
|
* @param string|null $node |
72
|
|
|
* @param string|null $step |
73
|
|
|
* @param array $params |
74
|
|
|
* @return PromiseInterface |
75
|
|
|
*/ |
76
|
|
|
public function output(string $id, string $node = null, string $step = null, array $params = []): PromiseInterface |
77
|
|
|
{ |
78
|
|
|
if ($node && $step) { |
|
|
|
|
79
|
|
|
$path = sprintf('/execution/%s/output/node/%s/step/%s', urlencode($id), urlencode($node), urlencode($step)); |
80
|
|
|
} elseif ($node && !$step) { |
|
|
|
|
81
|
|
|
$path = sprintf('/execution/%s/output/node/%s', urlencode($id), urlencode($node)); |
82
|
|
|
} elseif (!$node && $step) { |
|
|
|
|
83
|
|
|
$path = sprintf('/execution/%s/output/step/%s', urlencode($id), urlencode($step)); |
84
|
|
|
} else { |
85
|
|
|
$path = sprintf('/execution/%s/output', urlencode($id)); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
return $this->client->getConfiguration()->getGuzzle()->sendAsync( |
89
|
|
|
new Request('GET', $this->client->getConfiguration()->getBaseUri() . $path, [], $this->client->getConfiguration()->getFormat()->formatParams($params)) |
90
|
|
|
); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @param string $id |
95
|
|
|
* @param bool $stateOnly |
96
|
|
|
* @return PromiseInterface |
97
|
|
|
*/ |
98
|
|
|
public function outputWithState(string $id, bool $stateOnly = false): PromiseInterface |
99
|
|
|
{ |
100
|
|
|
return $this->client->getConfiguration()->getGuzzle()->sendAsync( |
101
|
|
|
new Request('GET', $this->client->getConfiguration()->getBaseUri() . sprintf('/execution/%s/output/state%s', urlencode($id), $stateOnly ? '?stateOnly=true' : '')) |
102
|
|
|
); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* @param string $id |
107
|
|
|
* @param array $params |
108
|
|
|
* @return PromiseInterface |
109
|
|
|
*/ |
110
|
|
|
public function abort(string $id, array $params = []): PromiseInterface |
111
|
|
|
{ |
112
|
|
|
return $this->client->getConfiguration()->getGuzzle()->sendAsync( |
113
|
|
|
new Request( |
114
|
|
|
'GET', |
115
|
|
|
$this->client->getConfiguration()->getBaseUri() . sprintf('/execution/%s/abort', urlencode($id)), |
116
|
|
|
[], |
117
|
|
|
$this->client->getConfiguration()->getFormat()->formatParams($params)) |
118
|
|
|
); |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* @return PromiseInterface |
123
|
|
|
*/ |
124
|
|
|
public function enable(): PromiseInterface |
125
|
|
|
{ |
126
|
|
|
return $this->client->getConfiguration()->getGuzzle()->sendAsync( |
127
|
|
|
new Request('POST', $this->client->getConfiguration()->getBaseUri() . '/system/executions/enable') |
128
|
|
|
); |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* @return PromiseInterface |
133
|
|
|
*/ |
134
|
|
|
public function disable(): PromiseInterface |
135
|
|
|
{ |
136
|
|
|
return $this->client->getConfiguration()->getGuzzle()->sendAsync( |
137
|
|
|
new Request('POST', $this->client->getConfiguration()->getBaseUri() . '/system/executions/disable') |
138
|
|
|
); |
139
|
|
|
} |
140
|
|
|
} |
141
|
|
|
|
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
string
values, the empty string''
is a special case, in particular the following results might be unexpected: