| @@ 431-471 (lines=41) @@ | ||
| 428 | * @param array $data |
|
| 429 | * @return bool |
|
| 430 | */ |
|
| 431 | public function updateContainer($id, array $data) |
|
| 432 | { |
|
| 433 | $validator = Validator::make($data, [ |
|
| 434 | 'docker_image' => 'required|string', |
|
| 435 | ]); |
|
| 436 | ||
| 437 | // Run validator, throw catchable and displayable exception if it fails. |
|
| 438 | // Exception includes a JSON result of failed validation rules. |
|
| 439 | if ($validator->fails()) { |
|
| 440 | throw new DisplayValidationException($validator->errors()); |
|
| 441 | } |
|
| 442 | ||
| 443 | DB::beginTransaction(); |
|
| 444 | try { |
|
| 445 | $server = Models\Server::findOrFail($id); |
|
| 446 | ||
| 447 | $server->image = $data['docker_image']; |
|
| 448 | $server->save(); |
|
| 449 | ||
| 450 | $server->node->guzzleClient([ |
|
| 451 | 'X-Access-Server' => $server->uuid, |
|
| 452 | 'X-Access-Token' => $server->node->daemonSecret, |
|
| 453 | ])->request('PATCH', '/server', [ |
|
| 454 | 'json' => [ |
|
| 455 | 'build' => [ |
|
| 456 | 'image' => $server->image, |
|
| 457 | ], |
|
| 458 | ], |
|
| 459 | ]); |
|
| 460 | ||
| 461 | DB::commit(); |
|
| 462 | ||
| 463 | return true; |
|
| 464 | } catch (TransferException $ex) { |
|
| 465 | DB::rollBack(); |
|
| 466 | throw new DisplayException('A TransferException occured while attempting to update the container image. Is the daemon online? This error has been logged.', $ex); |
|
| 467 | } catch (\Exception $ex) { |
|
| 468 | DB::rollBack(); |
|
| 469 | throw $ex; |
|
| 470 | } |
|
| 471 | } |
|
| 472 | ||
| 473 | /** |
|
| 474 | * [changeBuild description]. |
|
| @@ 869-904 (lines=36) @@ | ||
| 866 | } |
|
| 867 | } |
|
| 868 | ||
| 869 | public function updateSFTPPassword($id, $password) |
|
| 870 | { |
|
| 871 | $server = Models\Server::with('node')->findOrFail($id); |
|
| 872 | ||
| 873 | $validator = Validator::make(['password' => $password], [ |
|
| 874 | 'password' => 'required|regex:/^((?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,})$/', |
|
| 875 | ]); |
|
| 876 | ||
| 877 | if ($validator->fails()) { |
|
| 878 | throw new DisplayValidationException(json_encode($validator->errors())); |
|
| 879 | } |
|
| 880 | ||
| 881 | DB::beginTransaction(); |
|
| 882 | $server->sftp_password = Crypt::encrypt($password); |
|
| 883 | ||
| 884 | try { |
|
| 885 | $server->save(); |
|
| 886 | ||
| 887 | $server->node->guzzleClient([ |
|
| 888 | 'X-Access-Token' => $server->node->daemonSecret, |
|
| 889 | 'X-Access-Server' => $server->uuid, |
|
| 890 | ])->request('POST', '/server/password', [ |
|
| 891 | 'json' => ['password' => $password], |
|
| 892 | ]); |
|
| 893 | ||
| 894 | DB::commit(); |
|
| 895 | ||
| 896 | return true; |
|
| 897 | } catch (TransferException $ex) { |
|
| 898 | DB::rollBack(); |
|
| 899 | throw new DisplayException('There was an error while attmping to contact the remote service to change the password.', $ex); |
|
| 900 | } catch (\Exception $ex) { |
|
| 901 | DB::rollBack(); |
|
| 902 | throw $ex; |
|
| 903 | } |
|
| 904 | } |
|
| 905 | } |
|
| 906 | ||