diff --git a/packages/backend/src/entity/Deployment.ts b/packages/backend/src/entity/Deployment.ts index 8e0a324..655e6d7 100644 --- a/packages/backend/src/entity/Deployment.ts +++ b/packages/backend/src/entity/Deployment.ts @@ -35,6 +35,12 @@ export interface ApplicationDeploymentRequest { meta: string; } +export interface ApplicationDeploymentRemovalRequest { + type: string; + version: string; + deployment: string; +} + export interface ApplicationRecord { type: string; version: string; diff --git a/packages/backend/src/registry.ts b/packages/backend/src/registry.ts index ed30af9..71091f1 100644 --- a/packages/backend/src/registry.ts +++ b/packages/backend/src/registry.ts @@ -9,7 +9,8 @@ import { RegistryConfig } from './config'; import { ApplicationRecord, Deployment, - ApplicationDeploymentRequest + ApplicationDeploymentRequest, + ApplicationDeploymentRemovalRequest } from './entity/Deployment'; import { AppDeploymentRecord, PackageJSON } from './types'; import { sleep } from './utils'; @@ -18,6 +19,7 @@ const log = debug('snowball:registry'); const APP_RECORD_TYPE = 'ApplicationRecord'; const APP_DEPLOYMENT_REQUEST_TYPE = 'ApplicationDeploymentRequest'; +const APP_DEPLOYMENT_REMOVAL_REQUEST_TYPE = 'ApplicationDeploymentRemovalRequest'; const APP_DEPLOYMENT_RECORD_TYPE = 'ApplicationDeploymentRecord'; const SLEEP_DURATION = 1000; @@ -229,6 +231,37 @@ export class Registry { ); } + async createApplicationDeploymentRemovalRequest (data: { + deployment: Deployment + }): Promise<{ + applicationDeploymentRemovalRequestId: string; + applicationDeploymentRemovalRequestData: ApplicationDeploymentRemovalRequest; + }> { + const applicationDeploymentRemovalRequest = { + type: APP_DEPLOYMENT_REMOVAL_REQUEST_TYPE, + version: '1.0.0', + deployment: data.deployment.id + }; + + const result = await this.registry.setRecord( + { + privateKey: this.registryConfig.privateKey, + record: applicationDeploymentRemovalRequest, + bondId: this.registryConfig.bondId + }, + '', + this.registryConfig.fee + ); + + log(`Application deployment removal request record published: ${result.data.id}`); + log('Application deployment removal request data:', applicationDeploymentRemovalRequest); + + return { + applicationDeploymentRemovalRequestId: result.data.id, + applicationDeploymentRemovalRequestData: applicationDeploymentRemovalRequest + }; + } + getCrn (appName: string): string { assert(this.registryConfig.authority, "Authority doesn't exist"); return `crn://${this.registryConfig.authority}/applications/${appName}`;