Skip to content
This repository was archived by the owner on Nov 30, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions app/Client/Requests/UpdateEnvironmentRequestData.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ public function __construct(
public readonly ?string $databaseSchemaId = null,
public readonly ?string $cacheId = null,
public readonly ?string $websocketApplicationId = null,
/** @var string|null '' detaches it */
public readonly ?string $modelGatewayKeyId = null,
public readonly ?bool $usesOctane = null,
public readonly ?int $sleepTimeout = null,
/** @var int|string|null '' disables it */
Expand Down Expand Up @@ -74,6 +76,7 @@ public function toRequestData(): array
'database_schema_id' => $this->databaseSchemaId,
'cache_id' => $this->cacheId,
'websocket_application_id' => $this->websocketApplicationId,
'model_gateway_key_id' => $this->modelGatewayKeyId,
'uses_octane' => $this->usesOctane,
'sleep_timeout' => $this->sleepTimeout,
'hibernation_wake_up_interval' => $this->hibernationWakeUpInterval,
Expand Down
1 change: 1 addition & 0 deletions app/Client/Resources/EnvironmentsResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ public function withDefaultIncludes(): static
'database',
'cache',
'websocketApplication',
'modelGatewayKey',
'buckets',
);
}
Expand Down
15 changes: 15 additions & 0 deletions app/Commands/EnvironmentUpdate.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class EnvironmentUpdate extends BaseCommand
{--database-id= : Database ID to attach (empty string to detach)}
{--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)}
{--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}';

Expand Down Expand Up @@ -126,6 +127,7 @@ protected function updateEnvironment(Environment $environment): Environment
databaseSchemaId: $this->form()->get('database_id'),
cacheId: $this->form()->get('cache_id'),
websocketApplicationId: $this->form()->get('websocket_application_id'),
modelGatewayKeyId: $this->form()->get('model_gateway_key_id'),
usesOctane: $this->form()->boolean('uses_octane'),
sleepTimeout: $this->form()->integer('sleep_timeout'),
hibernationWakeUpInterval: $this->clearableInteger('hibernation_wake_up_interval'),
Expand Down Expand Up @@ -433,6 +435,19 @@ protected function defineFields(Environment $environment): void
'websocket-application-id',
)->setPreviousValue($environment->websocketApplicationId ?? '');

// The API has no endpoint that lists model gateway keys, so there is nothing to pick from.
$this->form()->define(
'model_gateway_key_id',
fn ($resolver) => $resolver->fromInput(
fn ($value) => text(
label: 'Model gateway key ID',
default: $value ?? $environment->modelGatewayKeyId ?? '',
hint: 'Leave empty to detach',
),
),
'model-gateway-key-id',
)->setPreviousValue($environment->modelGatewayKeyId ?? '')->setLabel('Model gateway key');

// Named after the API field so a validation error on filesystem_keys.* asks for the buckets again.
$this->form()->define(
'filesystem_keys',
Expand Down
5 changes: 5 additions & 0 deletions app/Dto/Environment.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public function __construct(
public readonly ?string $databaseSchemaId = null,
public readonly ?string $cacheId = null,
public readonly ?string $websocketApplicationId = null,
public readonly ?string $modelGatewayKeyId = null,
/** IDs of the attached buckets. The API does not say which key or disk each one uses. */
public readonly array $bucketIds = [],
#[DataCollectionOf(Secret::class)]
Expand Down Expand Up @@ -163,6 +164,10 @@ public static function createFromResponse(array $response): self
$transformed['websocketApplicationId'] = $relationships['websocketApplication']['data']['id'];
}

if (isset($relationships['modelGatewayKey']['data']['id'])) {
$transformed['modelGatewayKeyId'] = $relationships['modelGatewayKey']['data']['id'];
}

if (isset($relationships['buckets']['data'])) {
$transformed['bucketIds'] = array_column($relationships['buckets']['data'], 'id');
}
Expand Down
31 changes: 30 additions & 1 deletion tests/Feature/EnvironmentUpdateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,17 @@
],
], 'relationships' => [
'application' => ['data' => ['id' => 'app-123', 'type' => 'applications']],
'modelGatewayKey' => ['data' => ['id' => 'mgk-1', 'type' => 'model_gateway_keys']],
]]), 'included' => [createApplicationResponse()]];

MockClient::global([
GetOrganizationRequest::class => MockResponse::make(organizationResponse(), 200),
GetApplicationRequest::class => MockResponse::make(['data' => createApplicationResponse()], 200),
GetEnvironmentRequest::class => MockResponse::make($environment, 200),
GetEnvironmentRequest::class => function (PendingRequest $request) use ($environment) {
$this->sent->include = $request->query()->get('include');

return MockResponse::make($environment, 200);
},
UpdateEnvironmentRequest::class => function (PendingRequest $request) use ($environment) {
$this->sent->body = $request->body()->all();

Expand Down Expand Up @@ -276,3 +281,27 @@ function updateEnvironment(array $options): void
],
]);
});

it('attaches a model gateway key', function () {
updateEnvironment(['--model-gateway-key-id' => 'mgk-2']);

expect($this->sent->body)->toBe(['model_gateway_key_id' => 'mgk-2']);
});

it('detaches the model gateway key with an empty string', function () {
updateEnvironment(['--model-gateway-key-id' => '']);

expect($this->sent->body)->toBe(['model_gateway_key_id' => '']);
});

it('exposes the attached model gateway key', function () {
Artisan::call('environment:get', [
'environment' => 'env-1',
'--json' => true,
'--fields' => 'modelGatewayKeyId',
'--no-interaction' => true,
]);

expect(json_decode(Artisan::output(), true))->toBe(['modelGatewayKeyId' => 'mgk-1'])
->and(explode(',', $this->sent->include))->toContain('modelGatewayKey');
});