Skip to content

Commit

Permalink
patch,put,delete on metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
killua-eu committed Feb 20, 2024
1 parent 4f884df commit 2818dba
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 66 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ TODO: token

```bash
#create a new file
#curl -k -X POST https://glued/api/stor/v1/buckets/1fcb4d5c-5364-4cf3-b24e-070c4c71f8d2/objects
#curl -k -X POST https://glued/api/stor/v1/buckets/1fcb4d5c-5364-4cf3-b24e-070c4c71f8d2/objects \
curl -k -X POST https://gdev.industra.space/api/stor/v1/buckets/30ef1e33-da44-4503-85b0-a2ba41e2d82e/objects \
-H 'Authorization: Bearer gtk_35MCHFgkNh1PymQEOLStzMtESdo4DZXykoYWvjX9QcQ=' \
-H 'Content-Type: multipart/form-data' \
Expand All @@ -31,6 +31,11 @@ curl -k -X POST https://gdev.industra.space/api/stor/v1/buckets/30ef1e33-da44-45
-F 'file[]=@/home/killua/Ryanair.pdf' \
-F 'file[]=@/home/killua/eastern loves_INDUSTRA.png' \
-F 'field1=fiels2' | jq .

curl -k -X PATCH "https://glued/api/stor/v1/buckets/1fcb4d5c-5364-4cf3-b24e-070c4c71f8d2/objects/a2134852-e39f-4b81-8071-2971d1d48506/meta" -H "Content-Type: application/json" -d '{"example": 1}'
curl -k -X PATCH "https://gdev.industra.space/api/stor/v1/buckets/30ef1e33-da44-4503-85b0-a2ba41e2d82e/objects/e4f2ce6f-f4db-462d-8712-61928a5142f2/meta" -H "Content-Type: application/json" -d '{"example": 1}'
curl -k -X PUT "https://glued/api/stor/v1/buckets/1fcb4d5c-5364-4cf3-b24e-070c4c71f8d2/objects/a2134852-e39f-4b81-8071-2971d1d48506/refs" -H "Content-Type: application/json" -d '{"predecessor": "a2134852-e39f-4b81-8071-2971d1d48506", "sekatko:vpd": "a2134852-e39f-4b81-8071-2971d1d48506"}'
curl -k -X DELETE "https://glued/api/stor/v1/buckets/1fcb4d5c-5364-4cf3-b24e-070c4c71f8d2/objects/a2134852-e39f-4b81-8071-2971d1d48506/refs" -H "Content-Type: application/json" -d '{"predecessor": "a2134852-e39f-4b81-8071-2971d1d48506", "sekatko:vpd": "a2134852-e39f-4b81-8071-2971d1d48506"}'
```


Expand Down
2 changes: 1 addition & 1 deletion glued/Config/routes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ routes:
get: Glued\Controllers\ServiceController:dgs_r1

