Skip to content

Commit 3362348

Browse files
committed
Remove deprecated function calls
1 parent 38feac9 commit 3362348

File tree

3 files changed

+9
-87
lines changed

3 files changed

+9
-87
lines changed

app/Models/Node.php

Lines changed: 1 addition & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -74,35 +74,6 @@ class Node extends Model
7474
'daemonSFTP', 'daemonListen',
7575
];
7676

77-
/**
78-
* @var array
79-
*/
80-
protected static $guzzle = [];
81-
82-
/**
83-
* @var array
84-
*/
85-
protected static $nodes = [];
86-
87-
/**
88-
* Returns an instance of the database object for the requested node ID.
89-
*
90-
* @param int $id
91-
* @return \Illuminate\Database\Eloquent\Model
92-
*/
93-
public static function getByID($id)
94-
{
95-
96-
// The Node is already cached.
97-
if (array_key_exists($id, self::$nodes)) {
98-
return self::$nodes[$id];
99-
}
100-
101-
self::$nodes[$id] = self::where('id', $id)->first();
102-
103-
return self::$nodes[$id];
104-
}
105-
10677
/**
10778
* Return an instance of the Guzzle client for this specific node.
10879
*
@@ -119,32 +90,6 @@ public function guzzleClient($headers = [])
11990
]);
12091
}
12192

122-
/**
123-
* Returns a Guzzle Client for the node in question.
124-
*
125-
* @param int $node
126-
* @return \GuzzleHttp\Client
127-
* @deprecated
128-
*/
129-
public static function guzzleRequest($node)
130-
{
131-
132-
// The Guzzle Client is cached already.
133-
if (array_key_exists($node, self::$guzzle)) {
134-
return self::$guzzle[$node];
135-
}
136-
137-
$nodeData = self::getByID($node);
138-
139-
self::$guzzle[$node] = new Client([
140-
'base_uri' => sprintf('%s://%s:%s/', $nodeData->scheme, $nodeData->fqdn, $nodeData->daemonListen),
141-
'timeout' => 5.0,
142-
'connect_timeout' => 3.0,
143-
]);
144-
145-
return self::$guzzle[$node];
146-
}
147-
14893
/**
14994
* Returns the configuration in JSON format.
15095
*
@@ -194,12 +139,7 @@ public function getConfigurationAsJson($pretty = false)
194139
'keys' => [$this->daemonSecret],
195140
];
196141

197-
$json_options = JSON_UNESCAPED_SLASHES;
198-
if ($pretty) {
199-
$json_options |= JSON_PRETTY_PRINT;
200-
}
201-
202-
return json_encode($config, $json_options);
142+
return json_encode($config, ($pretty) ? JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT : JSON_UNESCAPED_SLASHES);
203143
}
204144

205145
/**

app/Repositories/Daemon/CommandRepository.php

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,10 @@
3232
class CommandRepository
3333
{
3434
protected $server;
35-
protected $node;
36-
protected $client;
3735

3836
public function __construct($server)
3937
{
4038
$this->server = ($server instanceof Models\Server) ? $server : Models\Server::findOrFail($server);
41-
$this->node = Models\Node::getByID($this->server->node);
42-
$this->client = Models\Node::guzzleRequest($this->server->node);
4339
}
4440

4541
/**
@@ -56,15 +52,10 @@ public function send($command)
5652
// Additionally not all calls to this will be from a logged in user.
5753
// (e.g. task queue or API)
5854
try {
59-
$response = $this->client->request('POST', '/server/command', [
60-
'headers' => [
61-
'X-Access-Token' => $this->server->daemonSecret,
62-
'X-Access-Server' => $this->server->uuid,
63-
],
64-
'json' => [
65-
'command' => $command,
66-
],
67-
]);
55+
$response = $this->server->node->guzzleClient([
56+
'X-Access-Token' => $this->server->daemonSecret,
57+
'X-Access-Server' => $this->server->uuid,
58+
])->request('POST', '/server/command', ['json' => ['command' => $command]]);
6859

6960
if ($response->getStatusCode() < 200 || $response->getStatusCode() >= 300) {
7061
throw new DisplayException('Command sending responded with a non-200 error code.');

app/Repositories/Daemon/PowerRepository.php

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,10 @@
3131
class PowerRepository
3232
{
3333
protected $server;
34-
protected $node;
35-
protected $client;
3634

3735
public function __construct($server)
3836
{
3937
$this->server = ($server instanceof Models\Server) ? $server : Models\Server::findOrFail($server);
40-
$this->node = Models\Node::getByID($this->server->node);
41-
$this->client = Models\Node::guzzleRequest($this->server->node);
4238
}
4339

4440
public function do($action)
@@ -48,15 +44,10 @@ public function do($action)
4844
// Additionally not all calls to this will be from a logged in user.
4945
// (e.g. task queue or API)
5046
try {
51-
$response = $this->client->request('PUT', '/server/power', [
52-
'headers' => [
53-
'X-Access-Token' => $this->server->daemonSecret,
54-
'X-Access-Server' => $this->server->uuid,
55-
],
56-
'json' => [
57-
'action' => $action,
58-
],
59-
]);
47+
$response = $this->server->node->guzzleClient([
48+
'X-Access-Token' => $this->server->daemonSecret,
49+
'X-Access-Server' => $this->server->uuid,
50+
])->request('PUT', '/server/power', ['json' => ['action' => $action]]);
6051

6152
if ($response->getStatusCode() < 200 || $response->getStatusCode() >= 300) {
6253
throw new DisplayException('Power status responded with a non-200 error code.');

0 commit comments

Comments
 (0)