@smythos/sre 1.5.9 → 1.5.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/dist/types/subsystems/IO/Storage.service/SmythFS.class.d.ts +3 -2
- package/dist/types/subsystems/IO/Storage.service/connectors/S3Storage.class.d.ts +4 -2
- package/dist/types/subsystems/Security/AccessControl/AccessCandidate.class.d.ts +1 -0
- package/package.json +1 -1
- package/src/subsystems/AgentManager/Agent.class.ts +3 -2
- package/src/subsystems/IO/Storage.service/SmythFS.class.ts +20 -3
- package/src/subsystems/IO/Storage.service/connectors/LocalStorage.class.ts +2 -0
- package/src/subsystems/IO/Storage.service/connectors/S3Storage.class.ts +9 -1
- package/src/subsystems/Security/AccessControl/AccessCandidate.class.ts +7 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { IAccessCandidate } from '@sre/types/ACL.types';
|
|
2
|
-
import { StorageMetadata } from '@sre/types/Storage.types';
|
|
2
|
+
import { StorageData, StorageMetadata } from '@sre/types/Storage.types';
|
|
3
3
|
import { StorageConnector } from './StorageConnector';
|
|
4
4
|
import { CacheConnector } from '@sre/MemoryManager/Cache.service/CacheConnector';
|
|
5
5
|
export type TSmythFSURI = {
|
|
@@ -24,7 +24,8 @@ export declare class SmythFS {
|
|
|
24
24
|
* @returns
|
|
25
25
|
*/
|
|
26
26
|
read(uri: string, candidate?: IAccessCandidate): Promise<Buffer>;
|
|
27
|
-
|
|
27
|
+
getMetadata(uri: string, candidate?: IAccessCandidate): Promise<Record<string, any>>;
|
|
28
|
+
write(uri: string, data: StorageData, candidate?: IAccessCandidate, metadata?: StorageMetadata, ttl?: number): Promise<void>;
|
|
28
29
|
delete(uri: string, candidate?: IAccessCandidate): Promise<void>;
|
|
29
30
|
exists(uri: string, candidate?: IAccessCandidate): Promise<boolean>;
|
|
30
31
|
genTempUrl(uri: string, candidate?: IAccessCandidate, ttlSeconds?: number): Promise<string>;
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { StorageConnector } from '@sre/IO/Storage.service/StorageConnector';
|
|
2
2
|
import { ACL } from '@sre/Security/AccessControl/ACL.class';
|
|
3
3
|
import { IAccessCandidate, IACL } from '@sre/types/ACL.types';
|
|
4
|
-
import { AWSRegionConfig, AWSCredentials } from '@sre/types/AWS.types';
|
|
5
4
|
import { StorageData, StorageMetadata } from '@sre/types/Storage.types';
|
|
6
5
|
import { AccessRequest } from '@sre/Security/AccessControl/AccessRequest.class';
|
|
7
|
-
export type S3Config =
|
|
6
|
+
export type S3Config = {
|
|
7
|
+
region: string;
|
|
8
|
+
accessKeyId: string;
|
|
9
|
+
secretAccessKey: string;
|
|
8
10
|
bucket: string;
|
|
9
11
|
};
|
|
10
12
|
export declare class S3Storage extends StorageConnector {
|
package/package.json
CHANGED
|
@@ -17,6 +17,7 @@ import { AccessCandidate } from '@sre/Security/AccessControl/AccessCandidate.cla
|
|
|
17
17
|
|
|
18
18
|
const console = Logger('Agent');
|
|
19
19
|
const idPromise = (id) => id;
|
|
20
|
+
const MAX_LATENCY = 50;
|
|
20
21
|
|
|
21
22
|
export class Agent implements IAgent {
|
|
22
23
|
public name: any;
|
|
@@ -302,9 +303,9 @@ export class Agent implements IAgent {
|
|
|
302
303
|
step = await this.agentRuntime.runCycle();
|
|
303
304
|
|
|
304
305
|
//adjust latency based on cpu load
|
|
305
|
-
const qosLatency = Math.floor(OSResourceMonitor.cpu.load *
|
|
306
|
+
const qosLatency = Math.floor(OSResourceMonitor.cpu.load * MAX_LATENCY || 0);
|
|
306
307
|
|
|
307
|
-
await delay(
|
|
308
|
+
await delay(10 + qosLatency);
|
|
308
309
|
} while (!step?.finalResult && !this._kill);
|
|
309
310
|
|
|
310
311
|
if (this._kill) {
|
|
@@ -113,7 +113,24 @@ export class SmythFS {
|
|
|
113
113
|
return data ? this.toBuffer(data) : null;
|
|
114
114
|
}
|
|
115
115
|
|
|
116
|
-
|
|
116
|
+
|
|
117
|
+
public async getMetadata(uri: string, candidate?: IAccessCandidate) {
|
|
118
|
+
const smythURI = await this.URIParser(uri);
|
|
119
|
+
if (!smythURI) throw new Error('Invalid Resource URI');
|
|
120
|
+
candidate = candidate || smythURI.defaultCandidate; //fallback to default candidate if not provided
|
|
121
|
+
|
|
122
|
+
const accountConnector = ConnectorService.getAccountConnector();
|
|
123
|
+
const isMember = await accountConnector.isTeamMember(smythURI.team, candidate);
|
|
124
|
+
if (!isMember) throw new Error('Access Denied');
|
|
125
|
+
|
|
126
|
+
const resourceId = `teams/${smythURI.team}${smythURI.path}`;
|
|
127
|
+
|
|
128
|
+
const _candidate = candidate instanceof AccessCandidate ? candidate : new AccessCandidate(candidate);
|
|
129
|
+
|
|
130
|
+
return await this.storage.requester(_candidate).getMetadata(resourceId);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
public async write(uri: string, data: StorageData, candidate?: IAccessCandidate, metadata?: StorageMetadata, ttl?: number) {
|
|
117
134
|
const smythURI = await this.URIParser(uri);
|
|
118
135
|
if (!smythURI) throw new Error('Invalid Resource URI');
|
|
119
136
|
candidate = candidate || smythURI.defaultCandidate; //fallback to default candidate if not provided
|
|
@@ -380,10 +397,10 @@ export class SmythFS {
|
|
|
380
397
|
let candidate: IAccessCandidate;
|
|
381
398
|
if (user) {
|
|
382
399
|
candidate = AccessCandidate.user(user);
|
|
383
|
-
basePath = '/' + user;
|
|
400
|
+
basePath = '.user/' + user;
|
|
384
401
|
} else if (agent) {
|
|
385
402
|
candidate = AccessCandidate.agent(agent);
|
|
386
|
-
basePath = '/' + agent;
|
|
403
|
+
basePath = '.agent/' + agent;
|
|
387
404
|
}
|
|
388
405
|
|
|
389
406
|
if (candidate) {
|
|
@@ -43,7 +43,15 @@ import { ConnectorService } from '@sre/Core/ConnectorsService';
|
|
|
43
43
|
|
|
44
44
|
const console = Logger('S3Storage');
|
|
45
45
|
|
|
46
|
-
export type S3Config = AWSCredentials & AWSRegionConfig & { bucket: string };
|
|
46
|
+
//export type S3Config = AWSCredentials & AWSRegionConfig & { bucket: string };
|
|
47
|
+
|
|
48
|
+
//We need to flatten the S3Config type in order to make it work with the SDK
|
|
49
|
+
export type S3Config = {
|
|
50
|
+
region: string;
|
|
51
|
+
accessKeyId: string;
|
|
52
|
+
secretAccessKey: string;
|
|
53
|
+
bucket: string;
|
|
54
|
+
};
|
|
47
55
|
|
|
48
56
|
export class S3Storage extends StorageConnector {
|
|
49
57
|
public name = 'S3Storage';
|
|
@@ -9,7 +9,13 @@ export class AccessCandidate implements IAccessCandidate {
|
|
|
9
9
|
//this._candidate = candidate || { role: TAccessRole.Public, id: '' };
|
|
10
10
|
|
|
11
11
|
this.role = candidate ? candidate.role : TAccessRole.Public;
|
|
12
|
-
this.id = candidate ? candidate.id : '';
|
|
12
|
+
this.id = candidate ? this._validateId(candidate.id) : '';
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
private _validateId(id: string) {
|
|
16
|
+
if (/[^a-zA-Z0-9-]/.test(id))
|
|
17
|
+
throw new Error('Access Candidate ID can only contain alphanumeric characters and hyphens');
|
|
18
|
+
return id;
|
|
13
19
|
}
|
|
14
20
|
|
|
15
21
|
public toString(): string {
|