Skip to content

Commit 5bdd4c7

Browse files
committed
JBDS-4000 Introduce download-manager urls
1. Add dmUrl into requirements.json 2. Downloader uses dmUrl 3. Downloader calculates .sha256 urls for dmUrl 4. Tests fixes
1 parent 707a1e2 commit 5bdd4c7

11 files changed

Lines changed: 108 additions & 53 deletions

File tree

browser/main.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@ let mainModule =
9595
installerDataSvc,
9696
reqs['cygwin.exe'].url,
9797
null,
98-
'cygwin')
98+
'cygwin',
99+
reqs['cygwin.exe'].sha256sum)
99100
);
100101

101102
installerDataSvc.addItemToInstall(
@@ -113,18 +114,19 @@ let mainModule =
113114
new CDKInstall(
114115
installerDataSvc,
115116
$timeout,
116-
reqs['cdk.zip'].url,
117-
reqs['rhel-vagrant-virtualbox.box'].url,
117+
reqs['cdk.zip'].dmUrl,
118+
reqs['rhel-vagrant-virtualbox.box'].dmUrl,
118119
reqs['oc.zip'].url,
119120
null,
120-
'cdk')
121+
'cdk',
122+
reqs['oc.zip'].sha256sum)
121123
);
122124

123125
installerDataSvc.addItemToInstall(
124126
JdkInstall.key(),
125127
new JdkInstall(
126128
installerDataSvc,
127-
reqs['jdk.msi'].url,
129+
reqs['jdk.msi'].dmUrl,
128130
null,
129131
reqs['jdk.msi'].prefix,
130132
'jdk8')
@@ -134,7 +136,7 @@ let mainModule =
134136
JbdsInstall.key(),
135137
new JbdsInstall(
136138
installerDataSvc,
137-
reqs['jbds.jar'].url,
139+
reqs['jbds.jar'].dmUrl,
138140
null,
139141
'developer-studio')
140142
);

browser/model/cdk.js

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import Installer from './helpers/installer';
1414
import Util from './helpers/util.js';
1515

