@streamr/autocertifier-client
Advanced tools
Comparing version 100.0.0-testnet-one.4 to 100.0.0-testnet-three.0
@@ -61,55 +61,9 @@ "use strict"; | ||
class AutoCertifierClient extends eventemitter3_1.EventEmitter { | ||
updateTimeout; | ||
restClient; | ||
configFile; | ||
streamrWebSocketPort; | ||
ongoingSessions = new Set(); | ||
constructor(configFile, streamrWebSocketPort, restApiUrl, registerRpcMethod) { | ||
super(); | ||
this.ongoingSessions = new Set(); | ||
this.createCertificate = async () => { | ||
const dir = path_1.default.dirname(this.configFile); | ||
ensureConfigFileWritable(dir); | ||
const sessionId = await this.restClient.createSession(); | ||
let certifiedSubdomain; | ||
this.ongoingSessions.add(sessionId); | ||
try { | ||
certifiedSubdomain = await this.restClient.createSubdomainAndCertificate(this.streamrWebSocketPort, sessionId); | ||
} | ||
finally { | ||
this.ongoingSessions.delete(sessionId); | ||
} | ||
// TODO: use async fs methods? | ||
if (!fs_1.default.existsSync(dir)) { | ||
fs_1.default.mkdirSync(dir, { recursive: true }); | ||
} | ||
fs_1.default.writeFileSync(this.configFile, JSON.stringify(certifiedSubdomain)); | ||
const certObj = forge.pki.certificateFromPem(certifiedSubdomain.certificate); | ||
const expirationTimestamp = certObj.validity.notAfter.getTime(); | ||
this.scheduleCertificateUpdate(expirationTimestamp); | ||
this.emit('updatedCertificate', certifiedSubdomain); | ||
}; | ||
this.updateCertificate = async () => { | ||
const sessionId = await this.restClient.createSession(); | ||
this.ongoingSessions.add(sessionId); | ||
const oldCertifiedSubdomain = JSON.parse(fs_1.default.readFileSync(this.configFile, 'utf8')); | ||
const updatedCertifiedSubdomain = await this.restClient.updateCertificate(oldCertifiedSubdomain.fqdn.split('.')[0], this.streamrWebSocketPort, oldCertifiedSubdomain.authenticationToken, sessionId); | ||
this.ongoingSessions.delete(sessionId); | ||
// TODO: use async fs methods? | ||
fs_1.default.writeFileSync(this.configFile, JSON.stringify(updatedCertifiedSubdomain)); | ||
const certObj = forge.pki.certificateFromPem(updatedCertifiedSubdomain.certificate); | ||
const expirationTimestamp = certObj.validity.notAfter.getTime(); | ||
this.scheduleCertificateUpdate(expirationTimestamp); | ||
// TODO: if the certificate was not updated there's no need to emit the event. Could compare certificates? | ||
this.emit('updatedCertificate', updatedCertifiedSubdomain); | ||
}; | ||
// This method should be called whenever the IP address or port of the node changes | ||
this.updateSubdomainIp = async () => { | ||
if (!fs_1.default.existsSync(this.configFile)) { | ||
logger.warn('updateSubdomainIp() called while subdomain file does not exist'); | ||
return; | ||
} | ||
// TODO: use async fs methods? | ||
const oldSubdomain = JSON.parse(fs_1.default.readFileSync(this.configFile, 'utf8')); | ||
logger.info('updateSubdomainIp() called for ' + oldSubdomain.fqdn); | ||
const sessionId = await this.restClient.createSession(); | ||
this.ongoingSessions.add(sessionId); | ||
await this.restClient.updateSubdomainIp(oldSubdomain.fqdn.split('.')[0], this.streamrWebSocketPort, sessionId, oldSubdomain.authenticationToken); | ||
this.ongoingSessions.delete(sessionId); | ||
}; | ||
this.restClient = new RestClient_1.RestClient(restApiUrl); | ||
@@ -172,2 +126,52 @@ this.configFile = (0, utils_1.filePathToNodeFormat)(configFile); | ||
} | ||
createCertificate = async () => { | ||
const dir = path_1.default.dirname(this.configFile); | ||
ensureConfigFileWritable(dir); | ||
const sessionId = await this.restClient.createSession(); | ||
let certifiedSubdomain; | ||
this.ongoingSessions.add(sessionId); | ||
try { | ||
certifiedSubdomain = await this.restClient.createSubdomainAndCertificate(this.streamrWebSocketPort, sessionId); | ||
} | ||
finally { | ||
this.ongoingSessions.delete(sessionId); | ||
} | ||
// TODO: use async fs methods? | ||
if (!fs_1.default.existsSync(dir)) { | ||
fs_1.default.mkdirSync(dir, { recursive: true }); | ||
} | ||
fs_1.default.writeFileSync(this.configFile, JSON.stringify(certifiedSubdomain)); | ||
const certObj = forge.pki.certificateFromPem(certifiedSubdomain.certificate); | ||
const expirationTimestamp = certObj.validity.notAfter.getTime(); | ||
this.scheduleCertificateUpdate(expirationTimestamp); | ||
this.emit('updatedCertificate', certifiedSubdomain); | ||
}; | ||
updateCertificate = async () => { | ||
const sessionId = await this.restClient.createSession(); | ||
this.ongoingSessions.add(sessionId); | ||
const oldCertifiedSubdomain = JSON.parse(fs_1.default.readFileSync(this.configFile, 'utf8')); | ||
const updatedCertifiedSubdomain = await this.restClient.updateCertificate(oldCertifiedSubdomain.fqdn.split('.')[0], this.streamrWebSocketPort, oldCertifiedSubdomain.authenticationToken, sessionId); | ||
this.ongoingSessions.delete(sessionId); | ||
// TODO: use async fs methods? | ||
fs_1.default.writeFileSync(this.configFile, JSON.stringify(updatedCertifiedSubdomain)); | ||
const certObj = forge.pki.certificateFromPem(updatedCertifiedSubdomain.certificate); | ||
const expirationTimestamp = certObj.validity.notAfter.getTime(); | ||
this.scheduleCertificateUpdate(expirationTimestamp); | ||
// TODO: if the certificate was not updated there's no need to emit the event. Could compare certificates? | ||
this.emit('updatedCertificate', updatedCertifiedSubdomain); | ||
}; | ||
// This method should be called whenever the IP address or port of the node changes | ||
updateSubdomainIp = async () => { | ||
if (!fs_1.default.existsSync(this.configFile)) { | ||
logger.warn('updateSubdomainIp() called while subdomain file does not exist'); | ||
return; | ||
} | ||
// TODO: use async fs methods? | ||
const oldSubdomain = JSON.parse(fs_1.default.readFileSync(this.configFile, 'utf8')); | ||
logger.info('updateSubdomainIp() called for ' + oldSubdomain.fqdn); | ||
const sessionId = await this.restClient.createSession(); | ||
this.ongoingSessions.add(sessionId); | ||
await this.restClient.updateSubdomainIp(oldSubdomain.fqdn.split('.')[0], this.streamrWebSocketPort, sessionId, oldSubdomain.authenticationToken); | ||
this.ongoingSessions.delete(sessionId); | ||
}; | ||
// IAutoCertifierRpc implementation | ||
@@ -174,0 +178,0 @@ // TODO: could move to the DHT package or move all rpc related logic here from AutoCertifierClientFacade in DHT |
@@ -19,2 +19,6 @@ "use strict"; | ||
class Err extends Error { | ||
code; | ||
// TODO: could remove httpStatus since we already have a higher level error? | ||
httpStatus; | ||
originalError; | ||
constructor(code, httpStatus, message, originalError) { | ||
@@ -21,0 +25,0 @@ super(message); |
@@ -10,7 +10,8 @@ "use strict"; | ||
class AutoCertifierRpcClient { | ||
_transport; | ||
typeName = AutoCertifier_1.AutoCertifierRpc.typeName; | ||
methods = AutoCertifier_1.AutoCertifierRpc.methods; | ||
options = AutoCertifier_1.AutoCertifierRpc.options; | ||
constructor(_transport) { | ||
this._transport = _transport; | ||
this.typeName = AutoCertifier_1.AutoCertifierRpc.typeName; | ||
this.methods = AutoCertifier_1.AutoCertifierRpc.methods; | ||
this.options = AutoCertifier_1.AutoCertifierRpc.options; | ||
} | ||
@@ -17,0 +18,0 @@ /** |
@@ -13,2 +13,3 @@ "use strict"; | ||
class RestClient { | ||
baseUrl; | ||
constructor(baseUrl) { | ||
@@ -15,0 +16,0 @@ this.baseUrl = baseUrl; |
{ | ||
"name": "@streamr/autocertifier-client", | ||
"version": "100.0.0-testnet-one.4", | ||
"version": "100.0.0-testnet-three.0", | ||
"description": "Autocertifier Client for Streamr Network", | ||
@@ -24,3 +24,3 @@ "repository": { | ||
"@protobuf-ts/runtime-rpc": "^2.8.2", | ||
"@streamr/utils": "100.0.0-testnet-one.4", | ||
"@streamr/utils": "100.0.0-testnet-three.0", | ||
"eventemitter3": "^5.0.0", | ||
@@ -31,6 +31,5 @@ "node-forge": "^1.3.1", | ||
"devDependencies": { | ||
"@types/node-forge": "^1.3.5", | ||
"@types/request": "^2.48.8", | ||
"ts-node": "^10.9.1" | ||
"@types/node-forge": "^1.3.11", | ||
"@types/request": "^2.48.8" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
84594
2
1399
+ Added@streamr/utils@100.0.0-testnet-three.0(transitive)
- Removed@streamr/utils@100.0.0-testnet-one.4(transitive)