@eik/core 1.3.54 → 1.3.56
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/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 +289 -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 +20 -15
- 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,104 +1,109 @@
|
|
|
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
|
-
import { decodeUriComponent, readJSON } from
|
|
8
|
-
import { createURIToTargetOfAlias } from
|
|
9
|
-
import { createFilePathToAlias } from
|
|
10
|
-
import HttpOutgoing from
|
|
11
|
-
import config from
|
|
7
|
+
import { decodeUriComponent, readJSON } from "../utils/utils.js";
|
|
8
|
+
import { createURIToTargetOfAlias } from "../utils/path-builders-uri.js";
|
|
9
|
+
import { createFilePathToAlias } from "../utils/path-builders-fs.js";
|
|
10
|
+
import HttpOutgoing from "../classes/http-outgoing.js";
|
|
11
|
+
import config from "../utils/defaults.js";
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @typedef {object} AliasGetOptions
|
|
15
|
+
* @property {string} [cacheControl]
|
|
16
|
+
* @property {Array<[string, string]>} [organizations] List of key-value pairs [hostname, organization]
|
|
17
|
+
* @property {import("@eik/sink").default} [sink]
|
|
18
|
+
* @property {import("abslog").AbstractLoggerOptions} [logger]
|
|
19
|
+
*/
|
|
12
20
|
|
|
13
21
|
const AliasGet = class AliasGet {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
0.01,
|
|
36
|
-
0.06,
|
|
37
|
-
0.1,
|
|
38
|
-
0.6,
|
|
39
|
-
1.0,
|
|
40
|
-
2.0,
|
|
41
|
-
4.0,
|
|
42
|
-
],
|
|
43
|
-
});
|
|
44
|
-
this._orgRegistry = new Map(this._organizations);
|
|
45
|
-
}
|
|
22
|
+
/**
|
|
23
|
+
* @param {AliasGetOptions} options
|
|
24
|
+
*/
|
|
25
|
+
constructor({ organizations, cacheControl, logger, sink } = {}) {
|
|
26
|
+
this._organizations = organizations || config.organizations;
|
|
27
|
+
this._cacheControl = cacheControl || "public, max-age=1200";
|
|
28
|
+
this._sink = sink;
|
|
29
|
+
this._log = abslog(logger);
|
|
30
|
+
this._metrics = new Metrics();
|
|
31
|
+
this._histogram = this._metrics.histogram({
|
|
32
|
+
name: "eik_core_alias_get_handler",
|
|
33
|
+
description:
|
|
34
|
+
"Histogram measuring time taken in @eik/core AliasGet handler method",
|
|
35
|
+
labels: {
|
|
36
|
+
success: true,
|
|
37
|
+
type: "unknown",
|
|
38
|
+
},
|
|
39
|
+
buckets: [0.005, 0.01, 0.06, 0.1, 0.6, 1.0, 2.0, 4.0],
|
|
40
|
+
});
|
|
41
|
+
this._orgRegistry = new Map(this._organizations);
|
|
42
|
+
}
|
|
46
43
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
44
|
+
get metrics() {
|
|
45
|
+
return this._metrics;
|
|
46
|
+
}
|
|
50
47
|
|
|
51
|
-
|
|
52
|
-
|
|
48
|
+
async handler(req, type, name, alias, extra) {
|
|
49
|
+
const end = this._histogram.timer();
|
|
53
50
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
51
|
+
const pAlias = decodeUriComponent(alias);
|
|
52
|
+
const pExtra = decodeUriComponent(extra);
|
|
53
|
+
const pName = decodeUriComponent(name);
|
|
57
54
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
55
|
+
try {
|
|
56
|
+
validators.alias(pAlias);
|
|
57
|
+
validators.extra(pExtra);
|
|
58
|
+
validators.name(pName);
|
|
59
|
+
validators.type(type);
|
|
60
|
+
} catch (error) {
|
|
61
|
+
this._log.debug(`alias:get - Validation failed - ${error.message}`);
|
|
62
|
+
const e = new HttpError.NotFound();
|
|
63
|
+
end({ labels: { success: false, status: e.status } });
|
|
64
|
+
throw e;
|
|
65
|
+
}
|
|
69
66
|
|
|
70
|
-
|
|
71
|
-
|
|
67
|
+
const url = originalUrl(req);
|
|
68
|
+
const org = this._orgRegistry.get(url.hostname);
|
|
72
69
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
70
|
+
if (!org) {
|
|
71
|
+
this._log.info(
|
|
72
|
+
`alias:get - Hostname does not match a configured organization - ${url.hostname}`,
|
|
73
|
+
);
|
|
74
|
+
const e = new HttpError.BadRequest();
|
|
75
|
+
end({ labels: { success: false, status: e.status, type } });
|
|
76
|
+
throw e;
|
|
77
|
+
}
|
|
79
78
|
|
|
80
|
-
|
|
79
|
+
const path = createFilePathToAlias({
|
|
80
|
+
org,
|
|
81
|
+
type,
|
|
82
|
+
name: pName,
|
|
83
|
+
alias: pAlias,
|
|
84
|
+
});
|
|
81
85
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
86
|
+
try {
|
|
87
|
+
const obj = await readJSON(this._sink, path);
|
|
88
|
+
const location = createURIToTargetOfAlias({ extra: pExtra, ...obj });
|
|
85
89
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
+
const outgoing = new HttpOutgoing();
|
|
91
|
+
outgoing.cacheControl = this._cacheControl;
|
|
92
|
+
outgoing.statusCode = 302;
|
|
93
|
+
outgoing.location = location;
|
|
90
94
|
|
|
91
|
-
|
|
95
|
+
this._log.debug(`alias:get - Alias found - Pathname: ${path}`);
|
|
92
96
|
|
|
93
|
-
|
|
97
|
+
end({ labels: { status: outgoing.statusCode, type } });
|
|
94
98
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
99
|
+
return outgoing;
|
|
100
|
+
// eslint-disable-next-line no-unused-vars
|
|
101
|
+
} catch (error) {
|
|
102
|
+
this._log.debug(`alias:get - Alias not found - Pathname: ${path}`);
|
|
103
|
+
const e = new HttpError.NotFound();
|
|
104
|
+
end({ labels: { success: false, status: e.status, type } });
|
|
105
|
+
throw e;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
103
108
|
};
|
|
104
109
|
export default AliasGet;
|
|
@@ -1,209 +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 { createURIToAlias } from
|
|
12
|
-
import MultipartParser from
|
|
13
|
-
import HttpIncoming from
|
|
14
|
-
import HttpOutgoing from
|
|
15
|
-
import Author from
|
|
16
|
-
import Alias from
|
|
17
|
-
import config from
|
|
18
|
-
import { decodeUriComponent, writeJSON } from
|
|
8
|
+
createFilePathToAlias,
|
|
9
|
+
createFilePathToAliasOrigin,
|
|
10
|
+
} from "../utils/path-builders-fs.js";
|
|
11
|
+
import { createURIToAlias } from "../utils/path-builders-uri.js";
|
|
12
|
+
import MultipartParser from "../multipart/parser.js";
|
|
13
|
+
import HttpIncoming from "../classes/http-incoming.js";
|
|
14
|
+
import HttpOutgoing from "../classes/http-outgoing.js";
|
|
15
|
+
import Author from "../classes/author.js";
|
|
16
|
+
import Alias from "../classes/alias.js";
|
|
17
|
+
import config from "../utils/defaults.js";
|
|
18
|
+
import { decodeUriComponent, writeJSON } from "../utils/utils.js";
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @typedef {object} AliasPostOptions
|
|
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 AliasPost = class AliasPost {
|
|
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
|
-
end({ labels: { success: false, status: e.status, type } });
|
|
194
|
-
throw e;
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
await this._parser(incoming);
|
|
198
|
-
|
|
199
|
-
const outgoing = new HttpOutgoing();
|
|
200
|
-
outgoing.cacheControl = this._cacheControl;
|
|
201
|
-
outgoing.statusCode = 303;
|
|
202
|
-
outgoing.location = createURIToAlias(incoming);
|
|
203
|
-
|
|
204
|
-
end({ labels: { status: outgoing.statusCode, type } });
|
|
205
|
-
|
|
206
|
-
return outgoing;
|
|
207
|
-
}
|
|
29
|
+
/**
|
|
30
|
+
* @param {AliasPostOptions} 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_post_handler",
|
|
40
|
+
description:
|
|
41
|
+
"Histogram measuring time taken in @eik/core AliasPost 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:post - 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:post - 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:post - 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:post - 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:post - Validation failed - ${error.message}`);
|
|
153
|
+
const e = new HttpError.NotFound();
|
|
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:post - 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:post - Alias does not exists - Org: ${org} - Type: ${type} - Name: ${pName} - Alias: ${pAlias}`,
|
|
184
|
+
);
|
|
185
|
+
const e = new HttpError.NotFound();
|
|
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
|
+
}
|
|
208
201
|
};
|
|
209
202
|
export default AliasPost;
|