Skip to content
This repository was archived by the owner on Apr 27, 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
1 change: 0 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ concurrency: ci-pipeline
env:
KBC_STORAGE_TOKEN: '${{ secrets.KBC_STORAGE_TOKEN }}'
KBC_MANAGE_TOKEN: '${{ secrets.KBC_MANAGE_TOKEN }}'
KBC_MANAGE_NOTIFY_TOKEN: '${{ secrets.KBC_MANAGE_NOTIFY_TOKEN }}'
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was used for sandboxes-api on CI,, but sandboxes-api no longer needs this environment variable


# Azure
AZURE_CLIENT_ID: 233328da-9afe-423b-82c1-915d8c539f71
Expand Down
1 change: 0 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ services:
KBC_URL: https://connection.keboola.com
KBC_STORAGE_TOKEN:
KBC_MANAGE_TOKEN:
KBC_MANAGE_NOTIFY_TOKEN:
DYNAMO_ENDPOINT: http://localstack:4566
DYNAMO_TABLE_SANDBOXES: sandboxes
DYNAMO_TABLE_ML_DEPLOYMENTS: ml-deployments
Expand Down
7 changes: 7 additions & 0 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ public function update(Sandbox $sandbox): Sandbox
return Sandbox::fromArray($this->sendRequest($request));
}

public function updateAutosaveTimestamp(string $id, string $timestamp): Sandbox
{
$jobData = json_encode(['lastAutosaveTimestamp' => $timestamp]);
$request = new Request('PATCH', "sandboxes/{$id}", [], $jobData);
return Sandbox::fromArray($this->sendRequest($request));
}

public function deactivate(string $id, bool $skipBillingReport = false): Sandbox
{
$query = [];
Expand Down
24 changes: 24 additions & 0 deletions tests/ClientFunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,30 @@ public function testProjectPersistentStorage(): void
self::assertNull($persistentStorage->getK8sStorageClassName());
}

public function testUpdateAutosaveTimestamp(): void
{
// 1. Create sandbox
$sandbox = (new Sandbox())
->setType('python')
->setActive(true);

$createdSandbox = $this->client->create($sandbox);
$sandboxId = $createdSandbox->getId();
$this->assertNotEmpty($sandboxId);

// 2. Update autosave timestamp
$timestamp = date('c');
$updatedSandbox = $this->client->updateAutosaveTimestamp($sandboxId, $timestamp);
$this->assertSame($timestamp, $updatedSandbox->getLastAutosaveTimestamp());

// 3. Verify persistence by getting the sandbox again
$retrievedSandbox = $this->client->get($sandboxId);
$this->assertSame($timestamp, $retrievedSandbox->getLastAutosaveTimestamp());

// 4. Clean up
$this->client->delete($sandboxId);
}

protected function tearDown(): void
{
$this->componentsClient->deleteConfiguration('transformation', $this->configurationId);
Expand Down
51 changes: 51 additions & 0 deletions tests/ClientUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,4 +184,55 @@ public function testDelete(string $sandboxId, bool $skipBillingReport, string $e
));
self::assertSame('', (string) $request->getBody());
}

public function testUpdateAutosaveTimestamp(): void
{
$requestsLog = [];
$sandboxId = '123';
$timestamp = '2025-01-18T10:30:00+00:00';
$responseData = [
'id' => $sandboxId,
'projectId' => 'project-id',
'tokenId' => 'token-id',
'type' => 'python',
'active' => true,
'createdTimestamp' => '2021-01-01T00:00:00+00:00',
'lastAutosaveTimestamp' => $timestamp,
];

$mockedResponses = [
new Response(200, [], (string) json_encode($responseData)),
];

$handlerStack = HandlerStack::create(new MockHandler($mockedResponses));
$handlerStack->push(Middleware::history($requestsLog));

$client = new Client((string) getenv('API_URL'), (string) getenv('KBC_STORAGE_TOKEN'), [
'handler' => $handlerStack,
]);

$result = $client->updateAutosaveTimestamp($sandboxId, $timestamp);

self::assertEquals(Sandbox::fromArray($responseData), $result);
self::assertEquals($timestamp, $result->getLastAutosaveTimestamp());

self::assertCount(1, $requestsLog);

$request = $requestsLog[0]['request'];
self::assertInstanceOf(Request::class, $request);

self::assertSame('PATCH', $request->getMethod());
self::assertSame('/sandboxes/123', Uri::composeComponents(
'',
'',
$request->getUri()->getPath(),
$request->getUri()->getQuery(),
'',
));

$requestBody = json_decode((string) $request->getBody(), true);
self::assertIsArray($requestBody);
self::assertArrayHasKey('lastAutosaveTimestamp', $requestBody);
self::assertSame($timestamp, $requestBody['lastAutosaveTimestamp']);
}
}
3 changes: 1 addition & 2 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
if (file_exists(__DIR__ . '/../.env')) {
$dotenv->load();
}
$dotenv->required(['API_URL', 'KBC_MANAGE_TOKEN', 'KBC_MANAGE_NOTIFY_TOKEN', 'KBC_STORAGE_TOKEN', 'KBC_URL']);
$dotenv->required(['API_URL', 'KBC_MANAGE_TOKEN', 'KBC_STORAGE_TOKEN', 'KBC_URL']);

$tokenEnvs = [
'KBC_STORAGE_TOKEN',
Expand Down Expand Up @@ -69,7 +69,6 @@

$tokenEnvs = [
'KBC_MANAGE_TOKEN',
'KBC_MANAGE_NOTIFY_TOKEN',
];

foreach ($tokenEnvs as $tokenEnv) {
Expand Down