add marketplace_url to backup metadata for service (#1688)

This commit is contained in:
Aiden McClelland
2022-07-25 12:43:40 -06:00
committed by GitHub
parent 61da050fe8
commit bdb906bf26
2 changed files with 25 additions and 4 deletions

View File

@@ -366,6 +366,7 @@ async fn perform_backup<Db: DbHandle>(
.backup .backup
.create( .create(
ctx, ctx,
&mut tx,
&package_id, &package_id,
&manifest.title, &manifest.title,
&manifest.version, &manifest.version,

View File

@@ -5,6 +5,7 @@ use chrono::{DateTime, Utc};
use color_eyre::eyre::eyre; use color_eyre::eyre::eyre;
use helpers::AtomicFile; use helpers::AtomicFile;
use patch_db::{DbHandle, HasModel, LockType}; use patch_db::{DbHandle, HasModel, LockType};
use reqwest::Url;
use rpc_toolkit::command; use rpc_toolkit::command;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use sqlx::{Executor, Sqlite}; use sqlx::{Executor, Sqlite};
@@ -61,6 +62,7 @@ pub fn package_backup() -> Result<(), Error> {
struct BackupMetadata { struct BackupMetadata {
pub timestamp: DateTime<Utc>, pub timestamp: DateTime<Utc>,
pub tor_keys: BTreeMap<InterfaceId, String>, pub tor_keys: BTreeMap<InterfaceId, String>,
pub marketplace_url: Option<Url>,
} }
#[derive(Clone, Debug, Deserialize, Serialize, HasModel)] #[derive(Clone, Debug, Deserialize, Serialize, HasModel)]
@@ -84,10 +86,11 @@ impl BackupActions {
Ok(()) Ok(())
} }
#[instrument(skip(ctx))] #[instrument(skip(ctx, db))]
pub async fn create( pub async fn create<Db: DbHandle>(
&self, &self,
ctx: &RpcContext, ctx: &RpcContext,
db: &mut Db,
pkg_id: &PackageId, pkg_id: &PackageId,
pkg_title: &str, pkg_title: &str,
pkg_version: &Version, pkg_version: &Version,
@@ -125,6 +128,18 @@ impl BackupActions {
) )
}) })
.collect(); .collect();
let marketplace_url = crate::db::DatabaseModel::new()
.package_data()
.idx_model(pkg_id)
.expect(db)
.await?
.installed()
.expect(db)
.await?
.marketplace_url()
.get(db, true)
.await?
.into_owned();
let tmp_path = Path::new(BACKUP_DIR) let tmp_path = Path::new(BACKUP_DIR)
.join(pkg_id) .join(pkg_id)
.join(format!("{}.s9pk", pkg_id)); .join(format!("{}.s9pk", pkg_id));
@@ -156,6 +171,7 @@ impl BackupActions {
.write_all(&IoFormat::Cbor.to_vec(&BackupMetadata { .write_all(&IoFormat::Cbor.to_vec(&BackupMetadata {
timestamp, timestamp,
tor_keys, tor_keys,
marketplace_url,
})?) })?)
.await?; .await?;
outfile.save().await.with_kind(ErrorKind::Filesystem)?; outfile.save().await.with_kind(ErrorKind::Filesystem)?;
@@ -227,17 +243,21 @@ impl BackupActions {
.package_data() .package_data()
.lock(db, LockType::Write) .lock(db, LockType::Write)
.await?; .await?;
crate::db::DatabaseModel::new() let pde = crate::db::DatabaseModel::new()
.package_data() .package_data()
.idx_model(pkg_id) .idx_model(pkg_id)
.expect(db) .expect(db)
.await? .await?
.installed() .installed()
.expect(db) .expect(db)
.await? .await?;
pde.clone()
.interface_addresses() .interface_addresses()
.put(db, &interfaces.install(&mut *secrets, pkg_id).await?) .put(db, &interfaces.install(&mut *secrets, pkg_id).await?)
.await?; .await?;
pde.marketplace_url()
.put(db, &metadata.marketplace_url)
.await?;
let entry = crate::db::DatabaseModel::new() let entry = crate::db::DatabaseModel::new()
.package_data() .package_data()