Skip to content

Commit 279e891

Browse files
authored
Merge pull request actions#1790 from actions/bdehamer/attest-headers
support for headers param in attest functions
2 parents 50f2977 + 340a103 commit 279e891

File tree

7 files changed

+26
-6
lines changed

7 files changed

+26
-6
lines changed

packages/attest/README.md

+4
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ export type AttestOptions = {
6363
// Sigstore instance to use for signing. Must be one of "public-good" or
6464
// "github".
6565
sigstore?: 'public-good' | 'github'
66+
// HTTP headers to include in request to attestations API.
67+
headers?: {[header: string]: string | number | undefined}
6668
// Whether to skip writing the attestation to the GH attestations API.
6769
skipWrite?: boolean
6870
}
@@ -113,6 +115,8 @@ export type AttestProvenanceOptions = {
113115
// Sigstore instance to use for signing. Must be one of "public-good" or
114116
// "github".
115117
sigstore?: 'public-good' | 'github'
118+
// HTTP headers to include in request to attestations API.
119+
headers?: {[header: string]: string | number | undefined}
116120
// Whether to skip writing the attestation to the GH attestations API.
117121
skipWrite?: boolean
118122
// Issuer URL responsible for minting the OIDC token from which the

packages/attest/RELEASES.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# @actions/attest Releases
22

3+
### 1.4.0
4+
5+
- Add new `headers` parameter to the `attest` and `attestProvenance` functions.
6+
37
### 1.3.1
48

59
- Fix bug with proxy support when retrieving JWKS for OIDC issuer

packages/attest/__tests__/store.test.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ describe('writeAttestation', () => {
55
const originalEnv = process.env
66
const attestation = {foo: 'bar '}
77
const token = 'token'
8+
const headers = {'X-GitHub-Foo': 'true'}
89

910
const mockAgent = new MockAgent()
1011
setGlobalDispatcher(mockAgent)
@@ -27,14 +28,16 @@ describe('writeAttestation', () => {
2728
.intercept({
2829
path: '/repos/foo/bar/attestations',
2930
method: 'POST',
30-
headers: {authorization: `token ${token}`},
31+
headers: {authorization: `token ${token}`, ...headers},
3132
body: JSON.stringify({bundle: attestation})
3233
})
3334
.reply(201, {id: '123'})
3435
})
3536

3637
it('persists the attestation', async () => {
37-
await expect(writeAttestation(attestation, token)).resolves.toEqual('123')
38+
await expect(
39+
writeAttestation(attestation, token, {headers})
40+
).resolves.toEqual('123')
3841
})
3942
})
4043

packages/attest/package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/attest/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@actions/attest",
3-
"version": "1.3.1",
3+
"version": "1.4.0",
44
"description": "Actions attestation lib",
55
"keywords": [
66
"github",

packages/attest/src/attest.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ export type AttestOptions = {
2828
// Sigstore instance to use for signing. Must be one of "public-good" or
2929
// "github".
3030
sigstore?: SigstoreInstance
31+
// HTTP headers to include in request to attestations API.
32+
headers?: {[header: string]: string | number | undefined}
3133
// Whether to skip writing the attestation to the GH attestations API.
3234
skipWrite?: boolean
3335
}
@@ -61,7 +63,11 @@ export async function attest(options: AttestOptions): Promise<Attestation> {
6163
// Store the attestation
6264
let attestationID: string | undefined
6365
if (options.skipWrite !== true) {
64-
attestationID = await writeAttestation(bundleToJSON(bundle), options.token)
66+
attestationID = await writeAttestation(
67+
bundleToJSON(bundle),
68+
options.token,
69+
{headers: options.headers}
70+
)
6571
}
6672

6773
return toAttestation(bundle, attestationID)

packages/attest/src/store.ts

+3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import * as github from '@actions/github'
22
import {retry} from '@octokit/plugin-retry'
3+
import {RequestHeaders} from '@octokit/types'
34

45
const CREATE_ATTESTATION_REQUEST = 'POST /repos/{owner}/{repo}/attestations'
56
const DEFAULT_RETRY_COUNT = 5
67

78
export type WriteOptions = {
89
retry?: number
10+
headers?: RequestHeaders
911
}
1012
/**
1113
* Writes an attestation to the repository's attestations endpoint.
@@ -26,6 +28,7 @@ export const writeAttestation = async (
2628
const response = await octokit.request(CREATE_ATTESTATION_REQUEST, {
2729
owner: github.context.repo.owner,
2830
repo: github.context.repo.repo,
31+
headers: options.headers,
2932
data: {bundle: attestation}
3033
})
3134

0 commit comments

Comments
 (0)