list_signatures.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  1. // Generated by IcedCoffeeScript 1.7.1-c
  2. (function() {
  3. var Base, Command, E, LinkTable, ST, User, add_option_dict, constants, env, format_fingerprint, iced, log, make_esc, session, tablify, timeago, util, __iced_k, __iced_k_noop,
  4. __hasProp = {}.hasOwnProperty,
  5. __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
  6. iced = require('iced-runtime').iced;
  7. __iced_k = __iced_k_noop = function() {};
  8. Base = require('./base').Base;
  9. log = require('../log');
  10. add_option_dict = require('./argparse').add_option_dict;
  11. session = require('../session').session;
  12. make_esc = require('iced-error').make_esc;
  13. env = require('../env').env;
  14. log = require('../log');
  15. User = require('../user').User;
  16. format_fingerprint = require('pgp-utils').util.format_fingerprint;
  17. util = require('util');
  18. E = require('../err').E;
  19. constants = require('../constants').constants;
  20. ST = constants.signature_types;
  21. tablify = require('tablify').tablify;
  22. timeago = require('timeago');
  23. LinkTable = require('../chainlink').LinkTable;
  24. exports.Command = Command = (function(_super) {
  25. __extends(Command, _super);
  26. function Command() {
  27. return Command.__super__.constructor.apply(this, arguments);
  28. }
  29. Command.prototype.OPTS = {
  30. r: {
  31. alias: 'revoked',
  32. action: 'storeTrue',
  33. help: 'show revoked signatures too'
  34. },
  35. v: {
  36. alias: 'verbose',
  37. action: 'storeTrue',
  38. help: 'a full dump, with more gory details'
  39. },
  40. j: {
  41. alias: 'json',
  42. action: 'storeTrue',
  43. help: 'output in json format; default is simple text list'
  44. },
  45. t: {
  46. alias: 'type',
  47. action: "append",
  48. help: 'the type of signatures to output; choose from ["track","proof","currency","self"]; all by default'
  49. }
  50. };
  51. Command.prototype.use_session = function() {
  52. return true;
  53. };
  54. Command.prototype.needs_configuration = function() {
  55. return true;
  56. };
  57. Command.prototype.TYPES = {
  58. track: ST.TRACK,
  59. proof: ST.REMOTE_PROOF,
  60. currency: ST.CRYPTOCURRENCY,
  61. self: ST.SELF_SIG
  62. };
  63. Command.prototype.add_subcommand_parser = function(scp) {
  64. var name, opts, sub;
  65. opts = {
  66. help: "list of your non-revoked signatures",
  67. aliases: ["list-sigs"]
  68. };
  69. name = "list-signatures";
  70. sub = scp.addParser(name, opts);
  71. sub.addArgument(["filter"], {
  72. nargs: '?',
  73. help: "a regex to filter by"
  74. });
  75. add_option_dict(sub, this.OPTS);
  76. return [name].concat(opts.aliases);
  77. };
  78. Command.prototype.display_json = function(list) {
  79. return JSON.stringify(list, null, " ");
  80. };
  81. Command.prototype.display = function(list) {
  82. if (this.argv.json) {
  83. return this.display_json(list);
  84. } else {
  85. return this.display_text(list);
  86. }
  87. };
  88. Command.prototype.display_text_line = function(k, v) {
  89. var fields, p, proofs, _i, _len, _ref;
  90. fields = [k];
  91. if (this.argv.verbose) {
  92. fields.push(v.key, v.ctime);
  93. proofs = [];
  94. _ref = v.proofs;
  95. for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  96. p = _ref[_i];
  97. if ((p.name != null) && (p.username != null)) {
  98. proofs.push("" + p.name + ":" + p.username);
  99. }
  100. }
  101. proofs.sort();
  102. fields = fields.concat(proofs);
  103. }
  104. return fields.join("\t");
  105. };
  106. Command.prototype.display_text = function(list) {
  107. var ctime, id, live, payload, row, rows, seqno, type;
  108. rows = (function() {
  109. var _i, _len, _ref, _results;
  110. _results = [];
  111. for (_i = 0, _len = list.length; _i < _len; _i++) {
  112. _ref = list[_i], seqno = _ref.seqno, id = _ref.id, type = _ref.type, ctime = _ref.ctime, live = _ref.live, payload = _ref.payload;
  113. row = [seqno, (this.argv.verbose ? id : id.slice(0, 9) + "..."), type, timeago(new Date(ctime * 1000))];
  114. if (this.argv.revoked) {
  115. row.push((live ? "+" : "-"));
  116. }
  117. row.push((typeof payload === 'string' ? payload : JSON.stringify(payload)));
  118. _results.push(row);
  119. }
  120. return _results;
  121. }).call(this);
  122. return tablify(rows, {
  123. row_start: ' ',
  124. row_end: '',
  125. spacer: ' ',
  126. row_sep_char: ''
  127. });
  128. };
  129. Command.prototype.filter_list = function(d) {
  130. var cd, k, out, proof, rps, v, _i, _len, _ref, _ref1, _ref2, _ref3, _ref4;
  131. if (this.filter_rxx != null) {
  132. out = {};
  133. for (k in d) {
  134. v = d[k];
  135. if (k.match(this.filter_rxx)) {
  136. out[k] = v;
  137. } else if ((rps = (_ref = v.body) != null ? (_ref1 = _ref.track) != null ? _ref1.remote_proofs : void 0 : void 0) != null) {
  138. for (_i = 0, _len = rps.length; _i < _len; _i++) {
  139. proof = rps[_i];
  140. if ((cd = proof != null ? (_ref2 = proof.remote_key_proof) != null ? _ref2.check_data_json : void 0 : void 0) != null) {
  141. if (((_ref3 = cd.username) != null ? _ref3.match(this.filter_rxx) : void 0) || ((_ref4 = cd.hostname) != null ? _ref4.match(this.filter_rxx) : void 0)) {
  142. out[k] = v;
  143. break;
  144. }
  145. }
  146. }
  147. }
  148. }
  149. d = out;
  150. }
  151. return d;
  152. };
  153. Command.prototype.parse_types = function(cb) {
  154. var err, k, t, types, _i, _len, _ref;
  155. types = null;
  156. err = null;
  157. if (this.argv.type != null) {
  158. _ref = this.argv.type;
  159. for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  160. t = _ref[_i];
  161. if ((k = this.TYPES[t]) == null) {
  162. err = new E.ArgsError("Bad signature type specified: " + t);
  163. break;
  164. }
  165. types || (types = []);
  166. types.push(k);
  167. }
  168. if (err == null) {
  169. this.types = types;
  170. }
  171. }
  172. return cb(err);
  173. };
  174. Command.prototype.parse_args = function(cb) {
  175. var esc, ___iced_passed_deferral, __iced_deferrals, __iced_k;
  176. __iced_k = __iced_k_noop;
  177. ___iced_passed_deferral = iced.findDeferral(arguments);
  178. esc = make_esc(cb, "Command::parse_args");
  179. (function(_this) {
  180. return (function(__iced_k) {
  181. __iced_deferrals = new iced.Deferrals(__iced_k, {
  182. parent: ___iced_passed_deferral,
  183. filename: "/home/max/src/keybase/node-client/src/command/list_signatures.iced",
  184. funcname: "Command.parse_args"
  185. });
  186. _this.parse_filter(esc(__iced_deferrals.defer({
  187. lineno: 146
  188. })));
  189. __iced_deferrals._fulfill();
  190. });
  191. })(this)((function(_this) {
  192. return function() {
  193. (function(__iced_k) {
  194. __iced_deferrals = new iced.Deferrals(__iced_k, {
  195. parent: ___iced_passed_deferral,
  196. filename: "/home/max/src/keybase/node-client/src/command/list_signatures.iced",
  197. funcname: "Command.parse_args"
  198. });
  199. _this.parse_types(esc(__iced_deferrals.defer({
  200. lineno: 147
  201. })));
  202. __iced_deferrals._fulfill();
  203. })(function() {
  204. return cb(null);
  205. });
  206. };
  207. })(this));
  208. };
  209. Command.prototype.parse_filter = function(cb) {
  210. var e, err, f;
  211. err = null;
  212. this.filter_rxx = null;
  213. if (((f = this.argv.filter) != null) && f.length) {
  214. try {
  215. this.filter_rxx = new RegExp(f, "i");
  216. } catch (_error) {
  217. e = _error;
  218. err = new E.ArgsError("Bad regex specified: " + e.message);
  219. }
  220. }
  221. return cb(err);
  222. };
  223. Command.prototype.select_sigs = function(me) {
  224. var tab;
  225. if ((tab = me.sig_chain.table) == null) {
  226. tab = new LinkTable();
  227. } else if (this.types != null) {
  228. tab = tab.select(this.types);
  229. }
  230. return tab;
  231. };
  232. Command.prototype.filter_sigs = function(tab) {
  233. if (this.filter_rxx != null) {
  234. return tab.prune((function(_this) {
  235. return function(obj) {
  236. return !(obj.matches(_this.filter_rxx));
  237. };
  238. })(this));
  239. }
  240. };
  241. Command.prototype.list_sigs = function(tab) {
  242. var list, p;
  243. return list = (function() {
  244. var _i, _len, _ref, _results;
  245. _ref = tab.flatten();
  246. _results = [];
  247. for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  248. p = _ref[_i];
  249. _results.push(p.summary());
  250. }
  251. return _results;
  252. })();
  253. };
  254. Command.prototype.sort_sigs = function(list) {
  255. return list.sort(function(a, b) {
  256. return a.seqno - b.seqno;
  257. });
  258. };
  259. Command.prototype.process_sigs = function(me) {
  260. var list, tab;
  261. tab = this.select_sigs(me);
  262. this.filter_sigs(tab);
  263. list = this.list_sigs(tab);
  264. this.sort_sigs(list);
  265. return list;
  266. };
  267. Command.prototype.run = function(cb) {
  268. var esc, list, logged_in, me, un, verify_opts, ___iced_passed_deferral, __iced_deferrals, __iced_k;
  269. __iced_k = __iced_k_noop;
  270. ___iced_passed_deferral = iced.findDeferral(arguments);
  271. esc = make_esc(cb, "Command::run");
  272. (function(_this) {
  273. return (function(__iced_k) {
  274. __iced_deferrals = new iced.Deferrals(__iced_k, {
  275. parent: ___iced_passed_deferral,
  276. filename: "/home/max/src/keybase/node-client/src/command/list_signatures.iced",
  277. funcname: "Command.run"
  278. });
  279. _this.parse_args(esc(__iced_deferrals.defer({
  280. lineno: 198
  281. })));
  282. __iced_deferrals._fulfill();
  283. });
  284. })(this)((function(_this) {
  285. return function() {
  286. (function(__iced_k) {
  287. if ((un = env().get_username()) != null) {
  288. (function(__iced_k) {
  289. __iced_deferrals = new iced.Deferrals(__iced_k, {
  290. parent: ___iced_passed_deferral,
  291. filename: "/home/max/src/keybase/node-client/src/command/list_signatures.iced",
  292. funcname: "Command.run"
  293. });
  294. session.check(esc(__iced_deferrals.defer({
  295. assign_fn: (function() {
  296. return function() {
  297. return logged_in = arguments[0];
  298. };
  299. })(),
  300. lineno: 200
  301. })));
  302. __iced_deferrals._fulfill();
  303. })(function() {
  304. verify_opts = {
  305. show_revoked: _this.argv.revoked,
  306. show_perm_failures: true
  307. };
  308. (function(__iced_k) {
  309. __iced_deferrals = new iced.Deferrals(__iced_k, {
  310. parent: ___iced_passed_deferral,
  311. filename: "/home/max/src/keybase/node-client/src/command/list_signatures.iced",
  312. funcname: "Command.run"
  313. });
  314. User.load_me({
  315. secret: false,
  316. verify_opts: verify_opts
  317. }, esc(__iced_deferrals.defer({
  318. assign_fn: (function() {
  319. return function() {
  320. return me = arguments[0];
  321. };
  322. })(),
  323. lineno: 202
  324. })));
  325. __iced_deferrals._fulfill();
  326. })(function() {
  327. list = _this.process_sigs(me);
  328. list = _this.display(list);
  329. return __iced_k(list.length ? log.console.log(list) : void 0);
  330. });
  331. });
  332. } else {
  333. return __iced_k(log.warn("Not logged in"));
  334. }
  335. })(function() {
  336. return cb(null);
  337. });
  338. };
  339. })(this));
  340. };
  341. return Command;
  342. })(Base);
  343. }).call(this);