New models for node and location admin pages.

This commit is contained in:
Dane Everitt 2017-02-03 16:50:28 -05:00
parent 96d3aa767f
commit 09d23deed6
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
10 changed files with 152 additions and 78 deletions

View file

@ -44,7 +44,7 @@ class LocationRepository
public function create(array $data)
{
$validator = Validator::make($data, [
'short' => 'required|regex:/^[a-z0-9_.-]{1,10}$/i|unique:locations,short',
'short' => 'required|regex:/^[\w.-]{1,20}$/i|unique:locations,short',
'long' => 'required|string|min:1|max:255',
]);
@ -73,9 +73,11 @@ class LocationRepository
*/
public function edit($id, array $data)
{
$location = Models\Location::findOrFail($id);
$validator = Validator::make($data, [
'short' => 'regex:/^[a-z0-9_.-]{1,10}$/i',
'long' => 'string|min:1|max:255',
'short' => 'required|regex:/^[\w.-]{1,20}$/i|unique:locations,short,' . $location->id,
'long' => 'required|string|min:1|max:255',
]);
// Run validator, throw catchable and displayable exception if it fails.
@ -84,15 +86,7 @@ class LocationRepository
throw new DisplayValidationException($validator->errors());
}
$location = Models\Location::findOrFail($id);
if (isset($data['short'])) {
$location->short = $data['short'];
}
if (isset($data['long'])) {
$location->long = $data['long'];
}
$location->fill($data);
return $location->save();
}

View file

@ -65,7 +65,7 @@ class NodeRepository
// Verify the FQDN if using SSL
if (filter_var($data['fqdn'], FILTER_VALIDATE_IP) && $data['scheme'] === 'https') {
throw new DisplayException('A fully qualified domain name is required to use secure comunication on this node.');
throw new DisplayException('A fully qualified domain name is required to use a secure comunication method on this node.');
}
// Verify FQDN is resolvable, or if not using SSL that the IP is valid.
@ -86,7 +86,7 @@ class NodeRepository
$node->fill($data);
$node->save();
return $node->id;
return $node;
}
public function update($id, array $data)
@ -152,18 +152,12 @@ class NodeRepository
$oldDaemonKey = $node->daemonSecret;
$node->update($data);
try {
$client = Models\Node::guzzleRequest($node->id);
$client->request('PATCH', '/config', [
'headers' => [
'X-Access-Token' => $oldDaemonKey,
],
$node->guzzleClient(['X-Access-Token' => $oldDaemonKey])->request('PATCH', '/config', [
'json' => [
'web' => [
'listen' => $node->daemonListen,
'ssl' => [
'enabled' => ($node->scheme === 'https'),
'certificate' => '/etc/letsencrypt/live/' . $node->fqdn . '/fullchain.pem',
'key' => '/etc/letsencrypt/live/' . $node->fqdn . '/privkey.pem',
],
],
'sftp' => [