Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use download from @serverless/utils #9513

Merged
merged 1 commit into from
May 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/plugins/aws/invokeLocal/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const stdin = require('get-stdin');
const spawnExt = require('child-process-ext/spawn');
const { spawn } = require('child_process');
const inspect = require('util').inspect;
const download = require('download');
const download = require('@serverless/utils/download');
const { ensureDir } = require('fs-extra');
const cachedir = require('cachedir');
const decompress = require('decompress');
Expand Down
27 changes: 19 additions & 8 deletions lib/utils/downloadTemplateFromRepo.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const path = require('path');
const os = require('os');
const URL = require('url');
const download = require('download');
const download = require('@serverless/utils/download');
const BbPromise = require('bluebird');
const fse = require('fs-extra');
const qs = require('querystring');
Expand Down Expand Up @@ -81,7 +81,8 @@ function parseGitHubURL(url) {
downloadUrl,
isSubdirectory,
pathToDirectory: getPathDirectory(pathLength + 1, parts),
auth: url.auth || '',
username: url.username || '',
password: url.password || '',
};
}

Expand Down Expand Up @@ -111,7 +112,8 @@ function parseBitbucketURL(url) {
downloadUrl,
isSubdirectory,
pathToDirectory: getPathDirectory(pathLength + 1, parts),
auth: '',
username: url.username || '',
password: url.password || '',
};
}

Expand All @@ -134,7 +136,8 @@ function parseBitbucketServerURL(url) {
downloadUrl,
isSubdirectory,
pathToDirectory: getPathDirectory(pathLength + 1, parts),
auth: url.auth || '',
username: url.username || '',
password: url.password || '',
};
}

Expand Down Expand Up @@ -176,7 +179,8 @@ function parseGitlabURL(url) {
downloadUrl,
isSubdirectory,
pathToDirectory: getPathDirectory(pathLength + 1, parts),
auth: '',
username: url.username || '',
password: url.password || '',
};
}

Expand All @@ -197,7 +201,8 @@ function parsePlainGitURL(url) {
branch,
downloadUrl,
isSubdirectory,
auth: url.auth || '',
username: url.username || '',
password: url.password || '',
};
}

Expand All @@ -215,6 +220,11 @@ function parseRepoURL(inputUrl) {
}

const url = URL.parse(inputUrl.replace(/\/$/, ''));
if (url.auth) {
const [username, password] = url.auth.split(':');
url.username = username;
url.password = password;
}

// check if url parameter is a valid url
if (!url.host && !url.href.startsWith('git@')) {
Expand Down Expand Up @@ -259,7 +269,7 @@ function downloadTemplateFromRepo(inputUrl, templateName, downloadPath, options
let serviceName;
let dirName;
let downloadServicePath;
const { auth } = repoInformation;
const { username, password } = repoInformation;

if (repoInformation.isSubdirectory) {
const folderName = repoInformation.pathToDirectory.split('/').splice(-1)[0];
Expand Down Expand Up @@ -296,7 +306,8 @@ function downloadTemplateFromRepo(inputUrl, templateName, downloadPath, options
extract: true,
strip: 1,
mode: '755',
auth,
username,
password,
};
// download service
return download(repoInformation.downloadUrl, downloadServicePath, downloadOptions)
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
"dayjs": "^1.10.4",
"decompress": "^4.2.1",
"dotenv": "^9.0.2",
"download": "^8.0.0",
"essentials": "^1.1.1",
"fastest-levenshtein": "^1.0.12",
"filesize": "^6.3.0",
Expand Down
32 changes: 21 additions & 11 deletions test/unit/lib/utils/downloadTemplateFromRepo.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ describe('downloadTemplateFromRepo', () => {

return BbPromise.reject(Error('unknown server type'));
},
'download': downloadStub,
'@serverless/utils/download': downloadStub,
'child-process-ext/spawn': spawnStub,
}
);
Expand Down Expand Up @@ -262,7 +262,8 @@ describe('downloadTemplateFromRepo', () => {
downloadUrl: 'https://github.com/serverless/serverless/archive/master.zip',
isSubdirectory: false,
pathToDirectory: '',
auth: '',
username: '',
password: '',
});
}
);
Expand All @@ -279,7 +280,8 @@ describe('downloadTemplateFromRepo', () => {
downloadUrl: 'https://github.com/serverless/serverless/archive/master.zip',
isSubdirectory: true,
pathToDirectory: 'assets',
auth: '',
username: '',
password: '',
});
});
});
Expand All @@ -295,7 +297,8 @@ describe('downloadTemplateFromRepo', () => {
downloadUrl: 'https://github.mydomain.com/serverless/serverless/archive/master.zip',
isSubdirectory: false,
pathToDirectory: '',
auth: '',
username: '',
password: '',
});
});
});
Expand All @@ -311,7 +314,8 @@ describe('downloadTemplateFromRepo', () => {
downloadUrl: 'https://github.mydomain.com/serverless/serverless/archive/master.zip',
isSubdirectory: true,
pathToDirectory: 'assets',
auth: '',
username: '',
password: '',
});
});
});
Expand All @@ -326,7 +330,8 @@ describe('downloadTemplateFromRepo', () => {
branch: 'master',
downloadUrl: 'https://github.com/serverless/serverless/archive/master.zip',
isSubdirectory: false,
auth: 'username:password',
username: 'username',
password: 'password',
pathToDirectory: '',
});
});
Expand All @@ -341,7 +346,8 @@ describe('downloadTemplateFromRepo', () => {
downloadUrl: 'https://bitbucket.org/atlassian/localstack/get/master.zip',
isSubdirectory: false,
pathToDirectory: '',
auth: '',
username: '',
password: '',
});
});
});
Expand All @@ -357,7 +363,8 @@ describe('downloadTemplateFromRepo', () => {
downloadUrl: 'https://bitbucket.org/atlassian/localstack/get/mvn.zip',
isSubdirectory: true,
pathToDirectory: `localstack${path.sep}dashboard`,
auth: '',
username: '',
password: '',
});
});
});
Expand All @@ -374,7 +381,8 @@ describe('downloadTemplateFromRepo', () => {
'https://mybitbucket.server.ltd/rest/api/latest/projects/myproject/repos/myrepo/archive?at=refs%2Fheads%2Fdevelop&format=zip',
isSubdirectory: false,
pathToDirectory: '',
auth: 'user:pass',
username: 'user',
password: 'pass',
});
});
});
Expand All @@ -389,7 +397,8 @@ describe('downloadTemplateFromRepo', () => {
'https://gitlab.com/serverless/serverless/-/archive/master/serverless-master.zip',
isSubdirectory: false,
pathToDirectory: '',
auth: '',
username: '',
password: '',
});
});
});
Expand All @@ -405,7 +414,8 @@ describe('downloadTemplateFromRepo', () => {
'https://gitlab.com/serverless/serverless/-/archive/dev/serverless-dev.zip',
isSubdirectory: true,
pathToDirectory: 'subdir',
auth: '',
username: '',
password: '',
});
}
);
Expand Down