@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Validate resource attributes for preallocated hosts before executing leases

Summary: This prevents issues when the user hasn't provided the appropriate attributes for a preallocated host.

Test Plan: Attempted to lease against a resource with omitted attributes, got an exception thrown before any SSH commands occurred.

Reviewers: epriestley, #blessed_reviewers

Reviewed By: epriestley

CC: Korvin, epriestley, aran

Maniphest Tasks: T1049

Differential Revision: https://secure.phabricator.com/D7695

+22 -3
+18 -3
src/applications/drydock/blueprint/DrydockPreallocatedHostBlueprintImplementation.php
··· 37 37 DrydockResource $resource, 38 38 DrydockLease $lease) { 39 39 40 + // Because preallocated resources are manually created, we should verify 41 + // we have all the information we need. 42 + PhutilTypeSpec::checkMap( 43 + $resource->getAttributesForTypeSpec( 44 + array('platform', 'host', 'port', 'user', 'path')), 45 + array( 46 + 'platform' => 'string', 47 + 'host' => 'string', 48 + 'port' => 'string', // Value is a string from the command line 49 + 'user' => 'string', 50 + 'path' => 'string', 51 + )); 52 + $v_platform = $resource->getAttribute('platform'); 53 + $v_path = $resource->getAttribute('path'); 54 + 40 55 // Similar to DrydockLocalHostBlueprint, we create a folder 41 56 // on the remote host that the lease can use. 42 57 ··· 46 61 // the platform we're currently running on, not the platform we are 47 62 // remoting to. 48 63 $separator = '/'; 49 - if ($lease->getAttribute('platform') === 'windows') { 64 + if ($v_platform === 'windows') { 50 65 $separator = '\\'; 51 66 } 52 67 53 68 // Clean up the directory path a little. 54 - $base_path = rtrim($resource->getAttribute('path'), '/'); 69 + $base_path = rtrim($v_path, '/'); 55 70 $base_path = rtrim($base_path, '\\'); 56 71 $full_path = $base_path.$separator.$lease_id; 57 72 58 73 $cmd = $lease->getInterface('command'); 59 74 60 - if ($lease->getAttribute('platform') !== 'windows') { 75 + if ($v_platform !== 'windows') { 61 76 $cmd->execx('mkdir %s', $full_path); 62 77 } else { 63 78 // Windows is terrible. The mkdir command doesn't even support putting
+4
src/applications/drydock/storage/DrydockResource.php
··· 35 35 return idx($this->attributes, $key, $default); 36 36 } 37 37 38 + public function getAttributesForTypeSpec(array $attribute_names) { 39 + return array_select_keys($this->attributes, $attribute_names); 40 + } 41 + 38 42 public function setAttribute($key, $value) { 39 43 $this->attributes[$key] = $value; 40 44 return $this;