screwdriver-api 8.0.182 → 8.0.184
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -83,10 +83,18 @@ module.exports = config => ({
|
|
|
83
83
|
const directoryArray = manifestArray.filter(f => f.startsWith(`./${artifact}/`));
|
|
84
84
|
let totalSize = 0;
|
|
85
85
|
|
|
86
|
+
// Manifest entries are build controlled, so encode them the same way
|
|
87
|
+
// single file requests are encoded. Appending them verbatim lets
|
|
88
|
+
// `..` segments be resolved away when the URL is normalized, which
|
|
89
|
+
// would point the request at another build's artifacts.
|
|
90
|
+
const fileUrl = file =>
|
|
91
|
+
`${baseUrl}/${encodeURIComponent(file.replace(/^\.\//, ''))}`
|
|
92
|
+
+ `?token=${token}&type=download`;
|
|
93
|
+
|
|
86
94
|
// Check file sizes by fetching metadata
|
|
87
95
|
for (const file of directoryArray) {
|
|
88
96
|
if (file) {
|
|
89
|
-
const fileMetaResponse = await request.head(
|
|
97
|
+
const fileMetaResponse = await request.head(fileUrl(file));
|
|
90
98
|
const fileSize = parseInt(fileMetaResponse.headers['content-length'], 10);
|
|
91
99
|
|
|
92
100
|
// Accumulate total size
|
|
@@ -120,7 +128,7 @@ module.exports = config => ({
|
|
|
120
128
|
// Fetch and append the directory files
|
|
121
129
|
for (const file of directoryArray) {
|
|
122
130
|
if (file) {
|
|
123
|
-
const fileStream = request.stream(
|
|
131
|
+
const fileStream = request.stream(fileUrl(file));
|
|
124
132
|
|
|
125
133
|
// Handle errors from file streaming
|
|
126
134
|
fileStream.on('error', (err) => {
|
|
@@ -92,7 +92,12 @@ module.exports = config => ({
|
|
|
92
92
|
try {
|
|
93
93
|
for (const file of manifestArray) {
|
|
94
94
|
if (file) {
|
|
95
|
-
|
|
95
|
+
// Manifest entries are build controlled, so encode them before
|
|
96
|
+
// appending. Verbatim entries let `..` segments be resolved away
|
|
97
|
+
// when the URL is normalized, which would point the request at
|
|
98
|
+
// another build's artifacts.
|
|
99
|
+
const encodedFile = encodeURIComponent(file.replace(/^\.\//, ''));
|
|
100
|
+
const fileStream = request.stream(`${baseUrl}/${encodedFile}?token=${token}&type=download`);
|
|
96
101
|
|
|
97
102
|
fileStream.on('error', (err) => {
|
|
98
103
|
logger.error(`Error downloading file: ${file}`, err);
|
|
@@ -27,7 +27,16 @@ server.register({
|
|
|
27
27
|
### Routes
|
|
28
28
|
|
|
29
29
|
#### Returns an access token to talk to coverage server
|
|
30
|
-
`GET /coverage/token?
|
|
30
|
+
`GET /coverage/token?projectKey=job:123`
|
|
31
|
+
|
|
32
|
+
`scope`, `projectName`, and `username` are not accepted as query parameters — all three are always resolved
|
|
33
|
+
server-side from the build's own JWT-verified identity. `projectKey` is rejected with a `403` unless it
|
|
34
|
+
names a project the calling build is authorized for (its own pipeline, its own job, or its PR parent job)
|
|
35
|
+
**and** matches the build's own resolved coverage scope.
|
|
36
|
+
|
|
37
|
+
> **Deployment order:** requires `screwdriver-coverage-sonar` ≥6.0.0
|
|
38
|
+
> ([coverage-sonar#80](https://github.com/screwdriver-cd/coverage-sonar/pull/80)). This API change must be
|
|
39
|
+
> deployed *before* that dependency is bumped — see that PR's README for why.
|
|
31
40
|
|
|
32
41
|
#### Get an object with coverage info
|
|
33
42
|
|
|
@@ -22,26 +22,20 @@ module.exports = config => ({
|
|
|
22
22
|
const { jobFactory, pipelineFactory } = request.server.app;
|
|
23
23
|
const buildCredentials = request.auth.credentials;
|
|
24
24
|
const { jobId, pipelineId } = buildCredentials;
|
|
25
|
-
const {
|
|
25
|
+
const { projectKey, selfSonarHost, selfSonarAdminToken } = request.query;
|
|
26
|
+
// `scope`, `projectName`, and `username` are deliberately not read from the query. The coverage
|
|
27
|
+
// plugin derives all three from records resolved below via the build's own JWT-verified ids, so
|
|
28
|
+
// a build cannot override which Sonar project or scope its token/Git App binding applies to.
|
|
26
29
|
const tokenConfig = {
|
|
27
|
-
buildCredentials
|
|
28
|
-
scope
|
|
30
|
+
buildCredentials
|
|
29
31
|
};
|
|
30
32
|
|
|
31
33
|
if (projectKey) {
|
|
32
34
|
tokenConfig.projectKey = projectKey;
|
|
33
35
|
}
|
|
34
36
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
if (username) {
|
|
40
|
-
tokenConfig.username = username;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
// Get scope and job name
|
|
44
|
-
if (jobId && !scope) {
|
|
37
|
+
// Get scope and job name; always resolved here so neither can be supplied by the caller
|
|
38
|
+
if (jobId) {
|
|
45
39
|
const job = await jobFactory.get(jobId);
|
|
46
40
|
|
|
47
41
|
if (!job) {
|
|
@@ -49,6 +43,13 @@ module.exports = config => ({
|
|
|
49
43
|
}
|
|
50
44
|
|
|
51
45
|
tokenConfig.jobName = job.name;
|
|
46
|
+
// Invariant this rejection below relies on: screwdriver-cd/launcher's coverage/info call
|
|
47
|
+
// (launch.go, GetCoverageInfo) reads this exact field/index -
|
|
48
|
+
// job.Permutations[0].Annotations.CoverageScope - and always sends it as `scope`, empty
|
|
49
|
+
// string when absent, never omitted (screwdriver.go's CoverageURL has no projectKey param
|
|
50
|
+
// at all). So the scope screwdriver-coverage-sonar resolved when it minted
|
|
51
|
+
// SD_SONAR_PROJECT_KEY and the annotation re-read here cannot disagree for a real build,
|
|
52
|
+
// short of a pipeline sync rewriting this annotation between build start and this request.
|
|
52
53
|
tokenConfig.scope =
|
|
53
54
|
job.permutations[0] && job.permutations[0].annotations
|
|
54
55
|
? job.permutations[0].annotations[COVERAGE_SCOPE_ANNOTATION]
|
|
@@ -56,8 +57,8 @@ module.exports = config => ({
|
|
|
56
57
|
}
|
|
57
58
|
let pipeline;
|
|
58
59
|
|
|
59
|
-
// Get pipeline name
|
|
60
|
-
if (pipelineId
|
|
60
|
+
// Get pipeline name; always resolved here so it can never be supplied by the caller
|
|
61
|
+
if (pipelineId) {
|
|
61
62
|
pipeline = await pipelineFactory.get(pipelineId);
|
|
62
63
|
|
|
63
64
|
if (!pipeline) {
|
|
@@ -91,12 +92,6 @@ module.exports = config => ({
|
|
|
91
92
|
const data = await config.coveragePlugin.getAccessToken(tokenConfig);
|
|
92
93
|
const { projectUrl } = config.coveragePlugin.getProjectData(tokenConfig);
|
|
93
94
|
|
|
94
|
-
if (!pipeline && pipelineId) {
|
|
95
|
-
pipeline = await pipelineFactory.get(pipelineId);
|
|
96
|
-
|
|
97
|
-
logger.info(`looking up again, pipeline:${pipelineId}, and found pipeline: ${pipeline}`);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
95
|
if (pipeline && projectUrl) {
|
|
101
96
|
try {
|
|
102
97
|
const pipelineSonarBadge = {
|