Skip to content

Commit e189873

Browse files
lukekarryswraithgar
authored andcommitted
deps: @sigstore/sign@2.3.1
1 parent c2b28f9 commit e189873

File tree

8 files changed

+170
-130
lines changed

8 files changed

+170
-130
lines changed

DEPENDENCIES.md

+2
Original file line numberDiff line numberDiff line change
@@ -737,6 +737,8 @@ graph LR;
737737
sigstore-->sigstore-verify["@sigstore/verify"];
738738
sigstore-bundle-->sigstore-protobuf-specs["@sigstore/protobuf-specs"];
739739
sigstore-sign-->make-fetch-happen;
740+
sigstore-sign-->proc-log;
741+
sigstore-sign-->promise-retry;
740742
sigstore-sign-->sigstore-bundle["@sigstore/bundle"];
741743
sigstore-sign-->sigstore-core["@sigstore/core"];
742744
sigstore-sign-->sigstore-protobuf-specs["@sigstore/protobuf-specs"];
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,21 @@
11
"use strict";
2+
/*
3+
Copyright 2023 The Sigstore Authors.
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
*/
217
Object.defineProperty(exports, "__esModule", { value: true });
3-
exports.checkStatus = exports.HTTPError = void 0;
18+
exports.HTTPError = void 0;
419
class HTTPError extends Error {
520
constructor({ status, message, location, }) {
621
super(`(${status}) ${message}`);
@@ -9,30 +24,3 @@ class HTTPError extends Error {
924
}
1025
}
1126
exports.HTTPError = HTTPError;
12-
const checkStatus = async (response) => {
13-
if (response.ok) {
14-
return response;
15-
}
16-
else {
17-
let message = response.statusText;
18-
const location = response.headers?.get('Location') || undefined;
19-
const contentType = response.headers?.get('Content-Type');
20-
// If response type is JSON, try to parse the body for a message
21-
if (contentType?.includes('application/json')) {
22-
try {
23-
await response.json().then((body) => {
24-
message = body.message;
25-
});
26-
}
27-
catch (e) {
28-
// ignore
29-
}
30-
}
31-
throw new HTTPError({
32-
status: response.status,
33-
message: message,
34-
location: location,
35-
});
36-
}
37-
};
38-
exports.checkStatus = checkStatus;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
"use strict";
2+
var __importDefault = (this && this.__importDefault) || function (mod) {
3+
return (mod && mod.__esModule) ? mod : { "default": mod };
4+
};
5+
Object.defineProperty(exports, "__esModule", { value: true });
6+
exports.fetchWithRetry = void 0;
7+
/*
8+
Copyright 2023 The Sigstore Authors.
9+
10+
Licensed under the Apache License, Version 2.0 (the "License");
11+
you may not use this file except in compliance with the License.
12+
You may obtain a copy of the License at
13+
14+
http://www.apache.org/licenses/LICENSE-2.0
15+
16+
Unless required by applicable law or agreed to in writing, software
17+
distributed under the License is distributed on an "AS IS" BASIS,
18+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19+
See the License for the specific language governing permissions and
20+
limitations under the License.
21+
*/
22+
const http2_1 = require("http2");
23+
const make_fetch_happen_1 = __importDefault(require("make-fetch-happen"));
24+
const proc_log_1 = require("proc-log");
25+
const promise_retry_1 = __importDefault(require("promise-retry"));
26+
const util_1 = require("../util");
27+
const error_1 = require("./error");
28+
const { HTTP2_HEADER_LOCATION, HTTP2_HEADER_CONTENT_TYPE, HTTP2_HEADER_USER_AGENT, HTTP_STATUS_INTERNAL_SERVER_ERROR, HTTP_STATUS_TOO_MANY_REQUESTS, HTTP_STATUS_REQUEST_TIMEOUT, } = http2_1.constants;
29+
async function fetchWithRetry(url, options) {
30+
return (0, promise_retry_1.default)(async (retry, attemptNum) => {
31+
const method = options.method || 'POST';
32+
const headers = {
33+
[HTTP2_HEADER_USER_AGENT]: util_1.ua.getUserAgent(),
34+
...options.headers,
35+
};
36+
const response = await (0, make_fetch_happen_1.default)(url, {
37+
method,
38+
headers,
39+
body: options.body,
40+
timeout: options.timeout,
41+
retry: false, // We're handling retries ourselves
42+
}).catch((reason) => {
43+
proc_log_1.log.http('fetch', `${method} ${url} attempt ${attemptNum} failed with ${reason}`);
44+
return retry(reason);
45+
});
46+
if (response.ok) {
47+
return response;
48+
}
49+
else {
50+
const error = await errorFromResponse(response);
51+
proc_log_1.log.http('fetch', `${method} ${url} attempt ${attemptNum} failed with ${response.status}`);
52+
if (retryable(response.status)) {
53+
return retry(error);
54+
}
55+
else {
56+
throw error;
57+
}
58+
}
59+
}, retryOpts(options.retry));
60+
}
61+
exports.fetchWithRetry = fetchWithRetry;
62+
// Translate a Response into an HTTPError instance. This will attempt to parse
63+
// the response body for a message, but will default to the statusText if none
64+
// is found.
65+
const errorFromResponse = async (response) => {
66+
let message = response.statusText;
67+
const location = response.headers?.get(HTTP2_HEADER_LOCATION) || undefined;
68+
const contentType = response.headers?.get(HTTP2_HEADER_CONTENT_TYPE);
69+
// If response type is JSON, try to parse the body for a message
70+
if (contentType?.includes('application/json')) {
71+
try {
72+
const body = await response.json();
73+
message = body.message || message;
74+
}
75+
catch (e) {
76+
// ignore
77+
}
78+
}
79+
return new error_1.HTTPError({
80+
status: response.status,
81+
message: message,
82+
location: location,
83+
});
84+
};
85+
// Determine if a status code is retryable. This includes 5xx errors, 408, and
86+
// 429.
87+
const retryable = (status) => [HTTP_STATUS_REQUEST_TIMEOUT, HTTP_STATUS_TOO_MANY_REQUESTS].includes(status) || status >= HTTP_STATUS_INTERNAL_SERVER_ERROR;
88+
// Normalize the retry options to the format expected by promise-retry
89+
const retryOpts = (retry) => {
90+
if (typeof retry === 'boolean') {
91+
return { retries: retry ? 1 : 0 };
92+
}
93+
else if (typeof retry === 'number') {
94+
return { retries: retry };
95+
}
96+
else {
97+
return { retries: 0, ...retry };
98+
}
99+
};
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
"use strict";
2-
var __importDefault = (this && this.__importDefault) || function (mod) {
3-
return (mod && mod.__esModule) ? mod : { "default": mod };
4-
};
52
Object.defineProperty(exports, "__esModule", { value: true });
63
exports.Fulcio = void 0;
74
/*
@@ -19,33 +16,26 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1916
See the License for the specific language governing permissions and
2017
limitations under the License.
2118
*/
22-
const make_fetch_happen_1 = __importDefault(require("make-fetch-happen"));
23-
const util_1 = require("../util");
24-
const error_1 = require("./error");
19+
const fetch_1 = require("./fetch");
2520
/**
2621
* Fulcio API client.
2722
*/
2823
class Fulcio {
2924
constructor(options) {
30-
this.fetch = make_fetch_happen_1.default.defaults({
31-
retry: options.retry,
32-
timeout: options.timeout,
25+
this.options = options;
26+
}
27+
async createSigningCertificate(request) {
28+
const { baseURL, retry, timeout } = this.options;
29+
const url = `${baseURL}/api/v2/signingCert`;
30+
const response = await (0, fetch_1.fetchWithRetry)(url, {
3331
headers: {
3432
'Content-Type': 'application/json',
35-
'User-Agent': util_1.ua.getUserAgent(),
3633
},
37-
});
38-
this.baseUrl = options.baseURL;
39-
}
40-
async createSigningCertificate(request) {
41-
const url = `${this.baseUrl}/api/v2/signingCert`;
42-
const response = await this.fetch(url, {
43-
method: 'POST',
4434
body: JSON.stringify(request),
35+
timeout,
36+
retry,
4537
});
46-
await (0, error_1.checkStatus)(response);
47-
const data = await response.json();
48-
return data;
38+
return response.json();
4939
}
5040
}
5141
exports.Fulcio = Fulcio;

node_modules/@sigstore/sign/dist/external/rekor.js

+21-56
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
"use strict";
2-
var __importDefault = (this && this.__importDefault) || function (mod) {
3-
return (mod && mod.__esModule) ? mod : { "default": mod };
4-
};
52
Object.defineProperty(exports, "__esModule", { value: true });
63
exports.Rekor = void 0;
74
/*
@@ -19,37 +16,31 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1916
See the License for the specific language governing permissions and
2017
limitations under the License.
2118
*/
22-
const make_fetch_happen_1 = __importDefault(require("make-fetch-happen"));
23-
const util_1 = require("../util");
24-
const error_1 = require("./error");
19+
const fetch_1 = require("./fetch");
2520
/**
2621
* Rekor API client.
2722
*/
2823
class Rekor {
2924
constructor(options) {
30-
this.fetch = make_fetch_happen_1.default.defaults({
31-
retry: options.retry,
32-
timeout: options.timeout,
33-
headers: {
34-
Accept: 'application/json',
35-
'User-Agent': util_1.ua.getUserAgent(),
36-
},
37-
});
38-
this.baseUrl = options.baseURL;
25+
this.options = options;
3926
}
4027
/**
4128
* Create a new entry in the Rekor log.
4229
* @param propsedEntry {ProposedEntry} Data to create a new entry
4330
* @returns {Promise<Entry>} The created entry
4431
*/
4532
async createEntry(propsedEntry) {
46-
const url = `${this.baseUrl}/api/v1/log/entries`;
47-
const response = await this.fetch(url, {
48-
method: 'POST',
49-
headers: { 'Content-Type': 'application/json' },
33+
const { baseURL, timeout, retry } = this.options;
34+
const url = `${baseURL}/api/v1/log/entries`;
35+
const response = await (0, fetch_1.fetchWithRetry)(url, {
36+
headers: {
37+
'Content-Type': 'application/json',
38+
Accept: 'application/json',
39+
},
5040
body: JSON.stringify(propsedEntry),
41+
timeout,
42+
retry,
5143
});
52-
await (0, error_1.checkStatus)(response);
5344
const data = await response.json();
5445
return entryFromResponse(data);
5546
}
@@ -59,44 +50,18 @@ class Rekor {
5950
* @returns {Promise<Entry>} The retrieved entry
6051
*/
6152
async getEntry(uuid) {
62-
const url = `${this.baseUrl}/api/v1/log/entries/${uuid}`;
63-
const response = await this.fetch(url);
64-
await (0, error_1.checkStatus)(response);
65-
const data = await response.json();
66-
return entryFromResponse(data);
67-
}
68-
/**
69-
* Search the Rekor log index for entries matching the given query.
70-
* @param opts {SearchIndex} Options to search the Rekor log
71-
* @returns {Promise<string[]>} UUIDs of matching entries
72-
*/
73-
async searchIndex(opts) {
74-
const url = `${this.baseUrl}/api/v1/index/retrieve`;
75-
const response = await this.fetch(url, {
76-
method: 'POST',
77-
body: JSON.stringify(opts),
78-
headers: { 'Content-Type': 'application/json' },
53+
const { baseURL, timeout, retry } = this.options;
54+
const url = `${baseURL}/api/v1/log/entries/${uuid}`;
55+
const response = await (0, fetch_1.fetchWithRetry)(url, {
56+
method: 'GET',
57+
headers: {
58+
Accept: 'application/json',
59+
},
60+
timeout,
61+
retry,
7962
});
80-
await (0, error_1.checkStatus)(response);
8163
const data = await response.json();
82-
return data;
83-
}
84-
/**
85-
* Search the Rekor logs for matching the given query.
86-
* @param opts {SearchLogQuery} Query to search the Rekor log
87-
* @returns {Promise<Entry[]>} List of matching entries
88-
*/
89-
async searchLog(opts) {
90-
const url = `${this.baseUrl}/api/v1/log/entries/retrieve`;
91-
const response = await this.fetch(url, {
92-
method: 'POST',
93-
body: JSON.stringify(opts),
94-
headers: { 'Content-Type': 'application/json' },
95-
});
96-
await (0, error_1.checkStatus)(response);
97-
const rawData = await response.json();
98-
const data = rawData.map((d) => entryFromResponse(d));
99-
return data;
64+
return entryFromResponse(data);
10065
}
10166
}
10267
exports.Rekor = Rekor;

node_modules/@sigstore/sign/dist/external/tsa.js

+9-18
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
"use strict";
2-
var __importDefault = (this && this.__importDefault) || function (mod) {
3-
return (mod && mod.__esModule) ? mod : { "default": mod };
4-
};
52
Object.defineProperty(exports, "__esModule", { value: true });
63
exports.TimestampAuthority = void 0;
74
/*
@@ -19,28 +16,22 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1916
See the License for the specific language governing permissions and
2017
limitations under the License.
2118
*/
22-
const make_fetch_happen_1 = __importDefault(require("make-fetch-happen"));
23-
const util_1 = require("../util");
24-
const error_1 = require("./error");
19+
const fetch_1 = require("./fetch");
2520
class TimestampAuthority {
2621
constructor(options) {
27-
this.fetch = make_fetch_happen_1.default.defaults({
28-
retry: options.retry,
29-
timeout: options.timeout,
22+
this.options = options;
23+
}
24+
async createTimestamp(request) {
25+
const { baseURL, timeout, retry } = this.options;
26+
const url = `${baseURL}/api/v1/timestamp`;
27+
const response = await (0, fetch_1.fetchWithRetry)(url, {
3028
headers: {
3129
'Content-Type': 'application/json',
32-
'User-Agent': util_1.ua.getUserAgent(),
3330
},
34-
});
35-
this.baseUrl = options.baseURL;
36-
}
37-
async createTimestamp(request) {
38-
const url = `${this.baseUrl}/api/v1/timestamp`;
39-
const response = await this.fetch(url, {
40-
method: 'POST',
4131
body: JSON.stringify(request),
32+
timeout,
33+
retry,
4234
});
43-
await (0, error_1.checkStatus)(response);
4435
return response.buffer();
4536
}
4637
}

0 commit comments

Comments
 (0)