Add method to get hash for env
This commit is contained in:
parent
a1993f88d0
commit
c30753ce11
@ -23,7 +23,6 @@
|
||||
"express-session": "^1.18.0",
|
||||
"fs-extra": "^11.2.0",
|
||||
"graphql": "^16.8.1",
|
||||
"js-yaml": "^4.1.0",
|
||||
"luxon": "^3.4.4",
|
||||
"nanoid": "3",
|
||||
"nanoid-dictionary": "^5.0.0-beta.1",
|
||||
@ -55,7 +54,6 @@
|
||||
"@types/cookie-session": "^2.0.49",
|
||||
"@types/express-session": "^1.17.10",
|
||||
"@types/fs-extra": "^11.0.4",
|
||||
"@types/js-yaml": "^4.0.9",
|
||||
"better-sqlite3": "^9.2.2",
|
||||
"copyfiles": "^2.4.1",
|
||||
"prettier": "^3.1.1",
|
||||
|
@ -4,26 +4,26 @@ import { Project } from './Project';
|
||||
@Entity()
|
||||
export class Deployer {
|
||||
@PrimaryColumn('varchar')
|
||||
deployerLrn!: string;
|
||||
deployerLrn!: string;
|
||||
|
||||
@Column('varchar')
|
||||
deployerId!: string;
|
||||
deployerId!: string;
|
||||
|
||||
@Column('varchar')
|
||||
deployerApiUrl!: string;
|
||||
|
||||
@Column('varchar')
|
||||
baseDomain!: string;
|
||||
baseDomain!: string;
|
||||
|
||||
@Column('varchar', { nullable: true})
|
||||
publicKey!: string | null;
|
||||
publicKey!: string | null;
|
||||
|
||||
@Column('varchar', { nullable: true })
|
||||
minimumPayment!: string | null;
|
||||
minimumPayment!: string | null;
|
||||
|
||||
@Column('varchar', { nullable: true })
|
||||
paymentAddress!: string | null;
|
||||
paymentAddress!: string | null;
|
||||
|
||||
@ManyToMany(() => Project, (project) => project.deployers)
|
||||
projects!: Project[];
|
||||
projects!: Project[];
|
||||
}
|
||||
|
@ -36,9 +36,7 @@ export interface ApplicationDeploymentRequest {
|
||||
application: string;
|
||||
lrn?: string;
|
||||
auction?: string;
|
||||
config: {
|
||||
ref: string;
|
||||
};
|
||||
config: string;
|
||||
meta: string;
|
||||
payment?: string;
|
||||
}
|
||||
|
@ -5,7 +5,6 @@ import { Octokit } from 'octokit';
|
||||
import { inc as semverInc } from 'semver';
|
||||
import { DeepPartial } from 'typeorm';
|
||||
import * as openpgp from 'openpgp';
|
||||
import yaml from 'js-yaml';
|
||||
|
||||
import { Account, DEFAULT_GAS_ESTIMATION_MULTIPLIER, Registry as LaconicRegistry, getGasPrice, parseGasAndFees } from '@cerc-io/registry-sdk';
|
||||
import { DeliverTxResponse, IndexedTx } from '@cosmjs/stargate';
|
||||
@ -251,7 +250,7 @@ export class Registry {
|
||||
apiUrl: string,
|
||||
environmentVariables: { [key: string]: string },
|
||||
dns: string,
|
||||
address: string,
|
||||
requesterAddress: string,
|
||||
publicKey: string,
|
||||
payment?: string | null
|
||||
}): Promise<{
|
||||
@ -268,40 +267,14 @@ export class Registry {
|
||||
|
||||
// Config to be encrypted
|
||||
const config = {
|
||||
"authorized": [data.address],
|
||||
"authorized": [data.requesterAddress],
|
||||
"config": { "env": data.environmentVariables },
|
||||
}
|
||||
|
||||
const binaryKey = Buffer.from(data.publicKey, 'base64');
|
||||
|
||||
// Convert binary to ASCII-armored format
|
||||
const publicKeyArmored = `-----BEGIN PGP PUBLIC KEY BLOCK-----\n\n` +
|
||||
binaryKey.toString('base64').match(/.{1,64}/g)?.join('\n') +
|
||||
`\n\n-----END PGP PUBLIC KEY BLOCK-----`;
|
||||
|
||||
// Read the public key
|
||||
const publicKey = await openpgp.readKey({ armoredKey: publicKeyArmored });
|
||||
|
||||
// Serialize the config (convert to YAML)
|
||||
const serialized = JSON.stringify(config, null, 2); // Use YAML if needed
|
||||
const serialized = JSON.stringify(config, null, 2);
|
||||
|
||||
// Encrypt the config
|
||||
const encrypted = await openpgp.encrypt({
|
||||
message: await openpgp.createMessage({ text: serialized }),
|
||||
encryptionKeys: publicKey,
|
||||
format: 'binary' // Equivalent to armor=False
|
||||
});
|
||||
|
||||
// To get the hash after uploading encrypted env
|
||||
const response = await fetch(`${data.apiUrl}/upload/config`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/octet-stream'
|
||||
},
|
||||
body: encrypted
|
||||
});
|
||||
|
||||
const envHash = await response.json();
|
||||
const envHash = await this.generateHash(serialized, data.publicKey, data.apiUrl);
|
||||
|
||||
// Create record of type ApplicationDeploymentRequest and publish
|
||||
const applicationDeploymentRequest = {
|
||||
@ -312,7 +285,9 @@ export class Registry {
|
||||
dns: data.dns,
|
||||
|
||||
// https://git.vdb.to/cerc-io/laconic-registry-cli/commit/129019105dfb93bebcea02fde0ed64d0f8e5983b
|
||||
config: { ref: envHash },
|
||||
config: JSON.stringify({
|
||||
ref: envHash
|
||||
}),
|
||||
meta: JSON.stringify({
|
||||
note: `Added by Snowball @ ${DateTime.utc().toFormat(
|
||||
"EEE LLL dd HH:mm:ss 'UTC' yyyy"
|
||||
@ -572,4 +547,30 @@ export class Registry {
|
||||
assert(this.registryConfig.authority, "Authority doesn't exist");
|
||||
return `lrn://${this.registryConfig.authority}/applications/${appName}`;
|
||||
}
|
||||
|
||||
async generateHash(message: string, pubKey: string, url: string): Promise<string> {
|
||||
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 }),
|
||||
encryptionKeys: publicKey,
|
||||
format: 'binary'
|
||||
});
|
||||
|
||||
// Get the hash after uploading encrypted env
|
||||
const response = await fetch(`${url}/upload/config`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/octet-stream'
|
||||
},
|
||||
body: encrypted
|
||||
});
|
||||
|
||||
const envHash = await response.json();
|
||||
|
||||
return envHash;
|
||||
};
|
||||
}
|
||||
|
@ -658,7 +658,7 @@ export class Service {
|
||||
apiUrl: deployer!.deployerApiUrl!,
|
||||
payment: data.project.txHash,
|
||||
auctionId: data.project.auctionId,
|
||||
address,
|
||||
requesterAddress: address,
|
||||
publicKey: deployer!.publicKey!
|
||||
});
|
||||
}
|
||||
@ -674,7 +674,7 @@ export class Service {
|
||||
dns: `${newDeployment.project.name}-${newDeployment.id}`,
|
||||
payment: data.project.txHash,
|
||||
auctionId: data.project.auctionId,
|
||||
address,
|
||||
requesterAddress: address,
|
||||
publicKey: deployer!.publicKey!
|
||||
});
|
||||
|
||||
@ -743,7 +743,7 @@ export class Service {
|
||||
auctionId: project.auctionId!,
|
||||
lrn: deployerLrn,
|
||||
apiUrl: deployer!.deployerApiUrl!,
|
||||
address,
|
||||
requesterAddress: address,
|
||||
publicKey: deployer!.publicKey!
|
||||
});
|
||||
}
|
||||
@ -759,7 +759,7 @@ export class Service {
|
||||
apiUrl: deployer!.deployerApiUrl!,
|
||||
environmentVariables: environmentVariablesObj,
|
||||
dns: `${newDeployment.project.name}-${newDeployment.id}`,
|
||||
address,
|
||||
requesterAddress: address,
|
||||
publicKey: deployer!.publicKey!
|
||||
});
|
||||
|
||||
|
@ -6793,11 +6793,6 @@
|
||||
jest-matcher-utils "^27.0.0"
|
||||
pretty-format "^27.0.0"
|
||||
|
||||
"@types/js-yaml@^4.0.9":
|
||||
version "4.0.9"
|
||||
resolved "https://registry.yarnpkg.com/@types/js-yaml/-/js-yaml-4.0.9.tgz#cd82382c4f902fed9691a2ed79ec68c5898af4c2"
|
||||
integrity sha512-k4MGaQl5TGo/iipqb2UDG2UwjXziSWkh0uysQelTlJpX1qGlpUZYm8PnO4DxG1qBomtJUdYJ6qR6xdIah10JLg==
|
||||
|
||||
"@types/json-schema@^7.0.9":
|
||||
version "7.0.15"
|
||||
resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.15.tgz#596a1747233694d50f6ad8a7869fcb6f56cf5841"
|
||||
|
Loading…
Reference in New Issue
Block a user