Skip to content

Commit b6219a1

Browse files
authored
Merge pull request #16 from myDevicesIoT/refactor/auth
refactor: authentication
2 parents 7ba810e + 0c24f1c commit b6219a1

23 files changed

+2463
-1473
lines changed

.env.example

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
CAYENNE_BASE_URL=
2+
CAYENNE_TOKEN=
3+
4+
DELOREAN_ES_BASE_URL=
5+
DELOREAN_ES_TOKEN=
6+
7+
EXECUTOR_BASE_URL=
8+
EXECUTOR_TOKEN=
9+
10+
HERMES_BASE_URL=
11+
HERMES_TOKEN=
12+
13+
PROMETHEUS_BASE_URL=
14+
PROMETHEUS_TOKEN=
15+
16+
STREAMING_BASE_URL=
17+
STREAMING_TOKEN=
18+
19+
TIMEKEEPER_BASE_URL=
20+
TIMEKEEPER_TOKEN=

lib/Auth/token.js

Lines changed: 0 additions & 33 deletions
This file was deleted.

lib/Core.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
const classes = {
2+
Cayenne: require('./Services/cayenne'),
3+
DeloreanES: require('./Services/delorean-es'),
4+
Executor: require('./Services/executor'),
5+
Hermes: require('./Services/hermes'),
6+
Prometheus: require('./Services/prometheus'),
7+
Streaming: require('./Services/streaming'),
8+
Timekeeper: require('./Services/timekeeper')
9+
};
10+
11+
/**
12+
* @typedef ServiceOpts
13+
*
14+
* @property {string} name
15+
* @property {string} url
16+
* @property {string} token
17+
*/
18+
19+
class Core {
20+
/**
21+
* @param {Object} coreOpts
22+
* @param {ServiceOpts} coreOpts.cayenne
23+
* @param {ServiceOpts} coreOpts.deloreanES
24+
* @param {ServiceOpts} coreOpts.executor
25+
* @param {ServiceOpts} coreOpts.hermes
26+
* @param {ServiceOpts} coreOpts.prometheus
27+
* @param {ServiceOpts} coreOpts.starbase
28+
* @param {ServiceOpts} coreOpts.streaming
29+
* @param {ServiceOpts} coreOpts.timekeeper
30+
* @param {Object} [opts={}]
31+
*/
32+
constructor(coreOpts, opts = {}) {
33+
Object.entries(coreOpts).forEach(([key, { name, url, token }]) => {
34+
if (!classes[name]) {
35+
return;
36+
}
37+
this[key] = new classes[name](url, token, opts);
38+
});
39+
}
40+
}
41+
42+
module.exports = Core;

lib/CoreError.js

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,23 +39,16 @@ class CoreError extends Boom {
3939
return this;
4040
}
4141

42-
static InvalidApplicationCredentials() {
43-
return this.unauthorized(this.InvalidApplicationCredentials.name, {
44-
ctr: this.InvalidApplicationCredentials,
42+
static InvalidConfiguration() {
43+
return this.badRequest(this.InvalidConfiguration.name, {
44+
ctr: this.InvalidConfiguration,
4545
isInternal: true
4646
});
4747
}
4848

49-
static MaxAuthenticationRequestsReached() {
50-
return this.unauthorized(this.MaxAuthenticationRequestsReached.name, {
51-
ctr: this.MaxAuthenticationRequestsReached,
52-
isInternal: true
53-
});
54-
}
55-
56-
static MaxAuthenticatedRequestsReached() {
57-
return this.unauthorized(this.MaxAuthenticatedRequestsReached.name, {
58-
ctr: this.MaxAuthenticatedRequestsReached,
49+
static InvalidCredentials() {
50+
return this.unauthorized(this.InvalidCredentials.name, {
51+
ctr: this.InvalidCredentials,
5952
isInternal: true
6053
});
6154
}

0 commit comments

Comments
 (0)