@@ -32,7 +32,7 @@ public function create(array $data)
3232 'disk_overallocate ' => 'required|numeric|min:-1 ' ,
3333 'daemonBase ' => 'required|regex:/^([\/][\d\w.\-\/]+)$/ ' ,
3434 'daemonSFTP ' => 'required|numeric|between:1,65535 ' ,
35- 'daemonListen ' => 'required|numeric|between:1,65535 '
35+ 'daemonListen ' => 'required|numeric|between:1,65535 ' ,
3636 ]);
3737
3838 // Run validator, throw catchable and displayable exception if it fails.
@@ -42,6 +42,9 @@ public function create(array $data)
4242 }
4343
4444 // Verify the FQDN
45+ if (filter_var ($ data ['fqdn ' ], FILTER_VALIDATE_IP )) {
46+ throw new DisplayException ('The FQDN provided was an IP address. You must use a FQDN. ' );
47+ }
4548 if (!filter_var (gethostbyname ($ data ['fqdn ' ]), FILTER_VALIDATE_IP )) {
4649 throw new DisplayException ('The FQDN provided does not resolve to a valid IP address. ' );
4750 }
@@ -63,4 +66,61 @@ public function create(array $data)
6366
6467 }
6568
69+ public function update ($ id , array $ data )
70+ {
71+ // Validate Fields
72+ $ validator = $ validator = Validator::make ($ data , [
73+ 'name ' => 'regex:/^([\w .-]{1,100})$/ ' ,
74+ 'location ' => 'numeric|min:1|exists:locations,id ' ,
75+ 'public ' => 'numeric|between:0,1 ' ,
76+ 'fqdn ' => 'string|unique:nodes,fqdn, ' . $ id ,
77+ 'scheme ' => 'regex:/^(http(s)?)$/ ' ,
78+ 'memory ' => 'numeric|min:1 ' ,
79+ 'memory_overallocate ' => 'numeric|min:-1 ' ,
80+ 'disk ' => 'numeric|min:1 ' ,
81+ 'disk_overallocate ' => 'numeric|min:-1 ' ,
82+ 'daemonBase ' => 'regex:/^([\/][\d\w.\-\/]+)$/ ' ,
83+ 'daemonSFTP ' => 'numeric|between:1,65535 ' ,
84+ 'daemonListen ' => 'numeric|between:1,65535 ' ,
85+ 'reset_secret ' => 'sometimes|accepted ' ,
86+ ]);
87+
88+ // Run validator, throw catchable and displayable exception if it fails.
89+ // Exception includes a JSON result of failed validation rules.
90+ if ($ validator ->fails ()) {
91+ throw new DisplayValidationException ($ validator ->errors ());
92+ }
93+
94+ // Verify the FQDN
95+ if (isset ($ data ['fqdn ' ])) {
96+ if (filter_var ($ data ['fqdn ' ], FILTER_VALIDATE_IP )) {
97+ throw new DisplayException ('The FQDN provided was an IP address. You must use a FQDN. ' );
98+ }
99+ if (!filter_var (gethostbyname ($ data ['fqdn ' ]), FILTER_VALIDATE_IP )) {
100+ throw new DisplayException ('The FQDN provided does not resolve to a valid IP address. ' );
101+ }
102+ }
103+
104+ // Should we be nulling the overallocations?
105+ if (isset ($ data ['memory_overallocate ' ])) {
106+ $ data ['memory_overallocate ' ] = ($ data ['memory_overallocate ' ] < 0 ) ? null : $ data ['memory_overallocate ' ];
107+ }
108+
109+ if (isset ($ data ['disk_overallocate ' ])) {
110+ $ data ['disk_overallocate ' ] = ($ data ['disk_overallocate ' ] < 0 ) ? null : $ data ['disk_overallocate ' ];
111+ }
112+
113+ // Set the Secret
114+ if (isset ($ data ['reset_secret ' ])) {
115+ $ uuid = new UuidService ;
116+ $ data ['daemonSecret ' ] = (string ) $ uuid ->generate ('nodes ' , 'daemonSecret ' );
117+ unset($ data ['reset_secret ' ]);
118+ }
119+
120+ // Store the Data
121+ $ node = Models \Node::findOrFail ($ id );
122+ return $ node ->update ($ data );
123+
124+ }
125+
66126}
0 commit comments