Skip to content

Commit 5e9fe8f

Browse files
committed
[DAPS-1515] Address pr comments
1 parent bfc57d9 commit 5e9fe8f

File tree

7 files changed

+60
-63
lines changed

7 files changed

+60
-63
lines changed

core/database/foxx/api/data_router.js

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ const g_lib = require("./support");
88
const g_proc = require("./process");
99
const g_tasks = require("./tasks");
1010
const { UserToken } = require("./lib/user_token");
11-
const { RepositoryOps } = require("./repository/operations");
12-
const { RepositoryType } = require("./repository/types");
11+
const { validateRepositorySupportsDataOperations } = require("./repository/validation");
1312

1413
module.exports = router;
1514

@@ -93,22 +92,11 @@ function recordCreate(client, record, result) {
9392
if (!repo_alloc) throw [g_lib.ERR_NO_ALLOCATION, "No allocation available"];
9493

9594
// Check if repository supports data operations
96-
var findResult = RepositoryOps.find(repo_alloc._to);
97-
if (findResult.ok) {
98-
var repository = findResult.value;
99-
var dataOpsResult = RepositoryOps.supportsDataOperations(repository);
100-
101-
if (dataOpsResult.ok && !dataOpsResult.value) {
102-
throw [
103-
g_lib.ERR_INVALID_OPERATION,
104-
"Data uploads not supported for metadata-only repository",
105-
{
106-
repo_type: repository.type,
107-
repo_id: repository.data._id,
108-
},
109-
];
110-
}
111-
}
95+
validateRepositorySupportsDataOperations(
96+
repo_alloc._to,
97+
null,
98+
"Data uploads not supported for metadata-only repository",
99+
);
112100

113101
// Extension setting only apply to managed data
114102
if (record.ext) {

core/database/foxx/api/repo_router.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ const g_lib = require("./support");
99
const g_tasks = require("./tasks");
1010
const { validateGlobusConfig, validatePartialGlobusConfig } = require("./repository/validation");
1111
const { RepositoryOps } = require("./repository/operations");
12-
const { RepositoryType } = require("./repository/types");
1312

1413
// Helper function to prepare repository data for saving
1514
const prepareRepoData = (obj) => {
@@ -692,21 +691,25 @@ router
692691
else subject_id = g_lib.getUserFromClientID(req.queryParams.subject)._id;
693692

694693
// Find the repository using the new type system
695-
var findResult = RepositoryOps.find(req.queryParams.repo);
694+
const findResult = RepositoryOps.find(req.queryParams.repo);
696695
if (!findResult.ok) {
697696
throw [findResult.error.code, findResult.error.message];
698697
}
699698

700-
var repository = findResult.value;
699+
const repository = findResult.value;
701700

702701
// Check permissions
703-
var permResult = RepositoryOps.checkPermission(repository, client._id, "admin");
702+
const permResult = RepositoryOps.checkPermission(
703+
repository,
704+
client._id,
705+
"admin",
706+
);
704707
if (!permResult.ok || !permResult.value) {
705708
throw g_lib.ERR_PERM_DENIED;
706709
}
707710

708711
// Create allocation using the new system
709-
var allocResult = RepositoryOps.createAllocation(repository, {
712+
const allocResult = RepositoryOps.createAllocation(repository, {
710713
subject: subject_id,
711714
size: req.queryParams.data_limit,
712715
rec_limit: req.queryParams.rec_limit,

core/database/foxx/api/repository/factory.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ const g_lib = require("../support");
3333
* @param {string} [config.pub_key] - Public key for ZeroMQ CURVE authentication (required for GLOBUS type)
3434
* @param {string} [config.address] - Network address (required for GLOBUS type)
3535
* @param {string} [config.exp_path] - Export path (optional for GLOBUS type)
36-
* @param {string} [config.domain] - Domain name (required for GLOBUS type)
3736
* @returns {{ok: boolean, error: *}|{ok: boolean, value: *}} Result object containing repository or error
3837
* @see https://doc.rust-lang.org/book/ch06-02-match.html
3938
*/
@@ -69,7 +68,6 @@ const createRepositoryByType = (config) => {
6968
pub_key: config.pub_key,
7069
address: config.address,
7170
exp_path: config.exp_path,
72-
domain: config.domain,
7371
});
7472

7573
const repoData = createRepositoryData({

core/database/foxx/api/repository/types.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,16 +71,14 @@ const createRepositoryData = ({
7171
* @param {string} config.pub_key - Public key for ZeroMQ CURVE authentication
7272
* @param {string} config.address - Network address
7373
* @param {string} [config.exp_path] - Export path
74-
* @param {string} config.domain - Domain name
75-
* @returns {{endpoint: string, path: string, pub_key: string, address: string, exp_path: string, domain: string}} Globus configuration object
74+
* @returns {{endpoint: string, path: string, pub_key: string, address: string, exp_path: string }} Globus configuration object
7675
*/
77-
const createGlobusConfig = ({ endpoint, path, pub_key, address, exp_path, domain }) => ({
76+
const createGlobusConfig = ({ endpoint, path, pub_key, address, exp_path }) => ({
7877
endpoint,
7978
path,
8079
pub_key,
8180
address,
8281
exp_path,
83-
domain,
8482
});
8583

8684
/**

core/database/foxx/api/repository/validation.js

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"use strict";
22

33
const { Result } = require("./types");
4+
const { RepositoryOps } = require("./operations");
45
const g_lib = require("../support");
56

67
/**
@@ -137,11 +138,6 @@ const validateGlobusConfig = (config) => {
137138
errors.push(endpointValidation.error.message);
138139
}
139140

140-
const domainValidation = validateNonEmptyString(config.domain, "Domain");
141-
if (!domainValidation.ok) {
142-
errors.push(domainValidation.error.message);
143-
}
144-
145141
if (errors.length > 0) {
146142
return Result.err({
147143
code: g_lib.ERR_INVALID_PARAM,
@@ -175,7 +171,7 @@ const validateMetadataConfig = (config) => {
175171

176172
// Metadata repositories don't need Globus-specific fields
177173
// But should not have them either
178-
const invalidFields = ["pub_key", "address", "endpoint", "path", "exp_path", "domain"];
174+
const invalidFields = ["pub_key", "address", "endpoint", "path", "exp_path"];
179175
const presentInvalidFields = invalidFields.filter((field) => config[field] !== undefined);
180176

181177
if (presentInvalidFields.length > 0) {
@@ -215,6 +211,29 @@ const validateAllocationParams = (params) => {
215211
return Result.ok(true);
216212
};
217213

214+
// Validates that a repository supports data operations
215+
const validateRepositorySupportsDataOperations = (repoId, dataId, errorMessage) => {
216+
const findResult = RepositoryOps.find(repoId);
217+
if (findResult.ok) {
218+
const repository = findResult.value;
219+
const dataOpsResult = RepositoryOps.supportsDataOperations(repository);
220+
221+
if (dataOpsResult.ok && !dataOpsResult.value) {
222+
const defaultMessage =
223+
errorMessage || `Data operations not supported for ${repository.type} repository`;
224+
throw [
225+
g_lib.ERR_INVALID_OPERATION,
226+
defaultMessage,
227+
{
228+
repo_type: repository.type,
229+
repo_id: repository.data._id,
230+
data_id: dataId,
231+
},
232+
];
233+
}
234+
}
235+
};
236+
218237
module.exports = {
219238
validateNonEmptyString,
220239
validateCommonFields,
@@ -223,4 +242,5 @@ module.exports = {
223242
validateGlobusConfig,
224243
validateMetadataConfig,
225244
validateAllocationParams,
245+
validateRepositorySupportsDataOperations,
226246
};

core/database/foxx/api/support.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -915,10 +915,10 @@ module.exports = (function () {
915915

916916
if (alloc.data_size < alloc.data_limit && alloc.rec_count < alloc.rec_limit) {
917917
// Check if repository supports data operations
918-
var findResult = RepositoryOps.find(alloc._to);
918+
const findResult = RepositoryOps.find(alloc._to);
919919
if (findResult.ok) {
920-
var repository = findResult.value;
921-
var dataOpsResult = RepositoryOps.supportsDataOperations(repository);
920+
const repository = findResult.value;
921+
const dataOpsResult = RepositoryOps.supportsDataOperations(repository);
922922

923923
// Skip metadata-only repositories
924924
if (dataOpsResult.ok && !dataOpsResult.value) {

core/database/foxx/api/tasks.js

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
const g_lib = require("./support");
44
const { UserToken } = require("./lib/user_token");
55
const { RepositoryOps } = require("./repository/operations");
6+
const { validateRepositorySupportsDataOperations } = require("./repository/validation");
67
const { RepositoryType } = require("./repository/types");
78

89
const g_db = require("@arangodb").db;
@@ -13,29 +14,6 @@ var g_internal = require("internal");
1314
const tasks_func = (function () {
1415
const obj = {};
1516

16-
// Helper function to validate repository supports data operations
17-
function validateRepositorySupportsDataOperations(loc, dataId) {
18-
if (loc) {
19-
const findResult = RepositoryOps.find(loc._to);
20-
if (findResult.ok) {
21-
const repository = findResult.value;
22-
const dataOpsResult = RepositoryOps.supportsDataOperations(repository);
23-
24-
if (dataOpsResult.ok && !dataOpsResult.value) {
25-
throw [
26-
g_lib.ERR_INVALID_OPERATION,
27-
`Data transfers not supported for ${repository.type} repository`,
28-
{
29-
repo_type: repository.type,
30-
repo_id: repository.data._id,
31-
data_id: dataId,
32-
},
33-
];
34-
}
35-
}
36-
}
37-
}
38-
3917
// ----------------------- ALLOC CREATE ----------------------------
4018

4119
obj.taskInitAllocCreate = function (
@@ -338,7 +316,13 @@ const tasks_func = (function () {
338316
var data = result.glob_data[i];
339317
// Get repository from data location
340318
var loc = g_db.loc.firstExample({ _from: data.id });
341-
validateRepositorySupportsDataOperations(loc, data.id);
319+
if (loc) {
320+
validateRepositorySupportsDataOperations(
321+
loc._to,
322+
data.id,
323+
`Data transfers not supported for this repository type`,
324+
);
325+
}
342326
}
343327
}
344328

@@ -532,7 +516,13 @@ const tasks_func = (function () {
532516
var data = result.glob_data[i];
533517
// Get repository from data location
534518
var loc = g_db.loc.firstExample({ _from: data.id });
535-
validateRepositorySupportsDataOperations(loc, data.id);
519+
if (loc) {
520+
validateRepositorySupportsDataOperations(
521+
loc._to,
522+
data.id,
523+
`Data transfers not supported for this repository type`,
524+
);
525+
}
536526
}
537527
}
538528

0 commit comments

Comments
 (0)