Merged 1.3.x_branch into master

This commit is contained in:
2021-03-04 17:10:53 +00:00
4 changed files with 60 additions and 17 deletions

View File

@@ -40,6 +40,18 @@ also be set to a strong, random password.
* For Skynet mounts, add `-sk` argument to all commands listed above. * For Skynet mounts, add `-sk` argument to all commands listed above.
* For ScPrime mounts, add `-sp` argument to all commands listed above. * For ScPrime mounts, add `-sp` argument to all commands listed above.
## Module Environment Variables
* To successfully complete unit tests, a `repertory` mount supporting remote mount needs to be
active. Set the following environment variables prior to running tests:
* `TEST_HOST`
* `TEST_PASSWORD`
* `TEST_PORT`
* To override the version being sent to `repertory`, set the following variable:
* `REPERTORY_JS_FORCE_VERSION`
* NOTE: This variable is primarily used for debugging/testing purposes and should normally
NOT be set.
## Example API Usage ## Example API Usage
```javascript ```javascript

View File

@@ -0,0 +1,27 @@
import {get_version, instance_id, package_json} from '../utils/constants'
const uuid = require('uuid');
test(`can read 'package.json'`, () => {
console.log(package_json);
expect(package_json).toBeDefined();
});
test(`'instance_id' is valid`, () => {
console.log(instance_id);
expect(instance_id).toBeDefined();
expect(uuid.parse(instance_id)).toBeInstanceOf(Uint8Array);
});
test(`'version' can be read from 'package.json'`, () => {
console.log(get_version());
expect(get_version()).toBe('1.3.1-r1');
});
test(`'version' can be overridden by environment variable`, () => {
console.log(process.env);
process.env.REPERTORY_JS_FORCE_VERSION = '1.3.0';
console.log(get_version());
expect(get_version()).toBe('1.3.0');
console.log(process.env);
});

View File

@@ -1,6 +1,5 @@
import Socket from 'net'; import Socket from 'net';
import package_json from '../../package.json'
import * as constants from '../utils/constants' import * as constants from '../utils/constants'
import packet from './packet'; import packet from './packet';
@@ -18,8 +17,8 @@ export default class connection {
} }
connected = false; connected = false;
host_or_ip = ""; host_or_ip = '';
password = ""; password = '';
port = 20000; port = 20000;
reject; reject;
resolve; resolve;
@@ -73,8 +72,12 @@ export default class connection {
const response = new packet(this.password); const response = new packet(this.password);
response.buffer = new Uint8Array(packet_data); response.buffer = new Uint8Array(packet_data);
response.decrypt() response.decrypt()
.then(() => {resolve(response)}) .then(() => {
.catch(e => {reject(e)}) resolve(response)
})
.catch(e => {
reject(e)
})
} }
} }
} }
@@ -120,11 +123,9 @@ export default class connection {
packet.token = this.password; packet.token = this.password;
packet.encode_top_utf8(method_name); packet.encode_top_utf8(method_name);
packet.encode_top_ui64(optional_thread_id || 1); packet.encode_top_ui64(optional_thread_id || 1);
packet.encode_top_utf8( packet.encode_top_utf8(constants.instance_id);
constants.instance_id ||
'c2e3da6656a9f5cd7b95f159687da459656738af7a6d0de533f526d67af14cac');
packet.encode_top_ui32(0); // Service flags packet.encode_top_ui32(0); // Service flags
packet.encode_top_utf8(package_json.version); packet.encode_top_utf8(constants.get_version());
await packet.encrypt(); await packet.encrypt();
packet.encode_top_ui32(packet.buffer.length); packet.encode_top_ui32(packet.buffer.length);
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {

View File

@@ -1,3 +1,6 @@
const {v4: uuidv4} = require('uuid'); const {v4: uuidv4} = require('uuid');
import _package_json from '../../package.json'
export const instance_id = uuidv4(); export const instance_id = uuidv4();
export const package_json = _package_json;
export const get_version = () => process.env.REPERTORY_JS_FORCE_VERSION || _package_json.version;