Skip to content

Commit

Permalink
Merge pull request #22 from secure-dashboards/feat/add-support-for-se…
Browse files Browse the repository at this point in the history
…crets
  • Loading branch information
UlisesGascon authored Dec 4, 2024
2 parents 96dd002 + fc28ad2 commit 084b836
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 2 deletions.
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ This is an evolution of [this proof of concept (POC)](https://github.com/UlisesG

- Node.js 22 and npm
- Docker and Docker Compose
- Github token with repo:read level access.

## Infrastructure

Expand All @@ -28,6 +29,23 @@ To stop the infrastructure, run the following command:
npm run infra:stop
```

## Configuration

### Environment Variables

This project requires a GitHub token to access the GitHub API. You need to set the `GITHUB_TOKEN` environment variable.

#### Optional: use .env file

Create a `.env` file and add your GitHub token:

```sh
GITHUB_TOKEN=your_github_token_here
```

then use `--env-file` flag to load it, like `node --env-file=.env index.js workflow run --name populate-repos-list`


## Database Management

### Running Migrations
Expand Down
24 changes: 23 additions & 1 deletion __tests__/utils.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,26 @@
const { validateGithubUrl } = require('../src/utils/index')
const { validateGithubUrl, ensureGithubToken } = require('../src/utils/index')

describe('ensureGithubToken', () => {
let originalGithubToken

beforeAll(() => {
originalGithubToken = process.env.GITHUB_TOKEN
})

afterAll(() => {
process.env.GITHUB_TOKEN = originalGithubToken
})

it('should throw an error if GITHUB_TOKEN is required', () => {
delete process.env.GITHUB_TOKEN
expect(() => ensureGithubToken()).toThrow('GITHUB_TOKEN is required')
})

it('should not throw an error if GITHUB_TOKEN is set', () => {
process.env.GITHUB_TOKEN = 'test-token'
expect(() => ensureGithubToken()).not.toThrow()
})
})

describe('validateGithubUrl', () => {
it('should return true for a valid GitHub URL', () => {
Expand Down
9 changes: 8 additions & 1 deletion src/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@ const isURL = require('validator/lib/isURL.js')

const validateGithubUrl = (url) => isURL(url, { protocols: ['https'], require_protocol: true }) && url.includes('github.com')

const ensureGithubToken = () => {
if (!process.env.GITHUB_TOKEN) {
throw new Error('GITHUB_TOKEN is required')
}
}

module.exports = {
validateGithubUrl
validateGithubUrl,
ensureGithubToken
}

0 comments on commit 084b836

Please sign in to comment.