Skip to content

Commit

Permalink
Remove checks for GITHUB_TOKEN around image fetching
Browse files Browse the repository at this point in the history
  • Loading branch information
Barry Gordon committed Mar 21, 2022
1 parent 259ca0d commit b9f64f7
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 68 deletions.
4 changes: 0 additions & 4 deletions .github/workflows/integration-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@ jobs:

- name: Pre-fetch the pinned images
run: npm run fetch-images
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Run integration tests
run: npm run test-integration
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
36 changes: 0 additions & 36 deletions __tests__/image-service.test.ts
Original file line number Diff line number Diff line change
@@ -1,43 +1,7 @@
import {ImageService} from '../src/image-service'

describe('ImageService', () => {
const originalEnv = process.env

describe('when GITHUB_TOKEN is not set', () => {
beforeEach(async () => {
jest.resetModules()
process.env = {
...originalEnv,
GITHUB_TOKEN: undefined
}
})

afterEach(async () => {
process.env = originalEnv
})

test('it raises an error', async () => {
await expect(
ImageService.pull('ghcr.io/dependabot/dependabot-core:latest')
).rejects.toThrowError(
new Error('No GITHUB_TOKEN set, unable to pull images.')
)
})
})

describe('when asked to fetch non-GitHub hosted images', () => {
beforeEach(async () => {
jest.resetModules()
process.env = {
...originalEnv,
GITHUB_TOKEN: 'mock_token'
}
})

afterEach(async () => {
process.env = originalEnv
})

test('it raises an error', async () => {
await expect(ImageService.pull('hello-world')).rejects.toThrowError(
new Error(
Expand Down
17 changes: 4 additions & 13 deletions dist/main/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/main/index.js.map

Large diffs are not rendered by default.

18 changes: 4 additions & 14 deletions src/image-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,9 @@ const endOfStream = async (docker: Docker, stream: Readable): Promise<void> => {
export const ImageService = {
async pull(imageName: string, force = false): Promise<void> {
/*
This method fetches images using a GITHUB_TOKEN we should check two things:
- The process has a GITHUB_TOKEN set so we don't attempt a failed call to docker
- The image being requested is actually hosted on GitHub.
This method fetches images hosts on GitHub infrastructure.
We expose the `fetch_image` utility method to allow us to pull in arbitrary images
without auth in unit tests.
We expose the `fetch_image` utility method to allow us to pull in arbitrary images for unit tests.
*/
if (
!(
Expand All @@ -32,10 +29,6 @@ export const ImageService = {
)
}

if (!process.env.GITHUB_TOKEN) {
throw new Error('No GITHUB_TOKEN set, unable to pull images.')
}

const docker = new Docker()
try {
const image = await docker.getImage(imageName).inspect()
Expand All @@ -49,11 +42,8 @@ export const ImageService = {
} // else fallthrough to pull
}

// const auth = {
// username: 'x',
// password: process.env.GITHUB_TOKEN
// }
await this.fetchImage(imageName, {}, docker)
const auth = {} // Images are public so not authentication info is required
await this.fetchImage(imageName, auth, docker)
},

/* Retrieve the imageName using the auth details provided, if any */
Expand Down

0 comments on commit b9f64f7

Please sign in to comment.