Refactor out code for config creation
All checks were successful
Lint / lint (20.x) (pull_request) Successful in 4m35s
All checks were successful
Lint / lint (20.x) (pull_request) Successful in 4m35s
This commit is contained in:
parent
c30753ce11
commit
2242e914c1
@ -265,16 +265,7 @@ export class Registry {
|
||||
throw new Error(`No record found for ${lrn}`);
|
||||
}
|
||||
|
||||
// Config to be encrypted
|
||||
const config = {
|
||||
"authorized": [data.requesterAddress],
|
||||
"config": { "env": data.environmentVariables },
|
||||
}
|
||||
|
||||
// Serialize the config (convert to YAML)
|
||||
const serialized = JSON.stringify(config, null, 2);
|
||||
|
||||
const envHash = await this.generateHash(serialized, data.publicKey, data.apiUrl);
|
||||
const envHash = await this.generateConfigHash(data.environmentVariables, data.requesterAddress, data.publicKey, data.apiUrl);
|
||||
|
||||
// Create record of type ApplicationDeploymentRequest and publish
|
||||
const applicationDeploymentRequest = {
|
||||
@ -548,14 +539,22 @@ export class Registry {
|
||||
return `lrn://${this.registryConfig.authority}/applications/${appName}`;
|
||||
}
|
||||
|
||||
async generateHash(message: string, pubKey: string, url: string): Promise<string> {
|
||||
async generateConfigHash(environmentVariables: { [key: string]: string }, requesterAddress: string, pubKey: string, url: string): Promise<string> {
|
||||
// Config to be encrypted
|
||||
const config = {
|
||||
"authorized": [requesterAddress],
|
||||
"config": { "env": environmentVariables },
|
||||
}
|
||||
|
||||
// Serialize the config (convert to YAML)
|
||||
const serialized = JSON.stringify(config, null, 2);
|
||||
const armoredKey = `-----BEGIN PGP PUBLIC KEY BLOCK-----\n\n${pubKey}\n\n-----END PGP PUBLIC KEY BLOCK-----`;
|
||||
|
||||
const publicKey = await openpgp.readKey({ armoredKey });
|
||||
|
||||
// Encrypt the config
|
||||
const encrypted = await openpgp.encrypt({
|
||||
message: await openpgp.createMessage({ text: message }),
|
||||
message: await openpgp.createMessage({ text: serialized }),
|
||||
encryptionKeys: publicKey,
|
||||
format: 'binary'
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user