From 9f498c8de3d3bb292075e109e7b108a063afcfe9 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 26 Nov 2026 13:09:35 +0000 Subject: [PATCH 1/4] Add environment:primary-domain The API now sets and clears an environment's primary domain (PUT and DELETE /environments/{environment}/primary-domain). The new command takes --domain (ID or name) or --clear, and interactively offers the environment's root domains plus an option to clear. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01T1Sq4WQ3L3cL3CyKM4B8P4 --- README.md | 3 + app/Client/README.md | 2 + ...ateEnvironmentPrimaryDomainRequestData.php | 20 ++ .../ClearPrimaryDomainRequest.php | 22 ++ .../UpdatePrimaryDomainRequest.php | 32 +++ app/Client/Resources/EnvironmentsResource.php | 13 ++ app/Commands/EnvironmentPrimaryDomain.php | 157 +++++++++++++ skills/deploying-to-cloud/SKILL.md | 1 + .../Feature/EnvironmentPrimaryDomainTest.php | 206 ++++++++++++++++++ 9 files changed, 456 insertions(+) create mode 100644 app/Client/Requests/UpdateEnvironmentPrimaryDomainRequestData.php create mode 100644 app/Client/Resources/Environments/ClearPrimaryDomainRequest.php create mode 100644 app/Client/Resources/Environments/UpdatePrimaryDomainRequest.php create mode 100644 app/Commands/EnvironmentPrimaryDomain.php create mode 100644 tests/Feature/EnvironmentPrimaryDomainTest.php diff --git a/README.md b/README.md index 7fa5fafa..34ba8091 100644 --- a/README.md +++ b/README.md @@ -175,11 +175,14 @@ Many commands accept an optional resource ID/name and support `--json` for machi | `cloud environment:metrics` | View environment compute and HTTP metrics | | `cloud environment:purge-edge-cache` | Purge the edge cache (everything, or a path, prefix, or tag) | | `cloud environment:vanity-domain` | Change the environment's Laravel Cloud domain | +| `cloud environment:primary-domain` | Set or clear the environment's primary domain | `environment:purge-edge-cache` purges everything cached at the edge for the environment unless you pass one of `--path`, `--prefix`, or `--tag`. Paths and prefixes start with `/`; purging by tag needs a dedicated edge network. Cloud queues the purge, and repeating the same purge right away has no effect. `environment:vanity-domain` takes only the first part of the domain: `--name=my-app` gives `my-app.laravel.cloud`. The new domain takes effect on the next deploy, and the domain can be changed only once every 30 minutes, so the command asks for confirmation (or `--force`). Afterward it offers to deploy the environment; pass `--deploy` to do that without asking. +`environment:primary-domain` makes one of the environment's custom domains its main address. Pass `--domain` with a domain ID or name, or `--clear` to remove the primary domain; clearing leaves the domain attached. Cloud accepts only a verified root domain that doesn't redirect to another domain. + ### Secrets Secrets are organization-wide encrypted values that can be attached to environments. Values are encrypted locally with the organization's public key before they are sent, so plaintext never leaves your machine. diff --git a/app/Client/README.md b/app/Client/README.md index 919d5670..81016999 100644 --- a/app/Client/README.md +++ b/app/Client/README.md @@ -45,6 +45,8 @@ $data = $response->json(); - `DeleteEnvironmentVariablesRequest` - Delete environment variables by key - `StartEnvironmentRequest` - Start an environment - `StopEnvironmentRequest` - Stop an environment +- `UpdatePrimaryDomainRequest` - Set an environment's primary domain +- `ClearPrimaryDomainRequest` - Clear an environment's primary domain #### Deployments - `ListDeploymentsRequest` - List deployments for an environment diff --git a/app/Client/Requests/UpdateEnvironmentPrimaryDomainRequestData.php b/app/Client/Requests/UpdateEnvironmentPrimaryDomainRequestData.php new file mode 100644 index 00000000..bf3c7d55 --- /dev/null +++ b/app/Client/Requests/UpdateEnvironmentPrimaryDomainRequestData.php @@ -0,0 +1,20 @@ + $this->domainId, + ]; + } +} diff --git a/app/Client/Resources/Environments/ClearPrimaryDomainRequest.php b/app/Client/Resources/Environments/ClearPrimaryDomainRequest.php new file mode 100644 index 00000000..95a5a469 --- /dev/null +++ b/app/Client/Resources/Environments/ClearPrimaryDomainRequest.php @@ -0,0 +1,22 @@ +environmentId}/primary-domain"; + } +} diff --git a/app/Client/Resources/Environments/UpdatePrimaryDomainRequest.php b/app/Client/Resources/Environments/UpdatePrimaryDomainRequest.php new file mode 100644 index 00000000..63a57c39 --- /dev/null +++ b/app/Client/Resources/Environments/UpdatePrimaryDomainRequest.php @@ -0,0 +1,32 @@ +data->environmentId}/primary-domain"; + } + + protected function defaultBody(): array + { + return $this->data->toRequestData(); + } +} diff --git a/app/Client/Resources/EnvironmentsResource.php b/app/Client/Resources/EnvironmentsResource.php index 731ba0c5..21d43f60 100644 --- a/app/Client/Resources/EnvironmentsResource.php +++ b/app/Client/Resources/EnvironmentsResource.php @@ -9,10 +9,12 @@ use App\Client\Requests\PurgeEdgeCacheRequestData; use App\Client\Requests\StartEnvironmentRequestData; use App\Client\Requests\StopEnvironmentRequestData; +use App\Client\Requests\UpdateEnvironmentPrimaryDomainRequestData; use App\Client\Requests\UpdateEnvironmentRequestData; use App\Client\Requests\UpdateVanityDomainRequestData; use App\Client\Resources\Environments\AddEnvironmentVariablesRequest; use App\Client\Resources\Environments\AttachEnvironmentSecretsRequest; +use App\Client\Resources\Environments\ClearPrimaryDomainRequest; use App\Client\Resources\Environments\CreateEnvironmentRequest; use App\Client\Resources\Environments\DeleteEnvironmentRequest; use App\Client\Resources\Environments\DeleteEnvironmentVariablesRequest; @@ -25,6 +27,7 @@ use App\Client\Resources\Environments\StartEnvironmentRequest; use App\Client\Resources\Environments\StopEnvironmentRequest; use App\Client\Resources\Environments\UpdateEnvironmentRequest; +use App\Client\Resources\Environments\UpdatePrimaryDomainRequest; use App\Client\Resources\Environments\UpdateVanityDomainRequest; use App\Dto\Environment; use App\Dto\EnvironmentLogPage; @@ -145,6 +148,16 @@ public function updateVanityDomain(UpdateVanityDomainRequestData $data): Environ return $request->createDtoFromResponse($response); } + public function updatePrimaryDomain(UpdateEnvironmentPrimaryDomainRequestData $data): void + { + $this->send(new UpdatePrimaryDomainRequest($data)); + } + + public function clearPrimaryDomain(string $environmentId): void + { + $this->send(new ClearPrimaryDomainRequest($environmentId)); + } + public function deleteVariables(DeleteEnvironmentVariablesRequestData $data): void { $this->send(new DeleteEnvironmentVariablesRequest($data)); diff --git a/app/Commands/EnvironmentPrimaryDomain.php b/app/Commands/EnvironmentPrimaryDomain.php new file mode 100644 index 00000000..2e8ff561 --- /dev/null +++ b/app/Commands/EnvironmentPrimaryDomain.php @@ -0,0 +1,157 @@ +ensureClient(); + + intro('Setting Primary Domain'); + + if ($this->option('clear') && $this->option('domain')) { + $this->failAndExit('Pass either --domain or --clear, not both.'); + } + + $environment = $this->resolvers()->environment()->from($this->argument('environment')); + + if ($this->option('clear')) { + return $this->clear($environment); + } + + $domains = $this->fetchList( + fn () => $this->client->domains()->list($environment->id), + 'Fetching domains...', + ); + + $domain = $this->option('domain') + ? $this->findDomain($environment, $domains, $this->option('domain')) + : $this->pickDomain($environment, $domains); + + if (! $domain) { + return $this->clear($environment); + } + + if ($domain->id === $environment->primaryDomainId) { + warning("{$domain->name} is already the primary domain of {$environment->name}."); + + $this->outputJsonIfWanted($environment); + + return self::SUCCESS; + } + + $updated = spin( + function () use ($environment, $domain) { + $this->client->environments()->updatePrimaryDomain( + new UpdateEnvironmentPrimaryDomainRequestData( + environmentId: $environment->id, + domainId: $domain->id, + ), + ); + + return $this->client->environments()->get($environment->id); + }, + 'Setting primary domain...', + ); + + $this->outputJsonIfWanted($updated); + + success("{$domain->name} is now the primary domain of {$updated->name}."); + + return self::SUCCESS; + } + + protected function clear(Environment $environment): int + { + if (! $environment->primaryDomainId) { + warning("{$environment->name} has no primary domain."); + + $this->outputJsonIfWanted($environment); + + return self::SUCCESS; + } + + $updated = spin( + function () use ($environment) { + $this->client->environments()->clearPrimaryDomain($environment->id); + + return $this->client->environments()->get($environment->id); + }, + 'Clearing primary domain...', + ); + + $this->outputJsonIfWanted($updated); + + success("Primary domain cleared for {$updated->name}."); + + return self::SUCCESS; + } + + /** + * @param Collection $domains + */ + protected function findDomain(Environment $environment, Collection $domains, string $idOrName): Domain + { + $domain = $domains->firstWhere('id', $idOrName) ?? $domains->firstWhere('name', $idOrName); + + if (! $domain) { + $this->failAndExit("Domain {$idOrName} is not attached to {$environment->name}. Run `cloud domain:list {$environment->id} --json` to see its domains."); + } + + return $domain; + } + + /** + * Only a root domain can be primary, so the others aren't offered. Returns null to clear. + * + * @param Collection $domains + */ + protected function pickDomain(Environment $environment, Collection $domains): ?Domain + { + $this->ensureInteractive('Provide a domain with --domain, or pass --clear.'); + + $options = $domains + ->filter(fn (Domain $domain) => $domain->type === 'root') + ->mapWithKeys(fn (Domain $domain) => [$domain->id => $domain->name]); + + if ($environment->primaryDomainId) { + $options->put(self::NONE, 'None (clear the primary domain)'); + } + + if ($options->isEmpty()) { + $this->failAndExit("{$environment->name} has no root domains to make primary. Add one with `cloud domain:create`."); + } + + $selected = select( + label: 'Primary domain', + options: $options->all(), + default: $environment->primaryDomainId ?? $options->keys()->first(), + ); + + return $selected === self::NONE ? null : $domains->firstWhere('id', $selected); + } +} diff --git a/skills/deploying-to-cloud/SKILL.md b/skills/deploying-to-cloud/SKILL.md index ac3577f9..d3706edb 100644 --- a/skills/deploying-to-cloud/SKILL.md +++ b/skills/deploying-to-cloud/SKILL.md @@ -118,6 +118,7 @@ Determine the task and follow the matching path: - Subdomain (`app.example.com`): pass `--www-redirect=none`. Nobody serves `www.app.example.com`, so a www variant never validates. - Apex (`example.com`): ask the user whether www redirects to the root (`www_to_root`) or the reverse (`root_to_www`). - Leave `--wildcard-enabled` off unless the user asks for wildcard subdomains. + - Primary domain: once a root domain is verified, `cloud environment:primary-domain {environment} --domain= -n` makes it the environment's main address; `--clear` removes it and leaves the domain attached. - Edge cache: `cloud environment:purge-edge-cache {environment} -n` purges everything; pass one of `--path=/blog/post`, `--prefix=/blog/`, or `--tag=` to purge less. Tags need a dedicated edge network. diff --git a/tests/Feature/EnvironmentPrimaryDomainTest.php b/tests/Feature/EnvironmentPrimaryDomainTest.php new file mode 100644 index 00000000..be9ab8c3 --- /dev/null +++ b/tests/Feature/EnvironmentPrimaryDomainTest.php @@ -0,0 +1,206 @@ +mockConfig = Mockery::mock(ConfigRepository::class); + $this->mockConfig->shouldReceive('apiTokens')->andReturn(collect(['test-api-token'])); + $this->app->instance(ConfigRepository::class, $this->mockConfig); +}); + +afterEach(function () { + MockClient::destroyGlobal(); +}); + +function primaryDomainResponse(string $id, string $name, string $type = 'root'): array +{ + return [ + 'id' => $id, + 'type' => 'domains', + 'attributes' => [ + 'name' => $name, + 'type' => $type, + 'hostname_status' => 'verified', + 'ssl_status' => 'verified', + 'origin_status' => 'verified', + 'redirect' => null, + ], + ]; +} + +/** + * @return Closure(): stdClass the primary domain requests that were sent, if any + */ +function setupPrimaryDomainMocks(?string $currentPrimaryId = null): Closure +{ + $sent = new stdClass; + $sent->primaryId = $currentPrimaryId; + + $environment = function () use ($sent) { + if (! $sent->primaryId) { + return MockResponse::make(['data' => createEnvironmentResponse()], 200); + } + + $domain = $sent->primaryId === 'domain-2' + ? primaryDomainResponse('domain-2', 'shop.example.com') + : primaryDomainResponse('domain-1', 'example.com'); + + return MockResponse::make([ + 'data' => createEnvironmentResponse([ + 'relationships' => ['primaryDomain' => ['data' => ['id' => $sent->primaryId, 'type' => 'domains']]], + ]), + 'included' => [$domain], + ], 200); + }; + + MockClient::global([ + GetOrganizationRequest::class => MockResponse::make(organizationResponse(), 200), + GetEnvironmentRequest::class => $environment, + ListDomainsRequest::class => MockResponse::make(['data' => [ + primaryDomainResponse('domain-1', 'example.com'), + primaryDomainResponse('domain-2', 'shop.example.com'), + ]], 200), + UpdatePrimaryDomainRequest::class => function (PendingRequest $request) use ($sent) { + $sent->updateUrl = $request->getUrl(); + $sent->updateMethod = $request->getMethod()->value; + $sent->body = $request->body()?->all(); + $sent->primaryId = $sent->body['domain_id']; + + return MockResponse::make(['data' => createEnvironmentResponse()], 200); + }, + ClearPrimaryDomainRequest::class => function (PendingRequest $request) use ($sent) { + $sent->clearUrl = $request->getUrl(); + $sent->clearMethod = $request->getMethod()->value; + $sent->primaryId = null; + + return MockResponse::make([], 204); + }, + ]); + + return fn () => $sent; +} + +it('sets the primary domain by name', function () { + $sent = setupPrimaryDomainMocks(); + + $this->artisan('environment:primary-domain', [ + 'environment' => 'env-1', + '--domain' => 'shop.example.com', + '--no-interaction' => true, + ])->assertSuccessful(); + + expect($sent()->updateMethod)->toBe('PUT'); + expect($sent()->updateUrl)->toEndWith('/environments/env-1/primary-domain'); + expect($sent()->body)->toBe(['domain_id' => 'domain-2']); +}); + +it('sets the primary domain by id', function () { + $sent = setupPrimaryDomainMocks(); + + $this->artisan('environment:primary-domain', [ + 'environment' => 'env-1', + '--domain' => 'domain-1', + '--no-interaction' => true, + ])->assertSuccessful(); + + expect($sent()->body)->toBe(['domain_id' => 'domain-1']); +}); + +it('outputs the environment with its new primary domain as JSON', function () { + setupPrimaryDomainMocks(); + + Artisan::call('environment:primary-domain', [ + 'environment' => 'env-1', + '--domain' => 'example.com', + '--json' => true, + ]); + + expect(json_decode(Artisan::output(), true))->toMatchArray([ + 'id' => 'env-1', + 'primaryDomainId' => 'domain-1', + ]); +}); + +it('does nothing when the domain is already primary', function () { + $sent = setupPrimaryDomainMocks('domain-1'); + + $this->artisan('environment:primary-domain', [ + 'environment' => 'env-1', + '--domain' => 'example.com', + '--no-interaction' => true, + ])->assertSuccessful(); + + expect($sent()->updateUrl ?? null)->toBeNull(); +}); + +it('fails when the domain is not attached to the environment', function () { + $sent = setupPrimaryDomainMocks(); + + $this->artisan('environment:primary-domain', [ + 'environment' => 'env-1', + '--domain' => 'other.com', + '--no-interaction' => true, + ])->assertFailed(); + + expect($sent()->updateUrl ?? null)->toBeNull(); +}); + +it('requires a domain or --clear when run non-interactively', function () { + $sent = setupPrimaryDomainMocks(); + + $this->artisan('environment:primary-domain', [ + 'environment' => 'env-1', + '--no-interaction' => true, + ])->assertFailed(); + + expect($sent()->updateUrl ?? null)->toBeNull(); +}); + +it('refuses --domain together with --clear', function () { + $sent = setupPrimaryDomainMocks('domain-1'); + + $this->artisan('environment:primary-domain', [ + 'environment' => 'env-1', + '--domain' => 'example.com', + '--clear' => true, + '--no-interaction' => true, + ])->assertFailed(); + + expect($sent()->updateUrl ?? null)->toBeNull(); + expect($sent()->clearUrl ?? null)->toBeNull(); +}); + +it('clears the primary domain', function () { + $sent = setupPrimaryDomainMocks('domain-1'); + + Artisan::call('environment:primary-domain', [ + 'environment' => 'env-1', + '--clear' => true, + '--json' => true, + ]); + + expect($sent()->clearMethod)->toBe('DELETE'); + expect($sent()->clearUrl)->toEndWith('/environments/env-1/primary-domain'); + expect(json_decode(Artisan::output(), true)['primaryDomainId'])->toBeNull(); +}); + +it('does not clear when there is no primary domain', function () { + $sent = setupPrimaryDomainMocks(); + + $this->artisan('environment:primary-domain', [ + 'environment' => 'env-1', + '--clear' => true, + '--no-interaction' => true, + ])->assertSuccessful(); + + expect($sent()->clearUrl ?? null)->toBeNull(); +}); From 81d8b78f0698ca9730aa84caf9c38a24ba6316e6 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 26 Nov 2026 15:17:17 +0000 Subject: [PATCH 2/4] Sync environments: dedicated cluster and AWS role fields The environment resource now carries `cluster_id`, `aws_role_arn` and `aws_trust_policy`, and `PATCH /environments/{environment}` accepts `aws_role_arn`. The DTO exposes all three; `environment:update` takes `--aws-role-arn` (empty removes it) and offers it interactively only for an environment on a dedicated cluster. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01T1Sq4Yc6BQ4S3vcDD6eqZ6 --- .../Requests/UpdateEnvironmentRequestData.php | 5 +++- app/Commands/EnvironmentUpdate.php | 17 +++++++++++ app/Dto/Environment.php | 8 +++++ tests/Feature/EnvironmentUpdateTest.php | 30 +++++++++++++++++++ 4 files changed, 59 insertions(+), 1 deletion(-) diff --git a/app/Client/Requests/UpdateEnvironmentRequestData.php b/app/Client/Requests/UpdateEnvironmentRequestData.php index e139dc32..445cfcf6 100644 --- a/app/Client/Requests/UpdateEnvironmentRequestData.php +++ b/app/Client/Requests/UpdateEnvironmentRequestData.php @@ -29,6 +29,8 @@ public function __construct( public readonly ?string $websocketApplicationId = null, /** @var string|null '' detaches it */ public readonly ?string $modelGatewayKeyId = null, + /** @var string|null '' removes it */ + public readonly ?string $awsRoleArn = null, public readonly ?bool $usesOctane = null, public readonly ?int $sleepTimeout = null, /** @var int|string|null '' disables it */ @@ -79,6 +81,7 @@ public function toRequestData(): array 'cache_id' => $this->cacheId, 'websocket_application_id' => $this->websocketApplicationId, 'model_gateway_key_id' => $this->modelGatewayKeyId, + 'aws_role_arn' => $this->awsRoleArn, 'uses_octane' => $this->usesOctane, 'sleep_timeout' => $this->sleepTimeout, 'hibernation_wake_up_interval' => $this->hibernationWakeUpInterval, @@ -99,7 +102,7 @@ public function toRequestData(): array ]); // filter() drops nulls, so the CLI's '' stands in for the explicit null the API needs to clear these. - foreach (['start_command', 'hibernation_wake_up_interval', 'nightwatch_token'] as $key) { + foreach (['start_command', 'hibernation_wake_up_interval', 'nightwatch_token', 'aws_role_arn'] as $key) { if (($data[$key] ?? null) === '') { $data[$key] = null; } diff --git a/app/Commands/EnvironmentUpdate.php b/app/Commands/EnvironmentUpdate.php index 8f5d4aff..f8452769 100644 --- a/app/Commands/EnvironmentUpdate.php +++ b/app/Commands/EnvironmentUpdate.php @@ -65,6 +65,7 @@ class EnvironmentUpdate extends BaseCommand {--cache-id= : Cache ID to attach (empty string to detach)} {--websocket-application-id= : WebSocket application ID to attach (empty string to detach)} {--model-gateway-key-id= : Model gateway key ID to attach, exposed as LARAVEL_CLOUD_MODEL_GATEWAY_API_KEY from the next deployment (empty string to detach)} + {--aws-role-arn= : IAM role ARN the application assumes, on a dedicated cluster with bring your own IAM role (empty string to remove)} {--bucket-keys= : Bucket keys to attach as comma-separated KEY_ID:DISK entries, with :default on at most one (fk-1:local:default,fk-2:public). Replaces every attached bucket; empty string to detach all} {--force : Force update without confirmation}'; @@ -130,6 +131,7 @@ protected function updateEnvironment(Environment $environment): Environment cacheId: $this->form()->get('cache_id'), websocketApplicationId: $this->form()->get('websocket_application_id'), modelGatewayKeyId: $this->form()->get('model_gateway_key_id'), + awsRoleArn: $this->form()->get('aws_role_arn'), usesOctane: $this->form()->boolean('uses_octane'), sleepTimeout: $this->form()->integer('sleep_timeout'), hibernationWakeUpInterval: $this->clearableInteger('hibernation_wake_up_interval'), @@ -451,6 +453,21 @@ protected function defineFields(Environment $environment): void 'model-gateway-key-id', )->setPreviousValue($environment->modelGatewayKeyId ?? '')->setLabel('Model gateway key'); + // Only an environment on a dedicated cluster can assume a role of its own, so the others aren't offered it. + if ($environment->clusterId !== null || $this->option('aws-role-arn') !== null) { + $this->form()->define( + 'aws_role_arn', + fn ($resolver) => $resolver->fromInput( + fn ($value) => text( + label: 'AWS role ARN', + default: $value ?? $environment->awsRoleArn ?? '', + hint: 'Leave empty to remove the role', + ), + ), + 'aws-role-arn', + )->setPreviousValue($environment->awsRoleArn ?? '')->setLabel('AWS role ARN'); + } + // Named after the API field so a validation error on filesystem_keys.* asks for the buckets again. $this->form()->define( 'filesystem_keys', diff --git a/app/Dto/Environment.php b/app/Dto/Environment.php index 4158ea19..be418ec9 100644 --- a/app/Dto/Environment.php +++ b/app/Dto/Environment.php @@ -69,6 +69,11 @@ public function __construct( public readonly ?string $postDeployCommand = null, public readonly bool $usesHttpBasicAuth = false, public readonly ?EnvironmentInternalNetworking $internalNetworking = null, + /** Null on shared compute. */ + public readonly ?string $clusterId = null, + /** The API sends it only for an environment on a dedicated cluster, in an organization with bring your own IAM role. */ + public readonly ?string $awsRoleArn = null, + public readonly ?string $awsTrustPolicy = null, ) { // } @@ -115,6 +120,9 @@ public static function createFromResponse(array $response): self 'postDeployCommand' => $attributes['post_deploy_command'] ?? null, 'usesHttpBasicAuth' => $attributes['uses_http_basic_auth'] ?? false, 'internalNetworking' => isset($attributes['internal_networking']) ? EnvironmentInternalNetworking::createFromResponse($attributes['internal_networking']) : null, + 'clusterId' => $attributes['cluster_id'] ?? null, + 'awsRoleArn' => $attributes['aws_role_arn'] ?? null, + 'awsTrustPolicy' => $attributes['aws_trust_policy'] ?? null, 'resend' => isset($attributes['resend']) ? EnvironmentResend::createFromResponse($attributes['resend']) : null, ]; diff --git a/tests/Feature/EnvironmentUpdateTest.php b/tests/Feature/EnvironmentUpdateTest.php index e2657248..bdf77cec 100644 --- a/tests/Feature/EnvironmentUpdateTest.php +++ b/tests/Feature/EnvironmentUpdateTest.php @@ -33,6 +33,9 @@ 'post_deploy_command' => 'php artisan cache:clear', 'uses_http_basic_auth' => true, 'uses_read_only_build_token' => true, + 'cluster_id' => 'cluster-1', + 'aws_role_arn' => 'arn:aws:iam::123456789012:role/laravel-cloud', + 'aws_trust_policy' => '{"Version":"2012-10-17","Statement":[]}', 'internal_networking' => [ 'enabled' => true, 'hostname' => 'production.internal', @@ -308,6 +311,33 @@ function updateEnvironment(array $options): void ->and(explode(',', $this->sent->include))->toContain('modelGatewayKey'); }); +it('sends the AWS role ARN', function () { + updateEnvironment(['--aws-role-arn' => 'arn:aws:iam::123456789012:role/storefront']); + + expect($this->sent->body)->toBe(['aws_role_arn' => 'arn:aws:iam::123456789012:role/storefront']); +}); + +it('removes the AWS role with an empty string', function () { + updateEnvironment(['--aws-role-arn' => '']); + + expect($this->sent->body)->toBe(['aws_role_arn' => null]); +}); + +it('exposes the dedicated cluster and AWS role', function () { + Artisan::call('environment:get', [ + 'environment' => 'env-1', + '--json' => true, + '--fields' => 'clusterId,awsRoleArn,awsTrustPolicy', + '--no-interaction' => true, + ]); + + expect(json_decode(Artisan::output(), true))->toBe([ + 'clusterId' => 'cluster-1', + 'awsRoleArn' => 'arn:aws:iam::123456789012:role/laravel-cloud', + 'awsTrustPolicy' => '{"Version":"2012-10-17","Statement":[]}', + ]); +}); + it('exposes whether builds use a read-only token', function () { Artisan::call('environment:get', [ 'environment' => 'env-1', From 7041cbe1e3b227a54dafe774df9b115f84911906 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 30 Nov 2026 12:11:33 +0000 Subject: [PATCH 3/4] Read a Resend sender the API reports as unset Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01T1Sq4XHhc6agf3Z2SuRBdi --- app/Commands/ResendAttach.php | 4 ++- app/Concerns/ManagesResend.php | 4 +-- app/Dto/EnvironmentResend.php | 19 ++++++++----- tests/Feature/ResendCommandsTest.php | 40 ++++++++++++++++++++++++++++ 4 files changed, 58 insertions(+), 9 deletions(-) diff --git a/app/Commands/ResendAttach.php b/app/Commands/ResendAttach.php index 367b26be..dd52e7f1 100644 --- a/app/Commands/ResendAttach.php +++ b/app/Commands/ResendAttach.php @@ -49,7 +49,9 @@ public function handle() $environment = $this->resolveResendEnvironment(attached: false, includes: ['application']); if ($environment->resend) { - $this->failAndExit("Resend is already attached to {$environment->name}, sending as {$environment->resend->sender()}. Change the sender with `cloud resend:update`."); + $sendingAs = ($sender = $environment->resend->sender()) !== null ? ", sending as {$sender}" : ''; + + $this->failAndExit("Resend is already attached to {$environment->name}{$sendingAs}. Change the sender with `cloud resend:update`."); } $domains = $this->verifiedSendingDomains(); diff --git a/app/Concerns/ManagesResend.php b/app/Concerns/ManagesResend.php index 29ecef41..2d9eb096 100644 --- a/app/Concerns/ManagesResend.php +++ b/app/Concerns/ManagesResend.php @@ -123,7 +123,7 @@ protected function failWithoutSendingDomains(): never /** * @param list $domains */ - protected function promptForSender(array $domains, ?string $currentAddress, string $currentName): void + protected function promptForSender(array $domains, ?string $currentAddress, ?string $currentName): void { $this->form()->prompt( 'from_address', @@ -137,7 +137,7 @@ protected function promptForSender(array $domains, ?string $currentAddress, stri fn ($resolver) => $resolver ->fromInput(fn (?string $value) => text( label: 'Sender name', - default: $value ?? $currentName, + default: $value ?? $currentName ?? '', required: true, )) ->nonInteractively(fn () => $currentName), diff --git a/app/Dto/EnvironmentResend.php b/app/Dto/EnvironmentResend.php index a08fd381..2b769a5a 100644 --- a/app/Dto/EnvironmentResend.php +++ b/app/Dto/EnvironmentResend.php @@ -7,8 +7,8 @@ class EnvironmentResend extends Data { public function __construct( - public readonly string $fromAddress, - public readonly string $fromName, + public readonly ?string $fromAddress, + public readonly ?string $fromName, public readonly string $keyName, ) { // @@ -17,14 +17,21 @@ public function __construct( public static function createFromResponse(array $resend): self { return new self( - fromAddress: $resend['from_address'], - fromName: $resend['from_name'], + fromAddress: $resend['from_address'] ?? null, + fromName: $resend['from_name'] ?? null, keyName: $resend['key_name'], ); } - public function sender(): string + /** + * The API can report Resend attached with no sender set, so either half may be missing. + */ + public function sender(): ?string { - return "{$this->fromName} <{$this->fromAddress}>"; + if ($this->fromName !== null && $this->fromAddress !== null) { + return "{$this->fromName} <{$this->fromAddress}>"; + } + + return $this->fromAddress ?? $this->fromName; } } diff --git a/tests/Feature/ResendCommandsTest.php b/tests/Feature/ResendCommandsTest.php index c6f6391b..1224a48f 100644 --- a/tests/Feature/ResendCommandsTest.php +++ b/tests/Feature/ResendCommandsTest.php @@ -11,6 +11,7 @@ use App\Cloud; use App\ConfigRepository; use App\Dto\Application; +use App\Dto\EnvironmentResend; use App\Dto\Organization; use App\Git; use Illuminate\Support\Composer; @@ -268,6 +269,45 @@ function setupResendMocks(?array $resend = null, ?array $domains = null, array $ ]); }); +it('updates a sender the API reports as unset', function () { + $sent = setupResendMocks(resend: resendSettings(['from_address' => null, 'from_name' => null])); + + $this->artisan('resend:update', [ + 'environment' => 'env-1', + '--from-address' => 'team@example.com', + '--from-name' => 'Acme', + '--no-interaction' => true, + ])->assertSuccessful(); + + expect($sent()->update['body'])->toBe([ + 'from_address' => 'team@example.com', + 'from_name' => 'Acme', + ]); +}); + +it('requires the sender name when the API reports none', function () { + $sent = setupResendMocks(resend: resendSettings(['from_name' => null])); + + $this->artisan('resend:update', [ + 'environment' => 'env-1', + '--from-address' => 'team@example.com', + '--no-interaction' => true, + ])->assertFailed(); + + expect($sent()->update ?? null)->toBeNull(); +}); + +it('reads a Resend sender with either half unset', function (?string $address, ?string $name, ?string $sender) { + $resend = EnvironmentResend::createFromResponse(resendSettings(['from_address' => $address, 'from_name' => $name])); + + expect($resend->sender())->toBe($sender); +})->with([ + 'both' => ['hello@example.com', 'My App', 'My App '], + 'no name' => ['hello@example.com', null, 'hello@example.com'], + 'no address' => [null, 'My App', 'My App'], + 'neither' => [null, null, null], +]); + it('refuses to update when Resend is not attached', function () { $sent = setupResendMocks(); From 2fdf43690990debc197cdfaa46c87f466f3b21a9 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 30 Nov 2026 13:10:51 +0000 Subject: [PATCH 4/4] Expose an environment's display name Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01T1Sq4VXQKRFwYMC5mNaee6 --- app/Dto/Environment.php | 2 ++ tests/Feature/EnvironmentUpdateTest.php | 15 +++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/app/Dto/Environment.php b/app/Dto/Environment.php index be418ec9..70247b92 100644 --- a/app/Dto/Environment.php +++ b/app/Dto/Environment.php @@ -74,6 +74,7 @@ public function __construct( /** The API sends it only for an environment on a dedicated cluster, in an organization with bring your own IAM role. */ public readonly ?string $awsRoleArn = null, public readonly ?string $awsTrustPolicy = null, + public readonly ?string $displayName = null, ) { // } @@ -123,6 +124,7 @@ public static function createFromResponse(array $response): self 'clusterId' => $attributes['cluster_id'] ?? null, 'awsRoleArn' => $attributes['aws_role_arn'] ?? null, 'awsTrustPolicy' => $attributes['aws_trust_policy'] ?? null, + 'displayName' => $attributes['display_name'] ?? null, 'resend' => isset($attributes['resend']) ? EnvironmentResend::createFromResponse($attributes['resend']) : null, ]; diff --git a/tests/Feature/EnvironmentUpdateTest.php b/tests/Feature/EnvironmentUpdateTest.php index bdf77cec..f5ab5ef2 100644 --- a/tests/Feature/EnvironmentUpdateTest.php +++ b/tests/Feature/EnvironmentUpdateTest.php @@ -36,6 +36,7 @@ 'cluster_id' => 'cluster-1', 'aws_role_arn' => 'arn:aws:iam::123456789012:role/laravel-cloud', 'aws_trust_policy' => '{"Version":"2012-10-17","Statement":[]}', + 'display_name' => 'Production', 'internal_networking' => [ 'enabled' => true, 'hostname' => 'production.internal', @@ -361,3 +362,17 @@ function updateEnvironment(array $options): void expect($this->sent->body)->toBe(['uses_read_only_build_token' => false]); }); + +it('exposes the display name', function () { + Artisan::call('environment:get', [ + 'environment' => 'env-1', + '--json' => true, + '--fields' => 'name,displayName', + '--no-interaction' => true, + ]); + + expect(json_decode(Artisan::output(), true))->toBe([ + 'name' => 'production', + 'displayName' => 'Production', + ]); +});