Update config format
All checks were successful
Lint / lint (20.x) (pull_request) Successful in 4m33s

This commit is contained in:
IshaVenikar 2025-01-30 11:40:54 +05:30
parent 8cef21d23c
commit d469e07eb1

View File

@ -265,7 +265,12 @@ export class Registry {
throw new Error(`No record found for ${lrn}`); throw new Error(`No record found for ${lrn}`);
} }
const envHash = await this.generateConfigHash(data.environmentVariables, data.requesterAddress, data.publicKey, data.apiUrl); const hash = await this.generateConfigHash(
data.environmentVariables,
data.requesterAddress,
data.publicKey,
data.apiUrl,
);
// Create record of type ApplicationDeploymentRequest and publish // Create record of type ApplicationDeploymentRequest and publish
const applicationDeploymentRequest = { const applicationDeploymentRequest = {
@ -277,7 +282,7 @@ export class Registry {
// https://git.vdb.to/cerc-io/laconic-registry-cli/commit/129019105dfb93bebcea02fde0ed64d0f8e5983b // https://git.vdb.to/cerc-io/laconic-registry-cli/commit/129019105dfb93bebcea02fde0ed64d0f8e5983b
config: JSON.stringify({ config: JSON.stringify({
ref: envHash ref: hash,
}), }),
meta: JSON.stringify({ meta: JSON.stringify({
note: `Added by Snowball @ ${DateTime.utc().toFormat( note: `Added by Snowball @ ${DateTime.utc().toFormat(
@ -539,37 +544,42 @@ export class Registry {
return `lrn://${this.registryConfig.authority}/applications/${appName}`; return `lrn://${this.registryConfig.authority}/applications/${appName}`;
} }
async generateConfigHash(environmentVariables: { [key: string]: string }, requesterAddress: 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 // Config to be encrypted
const config = { const config = {
"authorized": [requesterAddress], authorized: [requesterAddress],
"config": { "env": environmentVariables }, config: { env: environmentVariables },
} };
// Serialize the config (convert to YAML) // Serialize the config
const serialized = JSON.stringify(config, null, 2); 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 armoredKey = `-----BEGIN PGP PUBLIC KEY BLOCK-----\n\n${pubKey}\n\n-----END PGP PUBLIC KEY BLOCK-----`;
const publicKey = await openpgp.readKey({ armoredKey }); const publicKey = await openpgp.readKey({ armoredKey });
// Encrypt the config // Encrypt the config
const encrypted = await openpgp.encrypt({ const encrypted = await openpgp.encrypt({
message: await openpgp.createMessage({ text: serialized }), message: await openpgp.createMessage({ text: serialized }),
encryptionKeys: publicKey, encryptionKeys: publicKey,
format: 'binary' format: 'binary',
}); });
// Get the hash after uploading encrypted env // Get the hash after uploading encrypted config
const response = await fetch(`${url}/upload/config`, { const response = await fetch(`${url}/upload/config`, {
method: 'POST', method: 'POST',
headers: { headers: {
'Content-Type': 'application/octet-stream' 'Content-Type': 'application/octet-stream',
}, },
body: encrypted body: encrypted,
}); });
const envHash = await response.json(); const configHash = await response.json();
return envHash.id; return configHash.id;
}; }
} }