proxyca.js 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. // Generated by IcedCoffeeScript 1.7.1-c
  2. (function() {
  3. var E, ProxyCACert, ProxyCACerts, env, fs, iced, log, make_esc, __iced_k, __iced_k_noop, _pcc;
  4. iced = require('iced-runtime').iced;
  5. __iced_k = __iced_k_noop = function() {};
  6. env = require('./env').env;
  7. fs = require('fs');
  8. make_esc = require('iced-error').make_esc;
  9. E = require('./err').E;
  10. log = require('./log');
  11. ProxyCACert = (function() {
  12. function ProxyCACert(file) {
  13. this.file = file;
  14. }
  15. ProxyCACert.prototype.open = function(cb) {
  16. var err, ___iced_passed_deferral, __iced_deferrals, __iced_k;
  17. __iced_k = __iced_k_noop;
  18. ___iced_passed_deferral = iced.findDeferral(arguments);
  19. log.debug("| Load proxy CA: " + this.file);
  20. (function(_this) {
  21. return (function(__iced_k) {
  22. __iced_deferrals = new iced.Deferrals(__iced_k, {
  23. parent: ___iced_passed_deferral,
  24. filename: "/Users/max/src/keybase/node-client/src/proxyca.iced",
  25. funcname: "ProxyCACert.open"
  26. });
  27. fs.readFile(_this.file, __iced_deferrals.defer({
  28. assign_fn: (function(__slot_1) {
  29. return function() {
  30. err = arguments[0];
  31. return __slot_1.raw = arguments[1];
  32. };
  33. })(_this),
  34. lineno: 14
  35. }));
  36. __iced_deferrals._fulfill();
  37. });
  38. })(this)((function(_this) {
  39. return function() {
  40. return cb(err);
  41. };
  42. })(this));
  43. };
  44. ProxyCACert.prototype.to_string = function() {
  45. var _ref;
  46. return (_ref = this.raw) != null ? _ref.toString('utf8') : void 0;
  47. };
  48. return ProxyCACert;
  49. })();
  50. exports.ProxyCACerts = ProxyCACerts = (function() {
  51. function ProxyCACerts() {
  52. this._cas = [];
  53. this._arr = [];
  54. this._files = [];
  55. }
  56. ProxyCACerts.prototype.read_env = function(cb) {
  57. var e, err, o, v, _ref;
  58. o = env().get_proxy_ca_certs();
  59. v = null;
  60. err = null;
  61. if (o == null) {
  62. } else if (typeof o === 'string') {
  63. v = [o];
  64. } else if (typeof o === 'object' && Array.isArray(o)) {
  65. v = o;
  66. } else {
  67. err = new E.ArgsError("given CA list can't be parsed as list of files");
  68. }
  69. if (v != null) {
  70. this._files = (_ref = []).concat.apply(_ref, (function() {
  71. var _i, _len, _results;
  72. _results = [];
  73. for (_i = 0, _len = v.length; _i < _len; _i++) {
  74. e = v[_i];
  75. _results.push(e.split(/:/));
  76. }
  77. return _results;
  78. })());
  79. }
  80. return cb(err);
  81. };
  82. ProxyCACerts.prototype.open_files = function(cb) {
  83. var ca, esc, f, ___iced_passed_deferral, __iced_deferrals, __iced_k;
  84. __iced_k = __iced_k_noop;
  85. ___iced_passed_deferral = iced.findDeferral(arguments);
  86. esc = make_esc(cb, "CAs::open_files");
  87. this._cas = (function() {
  88. var _i, _len, _ref, _results;
  89. _ref = this._files;
  90. _results = [];
  91. for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  92. f = _ref[_i];
  93. _results.push(new ProxyCACert(f));
  94. }
  95. return _results;
  96. }).call(this);
  97. (function(_this) {
  98. return (function(__iced_k) {
  99. var _i, _len, _ref, _results, _while;
  100. _ref = _this._cas;
  101. _len = _ref.length;
  102. _i = 0;
  103. _results = [];
  104. _while = function(__iced_k) {
  105. var _break, _continue, _next;
  106. _break = function() {
  107. return __iced_k(_results);
  108. };
  109. _continue = function() {
  110. return iced.trampoline(function() {
  111. ++_i;
  112. return _while(__iced_k);
  113. });
  114. };
  115. _next = function(__iced_next_arg) {
  116. _results.push(__iced_next_arg);
  117. return _continue();
  118. };
  119. if (!(_i < _len)) {
  120. return _break();
  121. } else {
  122. ca = _ref[_i];
  123. (function(__iced_k) {
  124. __iced_deferrals = new iced.Deferrals(__iced_k, {
  125. parent: ___iced_passed_deferral,
  126. filename: "/Users/max/src/keybase/node-client/src/proxyca.iced",
  127. funcname: "ProxyCACerts.open_files"
  128. });
  129. ca.open(esc(__iced_deferrals.defer({
  130. lineno: 51
  131. })));
  132. __iced_deferrals._fulfill();
  133. })(_next);
  134. }
  135. };
  136. _while(__iced_k);
  137. });
  138. })(this)((function(_this) {
  139. return function() {
  140. return cb(null);
  141. };
  142. })(this));
  143. };
  144. ProxyCACerts.prototype.load = function(cb) {
  145. var c, esc, ___iced_passed_deferral, __iced_deferrals, __iced_k;
  146. __iced_k = __iced_k_noop;
  147. ___iced_passed_deferral = iced.findDeferral(arguments);
  148. log.debug("+ Load proxy CAs");
  149. esc = make_esc(cb, "CAs::init");
  150. (function(_this) {
  151. return (function(__iced_k) {
  152. __iced_deferrals = new iced.Deferrals(__iced_k, {
  153. parent: ___iced_passed_deferral,
  154. filename: "/Users/max/src/keybase/node-client/src/proxyca.iced",
  155. funcname: "ProxyCACerts.load"
  156. });
  157. _this.read_env(esc(__iced_deferrals.defer({
  158. lineno: 59
  159. })));
  160. __iced_deferrals._fulfill();
  161. });
  162. })(this)((function(_this) {
  163. return function() {
  164. (function(__iced_k) {
  165. __iced_deferrals = new iced.Deferrals(__iced_k, {
  166. parent: ___iced_passed_deferral,
  167. filename: "/Users/max/src/keybase/node-client/src/proxyca.iced",
  168. funcname: "ProxyCACerts.load"
  169. });
  170. _this.open_files(esc(__iced_deferrals.defer({
  171. lineno: 60
  172. })));
  173. __iced_deferrals._fulfill();
  174. })(function() {
  175. _this._ca_arr = (function() {
  176. var _i, _len, _ref, _results;
  177. _ref = this._cas;
  178. _results = [];
  179. for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  180. c = _ref[_i];
  181. _results.push(c.to_string());
  182. }
  183. return _results;
  184. }).call(_this);
  185. log.debug("- Loaded proxy CAs");
  186. return cb(null, _this._cas.length > 0);
  187. });
  188. };
  189. })(this));
  190. };
  191. ProxyCACerts.prototype.data = function() {
  192. return this._ca_arr;
  193. };
  194. ProxyCACerts.prototype.files = function() {
  195. return this._files;
  196. };
  197. return ProxyCACerts;
  198. })();
  199. _pcc = null;
  200. exports.init = function(cb) {
  201. var err, found, pcc, ___iced_passed_deferral, __iced_deferrals, __iced_k;
  202. __iced_k = __iced_k_noop;
  203. ___iced_passed_deferral = iced.findDeferral(arguments);
  204. pcc = new ProxyCACerts();
  205. (function(_this) {
  206. return (function(__iced_k) {
  207. __iced_deferrals = new iced.Deferrals(__iced_k, {
  208. parent: ___iced_passed_deferral,
  209. filename: "/Users/max/src/keybase/node-client/src/proxyca.iced",
  210. funcname: "init"
  211. });
  212. pcc.load(__iced_deferrals.defer({
  213. assign_fn: (function() {
  214. return function() {
  215. err = arguments[0];
  216. return found = arguments[1];
  217. };
  218. })(),
  219. lineno: 75
  220. }));
  221. __iced_deferrals._fulfill();
  222. });
  223. })(this)((function(_this) {
  224. return function() {
  225. if (found && (typeof err === "undefined" || err === null)) {
  226. _pcc = pcc;
  227. }
  228. return cb(err, _pcc);
  229. };
  230. })(this));
  231. };
  232. exports.get = function() {
  233. return _pcc;
  234. };
  235. }).call(this);