From: Ian Jackson Date: Sun, 2 May 2021 01:03:03 +0000 (+0100) Subject: bundles: Initial list-bundles X-Git-Tag: otter-0.6.0~474 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=153f08ce21e34baaf35602dd6f784c4a4f8d1ae1;p=otter.git bundles: Initial list-bundles Signed-off-by: Ian Jackson --- diff --git a/daemon/cmdlistener.rs b/daemon/cmdlistener.rs index b437201d..5873b979 100644 --- a/daemon/cmdlistener.rs +++ b/daemon/cmdlistener.rs @@ -62,6 +62,13 @@ enum PermissionCheckHow { type PCH = PermissionCheckHow; +pub const TP_ACCESS_BUNDLES: &[TP] = &[ + TP::ViewNotSecret, + TP::Play, + TP::ChangePieces, + TP::UploadBundles, +]; + // ========== management API ========== // ---------- management command implementations @@ -235,6 +242,16 @@ fn execute_and_respond(cs: &mut CommandStreamData, cmd: MgmtCommand, }; Fine } + MC::ListBundles { game } => { + let ag = AccountsGuard::lock(); + let gref = Instance::lookup_by_name_unauth(&game)?; + let bundles = gref.lock_bundles(); + let mut igu = gref.lock()?; + let (_ig, auth) = cs.check_acl(&ag, &mut igu, PCH::Instance, + TP_ACCESS_BUNDLES)?; + let bundles = bundles.by(auth); + MR::Bundles(bundles.list()) + } MC::ListGames { all } => { let ag = AccountsGuard::lock(); diff --git a/src/bin/otter.rs b/src/bin/otter.rs index 48907cea..f27fc961 100644 --- a/src/bin/otter.rs +++ b/src/bin/otter.rs @@ -1362,6 +1362,47 @@ mod upload_bundle { )} } +//---------- list-bundle ---------- + +mod list_bundles { + use super::*; + + #[derive(Default,Debug)] + struct Args { + table_name: String, + } + + fn subargs(sa: &mut Args) -> ArgumentParser { + use argparse::*; + let mut ap = ArgumentParser::new(); + ap.refer(&mut sa.table_name).required() + .add_argument("TABLE-NAME",Store,"table name"); + ap + } + + #[throws(AE)] + fn call(_sc: &Subcommand, ma: MainOpts, args: Vec) { + let args = parse_args::(args, &subargs, &ok_id, None); + let instance_name = ma.instance_name(&args.table_name); + let mut chan = access_game(&ma, &args.table_name)?; + let resp = chan.cmd(&MC::ListBundles { + game: instance_name.clone(), + })?; + if_let!{ MR::Bundles(bundles) = resp; + else throw!(anyhow!("unexpected {:?}", &resp)) }; + for (index, note) in bundles.into_iter().enumerate() { + if_let!{ Some(note) = note; else continue; } + println!("{:05} {:?}", index, ¬e); + } + } + + inventory::submit!{Subcommand( + "list-bundles", + "List bundles", + call, + )} +} + //---------- list-accounts ---------- mod list_accounts { diff --git a/src/bundles.rs b/src/bundles.rs index 0739692e..9e86f35b 100644 --- a/src/bundles.rs +++ b/src/bundles.rs @@ -31,23 +31,25 @@ pub struct InstanceBundles { bundles: Vec>, } -#[derive(Debug,Clone)] -struct Note { - kind: Kind, - state: State, +pub type MgmtList = Vec>; + +#[derive(Debug,Clone,Serialize,Deserialize)] +pub struct Note { + pub kind: Kind, + pub state: State, } type BadBundle = String; // todo: make this a newtype -#[derive(Debug,Clone)] -enum State { +#[derive(Debug,Clone,Serialize,Deserialize)] +pub enum State { Uploading, BadBundle(BadBundle), Loaded(Loaded), } -#[derive(Debug,Clone)] -struct Loaded { +#[derive(Debug,Clone,Serialize,Deserialize)] +pub struct Loaded { meta: BundleMeta, } @@ -147,6 +149,8 @@ fn incorporate_bundle(ib: &mut InstanceBundles, ig: &mut Instance, impl InstanceBundles { pub fn new() -> Self { InstanceBundles{ bundles: default() } } + pub fn list(&self) -> MgmtList { self.bundles.clone() } + #[throws(IE)] pub fn load_game_bundles(ig: &mut Instance) -> Self { let bd = b_dir(&ig.name); diff --git a/src/commands.rs b/src/commands.rs index 2d06892e..6f1205ee 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -46,10 +46,10 @@ pub enum MgmtCommand { hash: bundles::Hash, kind: bundles::Kind, }, - /* ListBundles { game: InstanceName, }, + /* DownloadBundle { game: InstanceName, index: bundles::Index, @@ -92,6 +92,7 @@ pub enum MgmtResponse { AccountsList(Vec>), GamesList(Vec>), LibraryItems(Vec), + Bundles(bundles::MgmtList), } #[derive(Debug,Serialize,Deserialize)] diff --git a/src/mgmtchannel.rs b/src/mgmtchannel.rs index 04e7474a..58a890ea 100644 --- a/src/mgmtchannel.rs +++ b/src/mgmtchannel.rs @@ -80,7 +80,8 @@ impl MgmtChannel { wbulk.finish().context("finish sending command and data")?; let (resp, mut rbulk)= self.read.read_withbulk().context("read response")?; match &resp { - Fine | AccountsList{..} | GamesList{..} | LibraryItems(_) => { }, + Fine | AccountsList{..} | GamesList{..} | + LibraryItems(_) | Bundles(..) => { }, AlterGame { error: None, .. } => { }, Error { error } => { Err(error.clone()).context(