Skip to content

Commit

Permalink
API keys are no longer needed
Browse files Browse the repository at this point in the history
  • Loading branch information
deniak committed Jul 24, 2023
1 parent 0c728a3 commit 639a2e2
Show file tree
Hide file tree
Showing 10 changed files with 70 additions and 100 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,3 @@ jobs:
- run: npm ci

- run: npm run coverage
env:
W3C_API_KEY: ${{ secrets.W3C_API_KEY }}
22 changes: 10 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,9 @@ on the same core library.
### Syntax and command-line parameters

```bash
$ W3C_API_KEY="<YOUR W3C API KEY>" npm start [PORT]
$ npm start [PORT]
```

Specberus relies on the [W3C API](https://w3c.github.io/w3c-api/) to run a few checks. You will need to provide [your key](https://w3c.github.io/w3c-api/#apikeys) in an environment variable `W3C_API_KEY`

Meaning of positional parameters:

1. `PORT`: where Specberus will be listening for HTTP connections.
Expand All @@ -49,16 +47,16 @@ Meaning of positional parameters:
Examples:

```bash
$ W3C_API_KEY="<YOUR W3C API KEY>" npm start
$ W3C_API_KEY="<YOUR W3C API KEY>" npm start 3001
$ npm start
$ npm start 3001
```

![running specberus](doc/running.jpg)

Set the environment variable `DEBUG` to run in _debug mode_ instead:

```bash
$ DEBUG=true W3C_API_KEY="<YOUR W3C API KEY>" npm run start
$ DEBUG=true npm run start
```

This modifies the behaviour of certain parts of the application to facilitate debugging.
Expand All @@ -69,18 +67,18 @@ If Specberus is _not_ going to be served from the root directory of a domain, or
set also `BASE_URI` pointing to the public root URI of Specberus; eg

```bash
$ BASE_URI=https://spec-store.com/check/ W3C_API_KEY=deadbeef npm start
$ BASE_URI=/hostname/can/be/omitted/ W3C_API_KEY=deadbeef npm start 88
$ BASE_URI=https://spec-store.com/check/ npm start
$ BASE_URI=/hostname/can/be/omitted/ npm start 88
```

2. Auto reload when developing

Run `npm run live` when developing. The app will automatically reload when changes happen.

```bash
$ W3C_API_KEY="xxx" npm run live
$ npm run live

$ W3C_API_KEY="xxx" npm run live 3001
$ npm run live 3001
```

## 3. Testing
Expand All @@ -90,7 +88,7 @@ $ W3C_API_KEY="xxx" npm run live 3001
Testing is done using mocha. Simply run:

```bash
$ W3C_API_KEY="<YOUR W3C API KEY>" mocha
$ mocha
```

from the root and you will be running the test suite. Mocha can be installed with:
Expand All @@ -105,7 +103,7 @@ Some of the tests can on occasion take a long time, or fail outright because a r
unavailable. To work around this, you can set SKIP_NETWORK:

```bash
$ SKIP_NETWORK=1 W3C_API_KEY="<YOUR W3C API KEY>" mocha
$ SKIP_NETWORK=1 mocha
```

#### 3. Run testserver
Expand Down
12 changes: 3 additions & 9 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,6 @@ const { version } = importJSON('./package.json', import.meta.url);
// Settings:
const DEFAULT_PORT = 80;

if (!process.env.W3C_API_KEY || process.env.W3C_API_KEY.length < 1) {
throw new Error(
'Pubrules is missing a valid key for the W3C API; define environment variable “W3C_API_KEY”'
);
}

if (!process.env.BASE_URI || process.env.BASE_URI.length < 1) {
console.warn(

Check warning on line 25 in app.js

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement
`Environment variable “BASE_URI” not defined; assuming that Pubrules lives at “/”`
Expand All @@ -42,7 +36,7 @@ app.use(compression());
app.use('/badterms.json', cors());

app.use(express.static('public'));
api.setUp(app, process.env.W3C_API_KEY);
api.setUp(app);
views.setUp(app);

// @TODO Localize this properly when messages are translated; hard-coded British English for now.
Expand All @@ -55,7 +49,7 @@ io.on('connection', socket => {
socket.on('extractMetadata', data => {

Check warning on line 49 in app.js

View workflow job for this annotation

GitHub Actions / lint

Expected to return a value at the end of arrow function
if (!data.url)
return socket.emit('exception', { message: 'URL not provided.' });
const specberus = new Specberus(process.env.W3C_API_KEY);
const specberus = new Specberus();
const handler = new Sink();
handler.on('err', (type, data) => {
try {
Expand Down Expand Up @@ -118,7 +112,7 @@ io.on('connection', socket => {
message: `Failed to get profile ${profilePath}.`,
});
}
const specberus = new Specberus(process.env.W3C_API_KEY);
const specberus = new Specberus();
const handler = new Sink();
const profileCode = profile.name;
socket.emit('start', {
Expand Down
2 changes: 0 additions & 2 deletions lib/rules/echidna/deliverer-change.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import w3cApi from 'node-w3capi';

w3cApi.apiKey = process.env.W3C_API_KEY;

const self = {
name: 'echidna.deliverer-change',
section: 'metadata',
Expand Down
3 changes: 0 additions & 3 deletions lib/rules/metadata/profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,12 @@
*/

// Internal packages:
import w3cApi from 'node-w3capi';
import { allProfiles, importJSON } from '../../util.js';
import { sortedProfiles } from '../../views.js';
import { check as getTitle } from './title.js';

const rules = importJSON('../../rules.json', import.meta.url);

w3cApi.apiKey = process.env.W3C_API_KEY;

// 'self.name' would be 'metadata.profile'
export const name = 'metadata.profile';

Expand Down
11 changes: 1 addition & 10 deletions lib/validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,8 @@ const { rules } = profileMetadata;
const { version } = importJSON('../package.json', import.meta.url);

setLanguage('en_GB');
w3cApi.apiKey = process.env.W3C_API_KEY;

const Specberus = function (apiKey = process.env.W3C_API_KEY) {
if (typeof apiKey !== 'string' || !apiKey.length) {
throw new Error('apiKey is required.');
}
this.apiKey = apiKey;
const Specberus = function () {
this.version = version;
this.clearCache();
};
Expand Down Expand Up @@ -583,12 +578,10 @@ Specberus.prototype.getDelivererGroups = async function () {
// send request to W3C API if there's id extracted from the doc.
for (let i = 0; i < ids.length; i += 1) {
const groupApiUrl = `https://api.w3.org/groups/${ids[i]}`;
const apikey = this.apiKey;
promiseArray.push(
new Promise(resolve => {
get(groupApiUrl)
.set('User-Agent', `W3C-Pubrules/${version}`)
.query({ apikey })
.end((err, data) => {
resolve(data);
});
Expand Down Expand Up @@ -662,12 +655,10 @@ Specberus.prototype.getDelivererIDs = async function () {
const [, type, shortname] =
REGEX_DELIVERER_IPR_URL.exec(href);
const groupApiUrl = `https://api.w3.org/groups/${type}/${shortname}`;
const apikey = this.apiKey;
promiseArray.push(
new Promise(resolve => {
get(groupApiUrl)
.set('User-Agent', `W3C-Pubrules/${version}`)
.query({ apikey })
.end((err, data) => {
resolve(data);
});
Expand Down
98 changes: 49 additions & 49 deletions package-lock.json

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

Loading

0 comments on commit 639a2e2

Please sign in to comment.