GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Pull Request — develop (#286)
by Dane
02:52
created

Node::guzzleClient()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 1
1
<?php
2
/**
3
 * Pterodactyl - Panel
4
 * Copyright (c) 2015 - 2017 Dane Everitt <[email protected]>.
5
 *
6
 * Permission is hereby granted, free of charge, to any person obtaining a copy
7
 * of this software and associated documentation files (the "Software"), to deal
8
 * in the Software without restriction, including without limitation the rights
9
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
 * copies of the Software, and to permit persons to whom the Software is
11
 * furnished to do so, subject to the following conditions:
12
 *
13
 * The above copyright notice and this permission notice shall be included in all
14
 * copies or substantial portions of the Software.
15
 *
16
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
 * SOFTWARE.
23
 */
24
25
namespace Pterodactyl\Models;
26
27
use GuzzleHttp\Client;
28
use Illuminate\Database\Eloquent\Model;
29
use Illuminate\Notifications\Notifiable;
30
31
class Node extends Model
32
{
33
    use Notifiable;
34
35
    /**
36
     * The table associated with the model.
37
     *
38
     * @var string
39
     */
40
    protected $table = 'nodes';
41
42
    /**
43
     * The attributes excluded from the model's JSON form.
44
     *
45
     * @var array
46
     */
47
    protected $hidden = ['daemonSecret'];
48
49
     /**
50
      * Cast values to correct type.
51
      *
52
      * @var array
53
      */
54
     protected $casts = [
55
         'public' => 'integer',
56
         'location_id' => 'integer',
57
         'memory' => 'integer',
58
         'disk' => 'integer',
59
         'daemonListen' => 'integer',
60
         'daemonSFTP' => 'integer',
61
     ];
62
63
    /**
64
     * Fields that are mass assignable.
65
     *
66
     * @var array
67
     */
68
    protected $fillable = [
69
        'public', 'name', 'location_id',
70
        'fqdn', 'scheme', 'memory',
71
        'memory_overallocate', 'disk',
72
        'disk_overallocate', 'upload_size',
73
        'daemonSecret', 'daemonBase',
74
        'daemonSFTP', 'daemonListen',
75
    ];
76
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
106
    /**
107
     * Return an instance of the Guzzle client for this specific node.
108
     *
109
     * @param array $headers
110
     * @return \GuzzleHttp\Client
111
     */
112
    public function guzzleClient($headers = [])
113
    {
114
        return new Client([
115
            'base_uri' => sprintf('%s://%s:%s/', $this->scheme, $this->fqdn, $this->daemonListen),
0 ignored issues
show
Documentation introduced by
The property scheme does not exist on object<Pterodactyl\Models\Node>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
Documentation introduced by
The property fqdn does not exist on object<Pterodactyl\Models\Node>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
Documentation introduced by
The property daemonListen does not exist on object<Pterodactyl\Models\Node>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
116
            'timeout' => env('GUZZLE_TIMEOUT', 5.0),
117
            'connect_timeout' => env('GUZZLE_CONNECT_TIMEOUT', 3.0),
118
            'headers' => $headers,
119
        ]);
120
    }
121
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
148
    /**
149
     * Returns the configuration in JSON format.
150
     *
151
     * @param bool $pretty Wether to pretty print the JSON or not
152
     * @return string The configration in JSON format
153
     */
154
    public function getConfigurationAsJson($pretty = false)
155
    {
156
        $config = [
157
            'web' => [
158
                'host' => '0.0.0.0',
159
                'listen' => $this->daemonListen,
0 ignored issues
show
Documentation introduced by
The property daemonListen does not exist on object<Pterodactyl\Models\Node>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
160
                'ssl' => [
161
                    'enabled' => $this->scheme === 'https',
0 ignored issues
show
Documentation introduced by
The property scheme does not exist on object<Pterodactyl\Models\Node>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
162
                    'certificate' => '/etc/letsencrypt/live/' . $this->fqdn . '/fullchain.pem',
0 ignored issues
show
Documentation introduced by
The property fqdn does not exist on object<Pterodactyl\Models\Node>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
163
                    'key' => '/etc/letsencrypt/live/' . $this->fqdn . '/privkey.pem',
0 ignored issues
show
Documentation introduced by
The property fqdn does not exist on object<Pterodactyl\Models\Node>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
164
                ],
165
            ],
166
            'docker' => [
167
                'socket' => '/var/run/docker.sock',
168
                'autoupdate_images' => true,
169
            ],
170
            'sftp' => [
171
                'path' => $this->daemonBase,
0 ignored issues
show
Documentation introduced by
The property daemonBase does not exist on object<Pterodactyl\Models\Node>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
172
                'port' => $this->daemonSFTP,
0 ignored issues
show
Documentation introduced by
The property daemonSFTP does not exist on object<Pterodactyl\Models\Node>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
173
                'container' => 'ptdl-sftp',
174
            ],
175
            'query' => [
176
                'kill_on_fail' => true,
177
                'fail_limit' => 5,
178
            ],
179
            'logger' => [
180
                'path' => 'logs/',
181
                'src' => false,
182
                'level' => 'info',
183
                'period' => '1d',
184
                'count' => 3,
185
            ],
186
            'remote' => [
187
                'base' => config('app.url'),
188
                'download' => route('remote.download'),
189
                'installed' => route('remote.install'),
190
            ],
191
            'uploads' => [
192
                'size_limit' => $this->upload_size,
0 ignored issues
show
Documentation introduced by
The property upload_size does not exist on object<Pterodactyl\Models\Node>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
193
            ],
194
            'keys' => [$this->daemonSecret],
0 ignored issues
show
Documentation introduced by
The property daemonSecret does not exist on object<Pterodactyl\Models\Node>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
195
        ];
196
197
        $json_options = JSON_UNESCAPED_SLASHES;
198
        if ($pretty) {
199
            $json_options |= JSON_PRETTY_PRINT;
200
        }
201
202
        return json_encode($config, $json_options);
203
    }
204
205
    /**
206
     * Gets the location associated with a node.
207
     *
208
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
209
     */
210
    public function location()
211
    {
212
        return $this->belongsTo(Location::class);
213
    }
214
215
    /**
216
     * Gets the servers associated with a node.
217
     *
218
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
219
     */
220
    public function servers()
221
    {
222
        return $this->hasMany(Server::class);
223
    }
224
225
    /**
226
     * Gets the allocations associated with a node.
227
     *
228
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
229
     */
230
    public function allocations()
231
    {
232
        return $this->hasMany(Allocation::class);
233
    }
234
}
235