1616
class CDKInstall extends InstallableItem {
17-
constructor(installerDataSvc, $timeout, cdkUrl, cdkBoxUrl, ocUrl, installFile, targetFolderName) {
17+
constructor(installerDataSvc, $timeout, cdkUrl, cdkBoxUrl, ocUrl, installFile, targetFolderName, ocSha256) {
1818
super('cdk',
1919
900,
2020
cdkUrl,
@@ -25,6 +25,7 @@ class CDKInstall extends InstallableItem {
2525
this.$timeout = $timeout;
2626
this.cdkBoxUrl = cdkBoxUrl;
2727
this.ocUrl = ocUrl;
28+
this.ocSha256 = ocSha256;
2829

2930
this.cdkFileName = 'cdk.zip';
3031
this.cdkDownloadedFile = path.join(this.installerDataSvc.tempDir(), this.cdkFileName);
@@ -45,8 +46,8 @@ class CDKInstall extends InstallableItem {
4546
return 'cdk';
4647
}
4748

48-
49-
checkForExistingInstall() {
49+
detectExistingInstall(cb = new function(){}){
50+
cb();
5051
}
5152

5253
downloadInstaller(progress, success, failure) {
@@ -61,26 +62,16 @@ class CDKInstall extends InstallableItem {
6162
if(!fs.existsSync(path.join(this.downloadFolder, this.boxName))) {
6263
let cdkBoxWriteStream = fs.createWriteStream(this.cdkBoxDownloadedFile);
6364
this.downloader.setWriteStream(cdkBoxWriteStream);
64-
this.downloader.download(this.cdkBoxUrl);
65+
this.downloader.downloadAuth(this.cdkBoxUrl,username,password);
6566
} else {
6667
this.cdkBoxDownloadedFile = path.join(this.downloadFolder, this.boxName);
6768
this.downloader.closeHandler();
6869
}
6970

7071
if(!fs.existsSync(path.join(this.downloadFolder, this.cdkFileName))) {
71-
// TODO Switch back to auth download when CDK latest is in Customer Portal
72-
// downloader.downloadAuth
73-
// ({
74-
// url: this.cdkBoxUrl,
75-
// rejectUnauthorized: false
76-
// }, username, password);
7772
let cdkWriteStream = fs.createWriteStream(this.cdkDownloadedFile);
7873
this.downloader.setWriteStream(cdkWriteStream);
79-
this.downloader.downloadAuth
80-
({
81-
url: this.getDownloadUrl(),
82-
rejectUnauthorized: false
83-
}, username, password);
74+
this.downloader.downloadAuth(this.getDownloadUrl(), username, password);
8475
} else {
8576
this.cdkDownloadedFile = path.join(this.downloadFolder, this.cdkFileName);
8677
this.downloader.closeHandler();
@@ -89,7 +80,7 @@ class CDKInstall extends InstallableItem {
8980
if(!fs.existsSync(path.join(this.downloadFolder, this.ocFileName))) {
9081
let ocWriteStream = fs.createWriteStream(this.ocDownloadedFile);
9182
this.downloader.setWriteStream(ocWriteStream);
92-
this.downloader.download(this.ocUrl);
83+
this.downloader.download(this.ocUrl,this.ocDownloadedFile,this.ocSha256);
9384
} else {
9485
this.ocDownloadedFile = path.join(this.downloadFolder, this.ocFileName);
9586
this.downloader.closeHandler();

browser/model/cygwin.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import Util from './helpers/util';
1414

1515

1616
class CygwinInstall extends InstallableItem {
17-
constructor(installerDataSvc, downloadUrl, installFile, targetFolderName) {
17+
constructor(installerDataSvc, downloadUrl, installFile, targetFolderName, sha256) {
1818
super('cygwin',
1919
720,
2020
downloadUrl,
@@ -27,6 +27,7 @@ class CygwinInstall extends InstallableItem {
2727
this.downloadedFile = path.join(this.installerDataSvc.tempDir(), this.downloadedFileName);
2828
this.cygwinPathScript = path.join(this.installerDataSvc.tempDir(), 'set-cygwin-path.ps1');
2929
this.addOption('install',this.version,'',true);
30+
this.checksum = sha256;
3031
}
3132

3233
isSkipped() {
@@ -65,7 +66,7 @@ class CygwinInstall extends InstallableItem {
6566
let writeStream = fs.createWriteStream(this.downloadedFile);
6667
this.downloader = new Downloader(progress, success, failure);
6768
this.downloader.setWriteStream(writeStream);
68-
this.downloader.download(this.downloadUrl);
69+
this.downloader.download(this.downloadUrl,this.downloadedFile,this.checksum);
6970
} else {
7071
this.downloadedFile = this.bundledFile;
7172
success();

browser/model/helpers/downloader.js

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ let request = require('request');
44
let fs = require('fs-extra');
55

66
import Hash from './hash';
7-
7+
import Logger from '../../services/logger';
88
const remote = require('electron').remote;
99

1010
class Downloader {
@@ -61,14 +61,16 @@ class Downloader {
6161
stream.end();
6262
}
6363

64-
closeHandler(file,sha) {
64+
closeHandler(file,sha,url) {
6565
if(this.downloads.get(file) && this.downloads.get(file)['failure']) {
6666
return;
6767
}
6868
if(sha) {
69+
Logger.log(`Configured file='${file}' sha256='${sha}'`);
6970
var h = new Hash();
7071
h.SHA256(file,(dlSha) => {
7172
if(sha === dlSha) {
73+
Logger.log(`Downloaded file='${file}' sha256='${dlSha}'`);
7274
this.successHandler(file);
7375
} else {
7476
if(this.downloads.get(file)) {
@@ -77,6 +79,29 @@ class Downloader {
7779
this.failure('SHA256 checksum verification failed');
7880
}
7981
});
82+
} else if(url && url.includes("?workflow=direct")) {
83+
let shaUrl = url.replace("?workflow=direct",".sha256");
84+
Logger.log(`Downloading sha256 from ${shaUrl}`);
85+
request(this.setAdditionalOptions(shaUrl), (error, response, sha) => {
86+
if (!error && response.statusCode == 200) {
87+
Logger.log(`Downloaded sha256='${sha}'`);
88+
if(sha) {
89+
var h = new Hash();
90+
h.SHA256(file,(dlSha) => {
91+
Logger.log(`Downloaded file='${file}' sha256='${dlSha}'`);
92+
if(sha === dlSha) {
93+
this.successHandler(file);
94+
} else {
95+
this.downloads.get(file)['failure'] = true;
96+
this.failure(`Dowloaded file sha256 '${dlSha}' doesn't match sha256 '${sha}' from ${shaUrl}`);
97+
}
98+
});
99+
}
100+
} else {
101+
this.downloads.get(file)['failure'] = true;
102+
this.failure(`SHA256 checksum filr download from ${shaUrl} failed with ${error}`);
103+
}
104+
});
80105
} else {
81106
this.successHandler(file);
82107
}
@@ -100,7 +125,7 @@ class Downloader {
100125
.on('data', this.dataHandler.bind(this))
101126
.on('end', this.endHandler.bind(this, stream))
102127
.pipe(stream)
103-
.on('close', this.closeHandler.bind(this,stream.path,sha));
128+
.on('close', this.closeHandler.bind(this,stream.path,sha,options));
104129
}
105130

106131
downloadAuth(options, username, password, file, sha) {
@@ -113,7 +138,7 @@ class Downloader {
113138
.on('data', this.dataHandler.bind(this))
114139
.on('end', this.endHandler.bind(this, stream))
115140
.pipe(stream)
116-
.on('close', this.closeHandler.bind(this,stream.path,sha));
141+
.on('close', this.closeHandler.bind(this,stream.path,sha,options));
117142
}
118143

119144
restartDownload() {
@@ -146,6 +171,7 @@ class Downloader {
146171
'User-Agent': this.userAgentString
147172
};
148173
optionsObj['followAllRedirects'] = true;
174+
optionsObj['jar'] = request.jar();
149175
return optionsObj;
150176
}
151177
}

browser/model/jbds.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ class JbdsInstall extends InstallableItem {
4949
});
5050
}
5151

52+
detectExistingInstall(cb = new function(){}) {
53+
cb();
54+
}
55+
5256
checkForExistingInstall(selection, data) {
5357
let pattern, directory;
5458
let versionRegex = /version\s(\d+)\.\d+\.\d+/;
@@ -111,13 +115,15 @@ class JbdsInstall extends InstallableItem {
111115
}
112116

113117
downloadInstaller(progress, success, failure) {
118+
let username = this.installerDataSvc.getUsername(),
119+
password = this.installerDataSvc.getPassword();
114120
progress.setStatus('Downloading');
115121
if(!this.hasExistingInstall() && !fs.existsSync(this.bundledFile)) {
116122
// Need to download the file
117123
let writeStream = fs.createWriteStream(this.downloadedFile);
118124
this.downloader = new Downloader(progress, success, failure);
119125
this.downloader.setWriteStream(writeStream);
120-
this.downloader.download(this.downloadUrl);
126+
this.downloader.downloadAuth(this.downloadUrl,username,password);
121127
} else {
122128
this.downloadedFile = this.bundledFile;
123129
success();

browser/model/jdk-install.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,13 +115,15 @@ class JdkInstall extends InstallableItem {
115115
}
116116

117117
downloadInstaller(progress, success, failure) {
118+
let username = this.installerDataSvc.getUsername(),
119+
password = this.installerDataSvc.getPassword();
118120
progress.setStatus('Downloading');
119121
if(this.selectedOption == 'install' && !fs.existsSync(this.bundledFile)) {
120122
// Need to download the file
121123
let writeStream = fs.createWriteStream(this.downloadedFile);
122124
this.downloader = new Downloader(progress, success, failure);
123125
this.downloader.setWriteStream(writeStream);
124-
this.downloader.download(this.downloadUrl);
126+
this.downloader.downloadAuth(this.downloadUrl,username,password);
125127
} else {
126128
this.downloadedFile = this.bundledFile;
127129
success();

requirements.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"description": "Developer Tools for Creating, Testing, and Distributing Red Hat Container-Based Applications",
55
"bundle": "yes",
66
"version": "2.2",
7+
"dmUrl": "https://developers.redhat.com/download-manager/jdf/file/cdk-2.1.0.zip?workflow=direct",
78
"url": "http://cdk-builds.usersys.redhat.com/builds/weekly/12-Aug-2016.rc1/cdk.zip",
89
"filename": "cdk_2.2.0.RC5-20160812.zip",
910
"sha256sum": "50e15628d6c9dd4761dc5ec9fdd335ced1511b5ef5a95314be4ea9923af9de06",
@@ -15,6 +16,7 @@
1516
"description": "Developer Tools for Creating, Testing, and Distributing Red Hat Container-Based Applications",
1617
"bundle": "yes",
1718
"version": "7.2.10082016-1",
19+
"dmUrl": "https://developers.redhat.com/download-manager/jdf/file/rhel-cdk-kubernetes-7.2-25.x86_64.vagrant-virtualbox.box?workflow=direct",
1820
"url": "http://cdk-builds.usersys.redhat.com/builds/weekly/12-Aug-2016.rc1/rhel-cdk-kubernetes-7.2-27.x86_64.vagrant-virtualbox.box",
1921
"filename": "rhel-cdk-kubernetes-7.2-27.x86_64.vagrant-virtualbox.box",
2022
"sha256sum": "55f06138ecb04023e287b41a5353f630881be391621d6fae0cc0f6732134e564",
@@ -46,7 +48,8 @@
4648
"name": "Red Hat JBoss Developer Studio",
4749
"description": "A certified Eclipse-based integrated development environment (IDE)",
4850
"bundle": "yes",
49-
"version": "10.1.0.AM3",
51+
"version": "10.1.0.GA",
52+
"dmUrl": "https://developers.redhat.com/download-manager/jdf/file/devstudio-10.0.0.GA-installer-standalone.jar?workflow=direct",
5053
"url": "http://www.qa.jboss.com/binaries/RHDS/10.0/snapshots/builds/devstudio.product_master/latest/all/devstudio-10.1.0.latest-installer-standalone.jar",
5154
"filename": "devstudio-10.1.0.latest-installer-standalone.jar",
5255
"sha256sum": "http://www.qa.jboss.com/binaries/RHDS/10.0/snapshots/builds/devstudio.product_master/latest/all/devstudio-10.1.0.latest-installer-standalone.jar.sha256",
@@ -58,6 +61,7 @@
5861
"bundle": "yes",
5962
"version": "1.8.0.101",
6063
"prefix": "java-1.8.0-openjdk-1.8.0",
64+
"dmUrl": "https://developers.redhat.com/download-manager/jdf/file/java-1.8.0-openjdk-1.8.0.101-1-redhat.b13.windows.x86_64.msi?workflow=direct",
6165
"url": "http://download.eng.bos.redhat.com/brewroot/packages/openjdk8-win/8u101/1/win/java-1.8.0-openjdk-1.8.0.101-1-redhat.b13.windows.x86_64.msi",
6266
"filename": "java-1.8.0-openjdk-1.8.0.91-3-redhat.b14.windows.x86_64.zip",
6367
"sha256sum": "bcac53c6730dad19270210c24ebff767f3036db00c476b6712ff0bcf281626ff",

test/unit/model/cdk-test.js

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ describe('CDK installer', function() {
3535
cdkBoxDir: function() {},
3636
cdkMarker: function() {},
3737
cdkDir: function() {},
38-
getInstallable: function(key) {}
38+
getInstallable: function(key) {},
39+
getUsername: function() {},
40+
getPassword: function() {}
3941
};
4042
let fakeProgress = {
4143
setStatus: function (desc) { return; },
@@ -91,6 +93,12 @@ describe('CDK installer', function() {
9193
errorStub.restore();
9294
});
9395

96+
let reqs = require(path.resolve('./requirements.json'));
97+
98+
let cdkUrl = reqs['cdk.zip'].url,
99+
cdkBoxUrl = reqs['rhel-vagrant-virtualbox.box'].url,
100+
ocUrl = reqs['oc.zip'].url;
101+
94102
beforeEach(function () {
95103
installer = new CDKInstall(installerDataSvc, 900, cdkUrl, cdkBoxUrl, ocUrl, null);
96104
sandbox = sinon.sandbox.create();
@@ -121,12 +129,6 @@ describe('CDK installer', function() {
121129
expect(new CDKInstall(installerDataSvc, 900, 'cdkUrl', 'cdkBoxUrl', 'ocUrl', null).useDownload).to.be.true;
122130
});
123131

124-
let reqs = require(path.resolve('./requirements.json'));
125-
126-
let cdkUrl = reqs['cdk.zip'].url,
127-
cdkBoxUrl = reqs['rhel-vagrant-virtualbox.box'].url,
128-
ocUrl = reqs['oc.zip'].url;
129-
130132
describe('files download', function() {
131133
let downloadStub, authStub;
132134

@@ -159,21 +161,17 @@ describe('CDK installer', function() {
159161
});
160162

161163
it('should call a correct downloader request for each file', function() {
162-
let headers = {
163-
url: cdkUrl,
164-
rejectUnauthorized: false
165-
};
166164
installer = new CDKInstall(installerDataSvc, 900, cdkUrl, cdkBoxUrl, ocUrl, null);
167165
installer.downloadInstaller(fakeProgress, function() {}, function() {});
168166

169167
//we download 1 out of 4 files with authentication
170-
expect(downloadStub.callCount).to.equal(2);
171-
expect(authStub).to.have.been.calledOnce;
168+
expect(authStub.callCount).to.equal(2);
169+
expect(downloadStub).to.have.been.calledOnce;
172170

173-
expect(downloadStub).calledWith(cdkBoxUrl);
171+
expect(authStub).calledWith(cdkBoxUrl);
174172
expect(downloadStub).calledWith(ocUrl);
175173

176-
expect(authStub).calledWith(headers, installerDataSvc.getUsername(), installerDataSvc.getPassword());
174+
expect(authStub).calledWith(cdkUrl, installerDataSvc.getUsername(), installerDataSvc.getPassword());
177175
});
178176

179177
it('should skip download when the files are located in downloads folder', function() {

test/unit/model/helpers/downloader-test.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import sinon from 'sinon';
55
import { default as sinonChai } from 'sinon-chai';
66
import request from 'request';
77
import Downloader from 'model/helpers/downloader';
8+
import Logger from 'services/logger';
89
import { Readable, PassThrough, Writable } from 'stream';
910
import Hash from 'model/helpers/hash';
1011
chai.use(sinonChai);
@@ -22,6 +23,20 @@ describe('Downloader', function() {
2223
let sandbox;
2324
let succ = function() {};
2425
let fail = function() {};
26+
let infoStub, errorStub, logStub;
27+
28+
before(function() {
29+
infoStub = sinon.stub(Logger, 'info');
30+
errorStub = sinon.stub(Logger, 'error');
31+
logStub = sinon.stub(Logger, 'log');
32+
});
33+
34+
after(function() {
35+
infoStub.restore();
36+
errorStub.restore();
37+
logStub.restore();
38+
});
39+
2540

2641
beforeEach(function() {
2742
sandbox = sinon.sandbox.create();
@@ -102,7 +117,7 @@ describe('Downloader', function() {
102117
downloader = new Downloader(fakeProgress, function() {}, function() {});
103118
let stub = sandbox.stub(Hash.prototype, 'SHA256').yields('hash');
104119

105-
downloader.closeHandler('file', 'hash');
120+
downloader.closeHandler('file', 'hash', 'url');
106121

107122
expect(stub).to.have.been.calledOnce;
108123
expect(stub).to.have.been.calledWith('file');

0 commit comments

Comments
 (0)