Created
March 18, 2020 13:41
-
-
Save tonysm/a2fab21857b92d5ce5d757976dbc0bbb to your computer and use it in GitHub Desktop.
AWS IoT, pipeline actions, and builder pattern
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class AwsIotProvider implements IotProvider | |
{ | |
public function createDevice(DeviceId $deviceId, Certificate $rootCertificate): void | |
{ | |
(new Pipeline(app())) | |
->send( | |
Aws\Tasks\CreateIotDeviceTask::forDeviceId($deviceId) | |
->withPolicyName(config('iot.providers.aws.devices.policy_name')) | |
->withDeviceType(config('iot.providers.aws.devices.device_type')) | |
->build() | |
) | |
->through([ | |
Aws\Actions\CreateDeviceThing::class, | |
Aws\Actions\CreateSignedDeviceCertificate::class, | |
]) | |
->thenReturn(); | |
} | |
} | |
final class CreateIotDeviceTask | |
{ | |
private DeviceId $deviceId; | |
private string $deviceType; | |
private string $policyName; | |
public static function forDeviceId(DeviceId $deviceId): CreateIotDeviceTaskBuilder | |
{ | |
return (new CreateIotDeviceTaskBuilder()) | |
->withDeviceId($deviceId); | |
} | |
// ... | |
} | |
final class CreateIotDeviceTaskBuilder | |
{ | |
public DeviceId $deviceId; | |
public string $deviceType; | |
public string $policyName; | |
public function withDeviceId(DeviceId $deviceId): self | |
{ | |
$this->deviceId = $deviceId; | |
return $this; | |
} | |
// ... | |
public function build(): CreateIotDeviceTask | |
{ | |
return new CreateIotDeviceTask($this->deviceId, $this->deviceType, $this->policyName); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment