@eik/core 1.3.53 → 1.3.55
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/lib/classes/alias.js +48 -48
- package/lib/classes/asset.js +99 -92
- package/lib/classes/author.js +20 -20
- package/lib/classes/http-incoming.js +52 -52
- package/lib/classes/http-outgoing.js +84 -83
- package/lib/classes/meta.js +20 -23
- package/lib/classes/package.js +73 -70
- package/lib/classes/versions.js +62 -60
- package/lib/handlers/alias.delete.js +125 -120
- package/lib/handlers/alias.get.js +92 -87
- package/lib/handlers/alias.post.js +196 -203
- package/lib/handlers/alias.put.js +196 -202
- package/lib/handlers/auth.post.js +95 -93
- package/lib/handlers/map.get.js +110 -111
- package/lib/handlers/map.put.js +256 -231
- package/lib/handlers/pkg.get.js +120 -122
- package/lib/handlers/pkg.log.js +112 -110
- package/lib/handlers/pkg.put.js +223 -213
- package/lib/handlers/versions.get.js +92 -101
- package/lib/main.js +47 -47
- package/lib/multipart/form-field.js +20 -23
- package/lib/multipart/form-file.js +22 -24
- package/lib/multipart/parser.js +231 -217
- package/lib/sinks/mem-entry.js +26 -31
- package/lib/sinks/test.js +287 -273
- package/lib/utils/defaults.js +11 -11
- package/lib/utils/globals.js +5 -5
- package/lib/utils/healthcheck.js +131 -108
- package/lib/utils/path-builders-fs.js +61 -29
- package/lib/utils/path-builders-uri.js +26 -18
- package/lib/utils/utils.js +76 -79
- package/package.json +22 -17
- package/types/classes/alias.d.ts +28 -0
- package/types/classes/asset.d.ts +48 -0
- package/types/classes/author.d.ts +17 -0
- package/types/classes/http-incoming.d.ts +37 -0
- package/types/classes/http-outgoing.d.ts +20 -0
- package/types/classes/meta.d.ts +17 -0
- package/types/classes/package.d.ts +40 -0
- package/types/classes/versions.d.ts +28 -0
- package/types/handlers/alias.delete.d.ts +33 -0
- package/types/handlers/alias.get.d.ts +48 -0
- package/types/handlers/alias.post.d.ts +83 -0
- package/types/handlers/alias.put.d.ts +83 -0
- package/types/handlers/auth.post.d.ts +82 -0
- package/types/handlers/map.get.d.ts +51 -0
- package/types/handlers/map.put.d.ts +78 -0
- package/types/handlers/pkg.get.d.ts +51 -0
- package/types/handlers/pkg.log.d.ts +51 -0
- package/types/handlers/pkg.put.d.ts +107 -0
- package/types/handlers/versions.get.d.ts +48 -0
- package/types/main.d.ts +44 -0
- package/types/multipart/form-field.d.ts +17 -0
- package/types/multipart/form-file.d.ts +17 -0
- package/types/multipart/parser.d.ts +52 -0
- package/types/sinks/mem-entry.d.ts +15 -0
- package/types/sinks/test.d.ts +32 -0
- package/types/utils/defaults.d.ts +9 -0
- package/types/utils/globals.d.ts +8 -0
- package/types/utils/healthcheck.d.ts +24 -0
- package/types/utils/path-builders-fs.d.ts +41 -0
- package/types/utils/path-builders-uri.d.ts +26 -0
- package/types/utils/utils.d.ts +6 -0
|
@@ -1,208 +1,202 @@
|
|
|
1
|
-
import { validators } from
|
|
2
|
-
import originalUrl from
|
|
3
|
-
import HttpError from
|
|
4
|
-
import abslog from
|
|
5
|
-
import Metrics from
|
|
1
|
+
import { validators } from "@eik/common";
|
|
2
|
+
import originalUrl from "original-url";
|
|
3
|
+
import HttpError from "http-errors";
|
|
4
|
+
import abslog from "abslog";
|
|
5
|
+
import Metrics from "@metrics/client";
|
|
6
6
|
|
|
7
7
|
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
} from
|
|
11
|
-
import { decodeUriComponent, writeJSON } from
|
|
12
|
-
import { createURIToAlias } from
|
|
13
|
-
import MultipartParser from
|
|
14
|
-
import HttpIncoming from
|
|
15
|
-
import HttpOutgoing from
|
|
16
|
-
import Author from
|
|
17
|
-
import Alias from
|
|
18
|
-
import config from
|
|
8
|
+
createFilePathToAlias,
|
|
9
|
+
createFilePathToAliasOrigin,
|
|
10
|
+
} from "../utils/path-builders-fs.js";
|
|
11
|
+
import { decodeUriComponent, writeJSON } from "../utils/utils.js";
|
|
12
|
+
import { createURIToAlias } from "../utils/path-builders-uri.js";
|
|
13
|
+
import MultipartParser from "../multipart/parser.js";
|
|
14
|
+
import HttpIncoming from "../classes/http-incoming.js";
|
|
15
|
+
import HttpOutgoing from "../classes/http-outgoing.js";
|
|
16
|
+
import Author from "../classes/author.js";
|
|
17
|
+
import Alias from "../classes/alias.js";
|
|
18
|
+
import config from "../utils/defaults.js";
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @typedef {object} AliasPutOptions
|
|
22
|
+
* @property {string} [cacheControl]
|
|
23
|
+
* @property {Array<[string, string]>} [organizations] List of key-value pairs [hostname, organization]
|
|
24
|
+
* @property {import("@eik/sink").default} [sink]
|
|
25
|
+
* @property {import("abslog").AbstractLoggerOptions} [logger]
|
|
26
|
+
*/
|
|
19
27
|
|
|
20
28
|
const AliasPut = class AliasPut {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
throw e;
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
await this._parser(incoming);
|
|
197
|
-
|
|
198
|
-
const outgoing = new HttpOutgoing();
|
|
199
|
-
outgoing.cacheControl = this._cacheControl;
|
|
200
|
-
outgoing.statusCode = 303;
|
|
201
|
-
outgoing.location = createURIToAlias(incoming);
|
|
202
|
-
|
|
203
|
-
end({ labels: { status: outgoing.statusCode, type } });
|
|
204
|
-
|
|
205
|
-
return outgoing;
|
|
206
|
-
}
|
|
29
|
+
/**
|
|
30
|
+
* @param {AliasPutOptions} options
|
|
31
|
+
*/
|
|
32
|
+
constructor({ organizations, cacheControl, logger, sink } = {}) {
|
|
33
|
+
this._organizations = organizations || config.organizations;
|
|
34
|
+
this._cacheControl = cacheControl;
|
|
35
|
+
this._sink = sink;
|
|
36
|
+
this._log = abslog(logger);
|
|
37
|
+
this._metrics = new Metrics();
|
|
38
|
+
this._histogram = this._metrics.histogram({
|
|
39
|
+
name: "eik_core_alias_put_handler",
|
|
40
|
+
description:
|
|
41
|
+
"Histogram measuring time taken in @eik/core AliasPut handler method",
|
|
42
|
+
labels: {
|
|
43
|
+
success: true,
|
|
44
|
+
type: "unknown",
|
|
45
|
+
},
|
|
46
|
+
buckets: [0.005, 0.01, 0.06, 0.1, 0.6, 1.0, 2.0, 4.0],
|
|
47
|
+
});
|
|
48
|
+
this._orgRegistry = new Map(this._organizations);
|
|
49
|
+
|
|
50
|
+
this._multipart = new MultipartParser({
|
|
51
|
+
legalFields: ["version"],
|
|
52
|
+
sink: this._sink,
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
get metrics() {
|
|
57
|
+
return this._metrics;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
_parser(incoming) {
|
|
61
|
+
return new Promise((resolve, reject) => {
|
|
62
|
+
this._multipart
|
|
63
|
+
.parse(incoming)
|
|
64
|
+
.then((result) => {
|
|
65
|
+
const obj = result[0];
|
|
66
|
+
if (obj && obj.constructor.name === "FormField") {
|
|
67
|
+
try {
|
|
68
|
+
validators.version(obj.value);
|
|
69
|
+
} catch (error) {
|
|
70
|
+
this._log.error(
|
|
71
|
+
`alias:put - Input field could not be validated - Name: ${obj.name} - Value: ${obj.value}`,
|
|
72
|
+
);
|
|
73
|
+
this._log.trace(error);
|
|
74
|
+
throw new HttpError.BadRequest();
|
|
75
|
+
}
|
|
76
|
+
const alias = new Alias(incoming);
|
|
77
|
+
alias.version = obj.value;
|
|
78
|
+
return alias;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
throw new HttpError.BadRequest();
|
|
82
|
+
})
|
|
83
|
+
.then(async (alias) => {
|
|
84
|
+
try {
|
|
85
|
+
const path = createFilePathToAliasOrigin({
|
|
86
|
+
org: alias.org,
|
|
87
|
+
type: alias.type,
|
|
88
|
+
name: alias.name,
|
|
89
|
+
version: alias.version,
|
|
90
|
+
});
|
|
91
|
+
await this._sink.read(path);
|
|
92
|
+
} catch (error) {
|
|
93
|
+
this._log.error(
|
|
94
|
+
`alias:post - Unable to locate requested published package version - Version ${alias.name}@${alias.version}`,
|
|
95
|
+
);
|
|
96
|
+
this._log.trace(error);
|
|
97
|
+
throw new HttpError.NotFound();
|
|
98
|
+
}
|
|
99
|
+
return alias;
|
|
100
|
+
})
|
|
101
|
+
.then(async (alias) => {
|
|
102
|
+
const path = createFilePathToAlias(incoming);
|
|
103
|
+
|
|
104
|
+
this._log.info(
|
|
105
|
+
`alias:put - Start writing alias to sink - Pathname: ${path}`,
|
|
106
|
+
);
|
|
107
|
+
|
|
108
|
+
try {
|
|
109
|
+
await writeJSON(this._sink, path, alias, "application/json");
|
|
110
|
+
} catch (error) {
|
|
111
|
+
this._log.error(
|
|
112
|
+
`alias:put - Failed writing alias to sink - Pathname: ${path}`,
|
|
113
|
+
);
|
|
114
|
+
this._log.trace(error);
|
|
115
|
+
throw new HttpError.BadGateway();
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
this._log.info(
|
|
119
|
+
`alias:put - Successfully wrote alias to sink - Pathname: ${path}`,
|
|
120
|
+
);
|
|
121
|
+
|
|
122
|
+
resolve(alias);
|
|
123
|
+
})
|
|
124
|
+
.catch((error) => {
|
|
125
|
+
reject(error);
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
async _exist(incoming) {
|
|
131
|
+
try {
|
|
132
|
+
const path = createFilePathToAlias(incoming);
|
|
133
|
+
await this._sink.exist(path);
|
|
134
|
+
return true;
|
|
135
|
+
// eslint-disable-next-line no-unused-vars
|
|
136
|
+
} catch (error) {
|
|
137
|
+
return false;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
async handler(req, user, type, name, alias) {
|
|
142
|
+
const end = this._histogram.timer();
|
|
143
|
+
|
|
144
|
+
const pAlias = decodeUriComponent(alias);
|
|
145
|
+
const pName = decodeUriComponent(name);
|
|
146
|
+
|
|
147
|
+
try {
|
|
148
|
+
validators.alias(pAlias);
|
|
149
|
+
validators.name(pName);
|
|
150
|
+
validators.type(type);
|
|
151
|
+
} catch (error) {
|
|
152
|
+
this._log.info(`alias:put - Validation failed - ${error.message}`);
|
|
153
|
+
const e = new HttpError.BadRequest();
|
|
154
|
+
end({ labels: { success: false, status: e.status } });
|
|
155
|
+
throw e;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
const url = originalUrl(req);
|
|
159
|
+
const org = this._orgRegistry.get(url.hostname);
|
|
160
|
+
|
|
161
|
+
if (!org) {
|
|
162
|
+
this._log.info(
|
|
163
|
+
`alias:put - Hostname does not match a configured organization - ${url.hostname}`,
|
|
164
|
+
);
|
|
165
|
+
const e = new HttpError.BadRequest();
|
|
166
|
+
end({ labels: { success: false, status: e.status, type } });
|
|
167
|
+
throw e;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
const author = new Author(user);
|
|
171
|
+
|
|
172
|
+
const incoming = new HttpIncoming(req, {
|
|
173
|
+
author,
|
|
174
|
+
alias: pAlias,
|
|
175
|
+
name: pName,
|
|
176
|
+
type,
|
|
177
|
+
org,
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
const exist = await this._exist(incoming);
|
|
181
|
+
if (exist) {
|
|
182
|
+
this._log.info(
|
|
183
|
+
`alias:put - Alias exists - Org: ${org} - Type: ${type} - Name: ${pName} - Alias: ${pAlias}`,
|
|
184
|
+
);
|
|
185
|
+
const e = new HttpError.Conflict();
|
|
186
|
+
end({ labels: { success: false, status: e.status, type } });
|
|
187
|
+
throw e;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
await this._parser(incoming);
|
|
191
|
+
|
|
192
|
+
const outgoing = new HttpOutgoing();
|
|
193
|
+
outgoing.cacheControl = this._cacheControl;
|
|
194
|
+
outgoing.statusCode = 303;
|
|
195
|
+
outgoing.location = createURIToAlias(incoming);
|
|
196
|
+
|
|
197
|
+
end({ labels: { status: outgoing.statusCode, type } });
|
|
198
|
+
|
|
199
|
+
return outgoing;
|
|
200
|
+
}
|
|
207
201
|
};
|
|
208
202
|
export default AliasPut;
|
|
@@ -1,109 +1,111 @@
|
|
|
1
|
-
import originalUrl from
|
|
2
|
-
import HttpError from
|
|
3
|
-
import Metrics from
|
|
4
|
-
import abslog from
|
|
1
|
+
import originalUrl from "original-url";
|
|
2
|
+
import HttpError from "http-errors";
|
|
3
|
+
import Metrics from "@metrics/client";
|
|
4
|
+
import abslog from "abslog";
|
|
5
5
|
|
|
6
|
-
import MultipartParser from
|
|
7
|
-
import HttpIncoming from
|
|
8
|
-
import HttpOutgoing from
|
|
9
|
-
import Author from
|
|
10
|
-
import config from
|
|
6
|
+
import MultipartParser from "../multipart/parser.js";
|
|
7
|
+
import HttpIncoming from "../classes/http-incoming.js";
|
|
8
|
+
import HttpOutgoing from "../classes/http-outgoing.js";
|
|
9
|
+
import Author from "../classes/author.js";
|
|
10
|
+
import config from "../utils/defaults.js";
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @typedef {object} AuthPostOptions
|
|
14
|
+
* @property {string} [authKey]
|
|
15
|
+
* @property {string} [cacheControl]
|
|
16
|
+
* @property {Array<[string, string]>} [organizations] List of key-value pairs [hostname, organization]
|
|
17
|
+
* @property {import("abslog").AbstractLoggerOptions} [logger]
|
|
18
|
+
*/
|
|
11
19
|
|
|
12
20
|
const AuthPost = class AuthPost {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
0.005,
|
|
34
|
-
0.01,
|
|
35
|
-
0.06,
|
|
36
|
-
0.1,
|
|
37
|
-
0.6,
|
|
38
|
-
1.0,
|
|
39
|
-
2.0,
|
|
40
|
-
4.0,
|
|
41
|
-
],
|
|
42
|
-
});
|
|
43
|
-
this._orgRegistry = new Map(this._organizations);
|
|
21
|
+
/**
|
|
22
|
+
* @param {AuthPostOptions} options
|
|
23
|
+
*/
|
|
24
|
+
constructor({ organizations, cacheControl, authKey, logger } = {}) {
|
|
25
|
+
this._organizations = organizations || config.organizations;
|
|
26
|
+
this._cacheControl = cacheControl;
|
|
27
|
+
this._authKey = authKey || config.authKey;
|
|
28
|
+
this._log = abslog(logger);
|
|
29
|
+
this._metrics = new Metrics();
|
|
30
|
+
this._histogram = this._metrics.histogram({
|
|
31
|
+
name: "eik_core_auth_post_handler",
|
|
32
|
+
description:
|
|
33
|
+
"Histogram measuring time taken in @eik/core AuthPost handler method",
|
|
34
|
+
labels: {
|
|
35
|
+
success: true,
|
|
36
|
+
type: "unknown",
|
|
37
|
+
},
|
|
38
|
+
buckets: [0.005, 0.01, 0.06, 0.1, 0.6, 1.0, 2.0, 4.0],
|
|
39
|
+
});
|
|
40
|
+
this._orgRegistry = new Map(this._organizations);
|
|
44
41
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
});
|
|
50
|
-
}
|
|
42
|
+
this._multipart = new MultipartParser({
|
|
43
|
+
legalFields: ["key"],
|
|
44
|
+
});
|
|
45
|
+
}
|
|
51
46
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
47
|
+
get metrics() {
|
|
48
|
+
return this._metrics;
|
|
49
|
+
}
|
|
55
50
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
51
|
+
_parser(incoming) {
|
|
52
|
+
return new Promise((resolve, reject) => {
|
|
53
|
+
this._multipart
|
|
54
|
+
.parse(incoming)
|
|
55
|
+
.then((result) => {
|
|
56
|
+
const obj = result[0];
|
|
57
|
+
if (obj && obj.constructor.name === "FormField") {
|
|
58
|
+
if (obj.value !== this._authKey) {
|
|
59
|
+
this._log.info(
|
|
60
|
+
`auth:post - Auth submitted an illegal key: ${obj.value}`,
|
|
61
|
+
);
|
|
62
|
+
throw new HttpError.Unauthorized();
|
|
63
|
+
}
|
|
64
|
+
const author = new Author({
|
|
65
|
+
user: "generic_user",
|
|
66
|
+
name: "Generic User",
|
|
67
|
+
});
|
|
68
|
+
resolve(author);
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
throw new HttpError.BadRequest();
|
|
72
|
+
})
|
|
73
|
+
.catch((error) => {
|
|
74
|
+
reject(error);
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
78
|
|
|
79
|
-
|
|
80
|
-
|
|
79
|
+
async handler(req) {
|
|
80
|
+
const end = this._histogram.timer();
|
|
81
81
|
|
|
82
|
-
|
|
83
|
-
|
|
82
|
+
const url = originalUrl(req);
|
|
83
|
+
const org = this._orgRegistry.get(url.hostname);
|
|
84
84
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
85
|
+
if (!org) {
|
|
86
|
+
this._log.info(
|
|
87
|
+
`auth:post - Hostname does not match a configured organization - ${url.hostname}`,
|
|
88
|
+
);
|
|
89
|
+
const e = new HttpError.BadRequest();
|
|
90
|
+
end({ labels: { success: false, status: e.status, type: "auth" } });
|
|
91
|
+
throw e;
|
|
92
|
+
}
|
|
91
93
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
94
|
+
const incoming = new HttpIncoming(req, {
|
|
95
|
+
org,
|
|
96
|
+
});
|
|
95
97
|
|
|
96
|
-
|
|
98
|
+
const obj = await this._parser(incoming);
|
|
97
99
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
100
|
+
const outgoing = new HttpOutgoing();
|
|
101
|
+
outgoing.cacheControl = this._cacheControl;
|
|
102
|
+
outgoing.statusCode = 200;
|
|
103
|
+
outgoing.mimeType = "application/json";
|
|
104
|
+
outgoing.body = obj;
|
|
103
105
|
|
|
104
|
-
|
|
106
|
+
end({ labels: { status: outgoing.statusCode, type: "auth" } });
|
|
105
107
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
+
return outgoing;
|
|
109
|
+
}
|
|
108
110
|
};
|
|
109
111
|
export default AuthPost;
|