1 | 'use strict';
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 | let fetchLatestMessageAdapterRelease = (() => {
|
10 | var _ref = _asyncToGenerator(function* (gitPath) {
|
11 | const url = process.env.GITHUB_TOKEN ? `https://api.github.com/repos/${gitPath}/releases/latest?access_token=${process.env.GITHUB_TOKEN}` : `https://api.github.com/repos/${gitPath}/releases/latest`;
|
12 |
|
13 | const response = yield got(url, {
|
14 | json: true,
|
15 | headers: {
|
16 | 'User-Agent': '@cumulus/deployment'
|
17 | }
|
18 | });
|
19 |
|
20 | return response.body.tag_name;
|
21 | });
|
22 |
|
23 | return function fetchLatestMessageAdapterRelease(_x) {
|
24 | return _ref.apply(this, arguments);
|
25 | };
|
26 | })();
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 | function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; }
|
38 |
|
39 | const fs = require('fs-extra');
|
40 | const http = require('@cumulus/common/http');
|
41 | const got = require('got');
|
42 | const extract = require('extract-zip');
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 |
|
51 | function downloadZipfile(fileUrl, localFilename) {
|
52 | return http.download(fileUrl, localFilename, {
|
53 | headers: {
|
54 | Accept: 'application/octet-stream',
|
55 | 'Content-Type': 'application/zip',
|
56 | 'Content-Transfer-Encoding': 'binary'
|
57 | }
|
58 | });
|
59 | }
|
60 |
|
61 |
|
62 |
|
63 |
|
64 |
|
65 |
|
66 |
|
67 |
|
68 | function extractZipFile(filename, dst) {
|
69 |
|
70 | fs.mkdirpSync(dst);
|
71 | return new Promise((resolve, reject) => {
|
72 | extract(filename, { dir: dst }, err => {
|
73 | if (err) return reject(err);
|
74 | console.log(`${filename} extracted to ${dst}`);
|
75 | return resolve(dst);
|
76 | });
|
77 | });
|
78 | }function messageAdapterVersion(version, gitPath) {
|
79 | if (version) {
|
80 | return Promise.resolve(version);
|
81 | }
|
82 | return fetchLatestMessageAdapterRelease(gitPath);
|
83 | }
|
84 |
|
85 |
|
86 |
|
87 |
|
88 |
|
89 |
|
90 |
|
91 |
|
92 |
|
93 | function messageAdapterUrl(version, gitPath, filename) {
|
94 | return messageAdapterVersion(version, gitPath).then(ver => process.env.GITHUB_TOKEN ? `https://github.com/${gitPath}/releases/download/${ver}/${filename}?access_token=${process.env.GITHUB_TOKEN}` : `https://github.com/${gitPath}/releases/download/${ver}/${filename}`);
|
95 | }
|
96 |
|
97 |
|
98 |
|
99 |
|
100 |
|
101 |
|
102 |
|
103 |
|
104 |
|
105 |
|
106 |
|
107 |
|
108 | function fetchMessageAdapter(version, gitPath, filename, src, dest) {
|
109 | return messageAdapterUrl(version, gitPath, filename).then(url => downloadZipfile(url, src)).then(() => extractZipFile(src, dest));
|
110 | }
|
111 |
|
112 | module.exports = {
|
113 | downloadZipfile,
|
114 | extractZipFile,
|
115 | fetchLatestMessageAdapterRelease,
|
116 | messageAdapterVersion,
|
117 | messageAdapterUrl,
|
118 | fetchMessageAdapter
|
119 | }; |
\ | No newline at end of file |