be_stor_objects_v1:
pattern: ${routes.be_stor.path}/v1/buckets/{bucket}/objects[/{object}[/{method}]]
pattern: ${routes.be_stor.path}/v1/buckets/{bucket}/objects[/{object}[/{element}]]
path: ${routes.be_stor.path}/v1/buckets
label: objects
dscr: Data objects
Expand Down
114 changes: 50 additions & 64 deletions glued/Controllers/ServiceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ private function write_object($file, $bucket, $meta = null, $refs = null): array
return isset($device["path"]) && is_string($device["path"]) &&
$device["health"] == "online" && $device["role"] == "storage" && $device["adapter"] == "filesystem";
});
if (count($localDevices) == 0) { throw new \Exception('No local writable devices available/online'); }
if (count($localDevices) == 0) { throw new \Exception('No local writable devices configured/online', 500); }
$device = $localDevices[0];
// Get uploaded file metadata
$object = $this->object_meta($file);
Expand Down Expand Up @@ -740,86 +740,72 @@ public function objects_r1(Request $request, Response $response, array $args = [

public function objects_d1(Request $request, Response $response, array $args = []): Response
{
$data = [
'timestamp' => microtime(),
'status' => '501 Not implemented',
'service' => basename(__ROOT__),
'data' => null
];
if (!array_key_exists('bucket', $args)) {
throw new Exception('Bucket not found.', 400);
}
if (array_key_exists('object', $args)) {
if (array_key_exists('method', $args)) {
if ($args['method'] == 'refs') {
$data['status'] = "Deleted";
$body = json_decode($request->getBody()->getContents(), true);
$firstkey = array_values($body)[0];
if (!is_string($firstkey)) { throw new \Exception('Request body must be reftype: [uuid] object'); }
$this->object_refs($args['object'], $body, 'del');
return $response->withJson($data)->withStatus(200);
}
}
if (!array_key_exists('bucket', $args)) { throw new Exception('Bucket UUID missing in request uri `/api/stor/v1/buckets/{bucket}/objects/{object}/{element}`.', 400); }
if (!array_key_exists('object', $args)) { throw new Exception('Object UUID missing in request uri `/api/stor/v1/buckets/{bucket}/objects/{object}/{element}`.', 400); }
if (!array_key_exists('element', $args)) { throw new Exception('Element UUID missing in request uri `/api/stor/v1/buckets/{bucket}/objects/{object}/{element}`.', 400); }
if ($args['element'] == 'refs') {
$body = $request->getParsedBody();
if (is_null($body)) { throw new \Exception('Request body must be a valid json', 400); }
$this->object_refs($args['object'], $body, 'del');
$data = [
'timestamp' => microtime(),
'status' => '200 Deleted',
'service' => basename(__ROOT__),
'data' => $body
];
return $response->withJson($data)->withStatus(200);
} else {
throw new Exception('DELETE request supported elements are: `refs`.', 400);
}
return $response->withJson($data)->withStatus(501);
}


public function objects_put1(Request $request, Response $response, array $args = []): Response
{
$data = [
'timestamp' => microtime(),
'status' => '501 Not implemented',
'service' => basename(__ROOT__),
'data' => null
];
if (!array_key_exists('bucket', $args)) {
throw new Exception('Bucket not found.', 400);
}
if (array_key_exists('object', $args)) {
if (array_key_exists('method', $args)) {
if ($args['method'] == 'refs') {
$data['status'] = "Added";
$body = json_decode($request->getBody()->getContents(), true);
$firstkey = array_values($body)[0];
if (!is_string($firstkey)) { throw new \Exception('Request body must be reftype: [uuid] object'); }
$this->object_refs($args['object'], $body, 'add');
return $response->withJson($data)->withStatus(200);
}
}
if (!array_key_exists('bucket', $args)) { throw new Exception('Bucket UUID missing in request uri `/api/stor/v1/buckets/{bucket}/objects/{object}/{element}`.', 400); }
if (!array_key_exists('object', $args)) { throw new Exception('Object UUID missing in request uri `/api/stor/v1/buckets/{bucket}/objects/{object}/{element}`.', 400); }
if (!array_key_exists('element', $args)) { throw new Exception('Element UUID missing in request uri `/api/stor/v1/buckets/{bucket}/objects/{object}/{element}`.', 400); }
if ($args['element'] == 'refs') {
$body = $request->getParsedBody();
if (is_null($body)) { throw new \Exception('Request body must be a valid json', 400); }
$this->object_refs($args['object'], $body, 'add');
$data = [
'timestamp' => microtime(),
'status' => '200 Added',
'service' => basename(__ROOT__),
'data' => $body
];
return $response->withJson($data)->withStatus(200);
} else {
throw new Exception('PUT request supported elements are: `refs`.', 400);
}
return $response->withJson($data)->withStatus(501);
}

public function objects_p1(Request $request, Response $response, array $args = []): Response
{
$data = [
'timestamp' => microtime(),
'status' => '501 Not implemented',
'service' => basename(__ROOT__),
'data' => null
];
if (!array_key_exists('bucket', $args)) {
throw new Exception('Bucket not found.', 400);
}
if (array_key_exists('object', $args)) {
if (array_key_exists('method', $args)) {
if ($args['method'] == 'refs') {
$data['status'] = "Patched";
$body = json_decode($request->getBody()->getContents());
if (is_null($body)) { throw new \Exception('Request body must be a valid json'); }
$this->patch_object_meta($args['object'], $body);
return $response->withJson($data)->withStatus(200);
}
}
if (!array_key_exists('bucket', $args)) { throw new Exception('Bucket UUID missing in request uri `/api/stor/v1/buckets/{bucket}/objects/{object}/{element}`.', 400); }
if (!array_key_exists('object', $args)) { throw new Exception('Object UUID missing in request uri `/api/stor/v1/buckets/{bucket}/objects/{object}/{element}`.', 400); }
if (!array_key_exists('element', $args)) { throw new Exception('Element UUID missing in request uri `/api/stor/v1/buckets/{bucket}/objects/{object}/{element}`.', 400); }
if ($args['element'] == 'meta') {
$body = $request->getParsedBody();
if (is_null($body)) { throw new \Exception('Request body must be a valid json', 400); }
$this->patch_object_meta($args['object'], $body);
$data = [
'timestamp' => microtime(),
'status' => '200 Patched',
'service' => basename(__ROOT__),
'data' => $body
];
return $response->withJson($data)->withStatus(200);
} else {
throw new Exception('PATCH request supported elements are: `meta`.', 400);
}
return $response->withJson($data)->withStatus(501);
}

/// ///////////////////////////////////////////////////////////////////////////////
/// OBJECTS (data objects)
/// ///////////////////////////////////////////////////////////////////////////////


public function generateRetrievalKey($bkt, $obj, $ttl = 3600): string
{
$iat = time();
Expand Down

0 comments on commit 2818dba

Please sign in to comment.