type PCH = PermissionCheckHow;
+pub const TP_ACCESS_BUNDLES: &[TP] = &[
+ TP::ViewNotSecret,
+ TP::Play,
+ TP::ChangePieces,
+ TP::UploadBundles,
+];
+
// ========== management API ==========
// ---------- management command implementations
};
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();
)}
}
+//---------- 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<String>) {
+ let args = parse_args::<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 {
bundles: Vec<Option<Note>>,
}
-#[derive(Debug,Clone)]
-struct Note {
- kind: Kind,
- state: State,
+pub type MgmtList = Vec<Option<Note>>;
+
+#[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,
}
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);
hash: bundles::Hash,
kind: bundles::Kind,
},
- /*
ListBundles {
game: InstanceName,
},
+ /*
DownloadBundle {
game: InstanceName,
index: bundles::Index,
AccountsList(Vec<Arc<AccountName>>),
GamesList(Vec<Arc<InstanceName>>),
LibraryItems(Vec<shapelib::ItemEnquiryData>),
+ Bundles(bundles::MgmtList),
}
#[derive(Debug,Serialize,Deserialize)]
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(