@adobe/helix-admin-support 1.6.37 → 2.0.1

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 CHANGED
@@ -1,3 +1,22 @@
1
+ ## [2.0.1](https://github.com/adobe/helix-admin-support/compare/v2.0.0...v2.0.1) (2023-04-04)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * regression - load fstab from github ([#131](https://github.com/adobe/helix-admin-support/issues/131)) ([389a0be](https://github.com/adobe/helix-admin-support/commit/389a0bef218ae299c3dd83fd30f190ab9cce64fe))
7
+
8
+ # [2.0.0](https://github.com/adobe/helix-admin-support/compare/v1.6.37...v2.0.0) (2023-04-03)
9
+
10
+
11
+ ### Features
12
+
13
+ * add fetchHelixConfig method ([#130](https://github.com/adobe/helix-admin-support/issues/130)) ([11267f4](https://github.com/adobe/helix-admin-support/commit/11267f4b1d31d4a9e67e4cd18a170667b5fc87f9))
14
+
15
+
16
+ ### BREAKING CHANGES
17
+
18
+ * fstab no longer loaded via github as fallback
19
+
1
20
  ## [1.6.37](https://github.com/adobe/helix-admin-support/compare/v1.6.36...v1.6.37) (2023-04-01)
2
21
 
3
22
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adobe/helix-admin-support",
3
- "version": "1.6.37",
3
+ "version": "2.0.1",
4
4
  "description": "Helix Admin Support Library",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -12,11 +12,23 @@
12
12
  import { AdminContext, PathInfo } from './index';
13
13
 
14
14
  /**
15
- * Retrieves the content bus id either from the context or by reading the fstab.
15
+ * Retrieves the content bus id by calculating the hash from the fstab.
16
16
  * @param {AdminContext} ctx the context
17
- * @param {PathInfo} opts lookup options
17
+ * @param {PathInfo} info lookup options
18
+ * @returns {Promise<string|null>} the content bus id
19
+ * or {@code null} if mountpoint not found in fstab
20
+ */
21
+ export function calculateContentBusId(ctx, info): Promise<string|null>;
22
+
23
+ /**
24
+ * Retrieves the content bus id either from the context or by reading fstab entry of
25
+ * helix-config.json. If the helix-config.json does contain the information (yet) it will fall back
26
+ * to {@link #calculateContentBusId}.
27
+ *
28
+ * @param {AdminContext} ctx the context
29
+ * @param {PathInfo} info lookup options
18
30
  * @param {boolean} optional returns {@code null} if the contentBusId can't be computed due to
19
- * missing fstab.
31
+ * missing helix-config or fstab.
20
32
  * @returns {Promise<string>} the content bus id
21
33
  */
22
- export function getContentBusId(ctx:AdminContext, opts:PathInfo, optional:boolean): Promise<string>;
34
+ export function getContentBusId(ctx:AdminContext, info:PathInfo, optional:boolean): Promise<string>;
package/src/contentbus.js CHANGED
@@ -10,37 +10,75 @@
10
10
  * governing permissions and limitations under the License.
11
11
  */
12
12
  import crypto from 'crypto';
13
+ import { MountConfig } from '@adobe/helix-shared-config';
13
14
  import { fetchFstab } from './fetch-fstab.js';
15
+ import { fetchHelixConfig } from './fetch-helix-config.js';
14
16
 
15
17
  /**
16
- * Retrieves the content bus id either from the context or by reading the fstab.
18
+ * Retrieves the content bus id by calculating the hash from the fstab.
17
19
  * @param {AdminContext} ctx the context
18
- * @param {PathInfo} opts lookup options
19
- * @param {boolean} optional returns {@code null} if the contentBusId can't be computed due to
20
- * missing fstab.
20
+ * @param {PathInfo} info lookup options
21
+ * @returns {Promise<string|null>} the content bus id or {@code null}
22
+ * if no fstab or no mountpoint not found in fstab
23
+ */
24
+ export async function calculateContentBusId(ctx, info) {
25
+ const { path } = info;
26
+ const fstab = await fetchFstab(ctx, info, true);
27
+ if (!fstab) {
28
+ return null;
29
+ }
30
+ const mp = fstab.match(path);
31
+ if (!mp) {
32
+ ctx.log.error(`path specified is not mounted in fstab.yaml: ${path}`);
33
+ return null;
34
+ }
35
+ const sha256 = crypto
36
+ .createHash('sha256')
37
+ .update(mp.url)
38
+ .digest('hex');
39
+ const contentBusId = `${sha256.substring(0, 59)}`;
40
+ ctx.log.info(`computed contentBusId: ${contentBusId} for ${mp.url} of ${info.repo}--${info.owner}`);
41
+ return contentBusId;
42
+ }
43
+
44
+ /**
45
+ * Retrieves the content bus id either from the context or by reading fstab entry of
46
+ * helix-config.json. If the helix-config.json does contain the information (yet) it will fall back
47
+ * to {@link #calculateContentBusId}.
48
+ *
49
+ * @param {AdminContext} ctx the context
50
+ * @param {PathInfo} info lookup options
51
+ * @param {boolean} optional if {@code true} it will return {@code null} if none of the sources
52
+ * exists.
21
53
  * @returns {Promise<string>} the content bus id
22
54
  */
23
- export async function getContentBusId(ctx, opts, optional) {
24
- if (ctx.attributes.contentBusId === undefined) {
25
- const { path } = opts;
26
- const fstab = await fetchFstab(ctx, opts, optional);
27
- if (fstab === null) {
28
- // this happens only when optional is `true` and there is no fstab.
29
- ctx.attributes.contentBusId = null;
30
- } else {
55
+ export async function getContentBusId(ctx, info, optional) {
56
+ const fetchId = async () => {
57
+ const { path } = info;
58
+ const helixConfig = await fetchHelixConfig(ctx, info, true);
59
+ if (helixConfig) {
60
+ // this is a bit a hack to transform the serialized fstab in helix-config back to the
61
+ // yaml-ish form.
62
+ const fstabJson = { mountpoints: {} };
63
+ for (const mp of helixConfig.fstab.data.mountpoints) {
64
+ fstabJson.mountpoints[mp.path] = mp;
65
+ }
66
+ const fstab = await new MountConfig().withJSON(fstabJson).init();
31
67
  const mp = fstab.match(path);
32
- if (!mp) {
33
- ctx.log.error(`path specified is not mounted in fstab.yaml: ${path}`);
34
- ctx.attributes.contentBusId = null;
35
- return null;
68
+ if (mp && mp.contentBusId) {
69
+ ctx.log.info(`loaded contentBusId: ${mp.contentBusId} for ${mp.url} of ${info.repo}--${info.owner}`);
70
+ return mp.contentBusId;
36
71
  }
37
- const sha256 = crypto
38
- .createHash('sha256')
39
- .update(mp.url)
40
- .digest('hex');
41
- ctx.attributes.contentBusId = `${sha256.substring(0, 59)}`;
42
- ctx.log.info(`computed contentBusId: ${ctx.attributes.contentBusId} for ${mp.url} of ${opts.repo}--${opts.owner}`);
43
72
  }
73
+ return calculateContentBusId(ctx, info);
74
+ };
75
+
76
+ if (ctx.attributes.contentBusId === undefined) {
77
+ ctx.attributes.contentBusId = await fetchId();
78
+ }
79
+
80
+ if (ctx.attributes.contentBusId || optional) {
81
+ return ctx.attributes.contentBusId;
44
82
  }
45
- return ctx.attributes.contentBusId;
83
+ throw Error(`unable to load contentbus-id for ${info.owner}/${info.repo}/${info.ref}`);
46
84
  }
@@ -0,0 +1,23 @@
1
+ /*
2
+ * Copyright 2023 Adobe. All rights reserved.
3
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License. You may obtain a copy
5
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+ *
7
+ * Unless required by applicable law or agreed to in writing, software distributed under
8
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ * OF ANY KIND, either express or implied. See the License for the specific language
10
+ * governing permissions and limitations under the License.
11
+ */
12
+ import { AdminContext, PathInfo } from './index';
13
+ import {HelixConfig} from "../types/helix-config";
14
+
15
+ /**
16
+ * Retrieves the helix-config.json which is an aggregate from fstab.yaml and head.html.
17
+ *
18
+ * @param {AdminContext} ctx the context
19
+ * @param {PathInfo} info path info
20
+ * @param {boolean} optional if {@code true} returns null if not found
21
+ * @returns {Promise<HelixConfig>} the helix-config or {@code null} if optional and not found.
22
+ */
23
+ export function fetchHelixConfig(ctx, info, optional): Promise<HelixConfig>;
@@ -0,0 +1,69 @@
1
+ /*
2
+ * Copyright 2021 Adobe. All rights reserved.
3
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License. You may obtain a copy
5
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+ *
7
+ * Unless required by applicable law or agreed to in writing, software distributed under
8
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ * OF ANY KIND, either express or implied. See the License for the specific language
10
+ * governing permissions and limitations under the License.
11
+ */
12
+ import { logLevelForStatusCode, propagateStatusCode } from '@adobe/helix-shared-utils';
13
+ import { fetchS3 } from './fetch-s3.js';
14
+
15
+ /**
16
+ * Checks if the response is valid and returns the helix config.
17
+ *
18
+ * @param {Logger} log logger
19
+ * @param {Response} response content response from the storage
20
+ * @param {string} key storage key (logging information)
21
+ * @param {string} type type of storage (logging information
22
+ * @returns {Promise<HelixConfig>} the index config or null
23
+ */
24
+ async function handleResponse(log, response, key, type) {
25
+ const text = await response.text();
26
+ if (response.ok) {
27
+ const config = JSON.parse(text);
28
+ // set contentbus id, if present in header
29
+ const cbid = response.headers.get('x-contentbus-id');
30
+ if (cbid) {
31
+ // todo: eventually parse the header properly
32
+ config.fstab.data.mountpoints[0].contentBusId = cbid.substring(2);
33
+ }
34
+ return config;
35
+ }
36
+
37
+ if (response.status === 404) {
38
+ return null;
39
+ }
40
+
41
+ log[logLevelForStatusCode(response.status)](`Invalid response (${response.status}) when fetching helix-config from ${type} ${key}`);
42
+ const err = new Error(`Unable to fetch helix-config: ${response.status} ${text}`);
43
+ err.status = propagateStatusCode(response.status);
44
+ throw err;
45
+ }
46
+
47
+ /**
48
+ * Retrieves the helix-config.json which is an aggregate from fstab.yaml and head.html.
49
+ *
50
+ * @param {AdminContext} ctx the context
51
+ * @param {PathInfo} info path info
52
+ * @param {boolean} optional if {@code true} returns null if not found
53
+ * @returns {Promise<HelixConfig>} the helix-config or {@code null} if optional and not found.
54
+ */
55
+ export async function fetchHelixConfig(ctx, info, optional) {
56
+ const { attributes, log } = ctx;
57
+ const { owner, repo, ref } = info;
58
+
59
+ if (!('helixConfig' in attributes)) {
60
+ const key = `${owner}/${repo}/${ref}/helix-config.json`;
61
+ const response = await fetchS3(ctx, 'helix-code-bus', key);
62
+ attributes.helixConfig = await handleResponse(log, response, key, 'code-bus');
63
+ }
64
+
65
+ if (attributes.helixConfig || optional) {
66
+ return attributes.helixConfig;
67
+ }
68
+ throw Error(`no helix-config for ${owner}/${repo}/${ref}`);
69
+ }
package/src/index.d.ts CHANGED
@@ -13,6 +13,7 @@ import { OneDrive } from '@adobe/helix-onedrive-support';
13
13
  import { UniversalContext } from '@adobe/helix-universal';
14
14
  import { ProjectConfig } from './fetch-config';
15
15
  import { ConfigAll } from "./fetch-config-all";
16
+ import {HelixConfig} from "../types/helix-config";
16
17
 
17
18
  declare interface AuthInfo {}
18
19
  declare interface MountConfig {}
@@ -27,6 +28,7 @@ export * from './fetch-crontab';
27
28
  export * from './fetch-fstab';
28
29
  export * from './fetch-ignore';
29
30
  export * from './fetch-index';
31
+ export * from './fetch-helix-config';
30
32
  export * from './fetch-s3';
31
33
  export * from './fetch-sitemap';
32
34
  export * from './flatJson2Object';
@@ -202,9 +204,14 @@ export declare interface ContextAttributes {
202
204
  notifier?:object;
203
205
 
204
206
  /**
205
- * combined config
207
+ * combined config (content)
206
208
  */
207
209
  configAll?:ConfigAll;
210
+
211
+ /**
212
+ * combined helix-config (code)
213
+ */
214
+ helixConfig?:HelixConfig;
208
215
  }
209
216
 
210
217
  export declare interface AdminContext extends UniversalContext {
package/src/index.js CHANGED
@@ -17,6 +17,7 @@ export * from './fetch-crontab.js';
17
17
  export * from './fetch-fstab.js';
18
18
  export * from './fetch-ignore.js';
19
19
  export * from './fetch-index.js';
20
+ export * from './fetch-helix-config.js';
20
21
  export * from './fetch-s3.js';
21
22
  export * from './fetch-sitemap.js';
22
23
  export * from './flatJson2Object.js';
@@ -0,0 +1,65 @@
1
+ {
2
+ "meta:license": [
3
+ "Copyright 2023 Adobe. All rights reserved.",
4
+ "This file is licensed to you under the Apache License, Version 2.0 (the \"License\");",
5
+ "you may not use this file except in compliance with the License. You may obtain a copy",
6
+ "of the License at http://www.apache.org/licenses/LICENSE-2.0",
7
+ "",
8
+ "Unless required by applicable law or agreed to in writing, software distributed under",
9
+ "the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS",
10
+ "OF ANY KIND, either express or implied. See the License for the specific language",
11
+ "governing permissions and limitations under the License."
12
+ ],
13
+ "$id": "https://ns.adobe.com/helix/config/helix",
14
+ "$schema": "http://json-schema.org/draft-07/schema#",
15
+ "title": "HelixConfig",
16
+ "description": "Internal configuration aggregate consisting of fstab.yaml and head.html",
17
+ "type": "object",
18
+ "properties": {
19
+ "fstab": {
20
+ "type": "object",
21
+ "description": "The embedded fstab.yaml",
22
+ "properties": {
23
+ "lastModified": {
24
+ "description": "The last modified date",
25
+ "type": "string"
26
+ },
27
+ "data": {
28
+ "$ref": "./mountconfig.schema.json"
29
+ }
30
+ },
31
+ "required": [
32
+ "data",
33
+ "lastModified"
34
+ ],
35
+ "additionalProperties": false
36
+ },
37
+ "head": {
38
+ "type": "object",
39
+ "description": "The embedded head.html",
40
+ "properties": {
41
+ "lastModified": {
42
+ "description": "The last modified date",
43
+ "type": "string"
44
+ },
45
+ "data": {
46
+ "type": "object",
47
+ "properties": {
48
+ "html": {
49
+ "type": "string",
50
+ "description": "The contents of the head.html"
51
+ }
52
+ },
53
+ "additionalProperties": false
54
+ },
55
+ "additionalProperties": false
56
+ },
57
+ "required": [
58
+ "data",
59
+ "lastModified"
60
+ ],
61
+ "additionalProperties": false
62
+ }
63
+ },
64
+ "additionalProperties": false
65
+ }
@@ -0,0 +1,38 @@
1
+ {
2
+ "meta:license": [
3
+ "Copyright 2019 Adobe. All rights reserved.",
4
+ "This file is licensed to you under the Apache License, Version 2.0 (the \"License\");",
5
+ "you may not use this file except in compliance with the License. You may obtain a copy",
6
+ "of the License at http://www.apache.org/licenses/LICENSE-2.0",
7
+ "",
8
+ "Unless required by applicable law or agreed to in writing, software distributed under",
9
+ "the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS",
10
+ "OF ANY KIND, either express or implied. See the License for the specific language",
11
+ "governing permissions and limitations under the License."
12
+ ],
13
+ "$id": "https://ns.adobe.com/helix/shared/fstab",
14
+ "$schema": "http://json-schema.org/draft-07/schema#",
15
+ "type": "object",
16
+ "title": "MountConfig",
17
+ "description": "Defines a mapping between mount points and source URLs. Mount points **must** start with a slash (`/`) but may not end with one.",
18
+ "properties": {
19
+ "mountpoints": {
20
+ "type": "array",
21
+ "items": {
22
+ "$ref": "./mountpoint.schema.json"
23
+ }
24
+ },
25
+ "folders": {
26
+ "type": "object",
27
+ "description": "Mapping from subtrees to single sources for catch-all folder support.",
28
+ "patternProperties": {
29
+ "^/.*[^/]$": {
30
+ "type": "string"
31
+ }
32
+ },
33
+ "additionalProperties": false
34
+ }
35
+ },
36
+ "additionalProperties": false,
37
+ "required": ["mountpoints"]
38
+ }
@@ -0,0 +1,56 @@
1
+ {
2
+ "meta:license": [
3
+ "Copyright 2019 Adobe. All rights reserved.",
4
+ "This file is licensed to you under the Apache License, Version 2.0 (the \"License\");",
5
+ "you may not use this file except in compliance with the License. You may obtain a copy",
6
+ "of the License at http://www.apache.org/licenses/LICENSE-2.0",
7
+ "",
8
+ "Unless required by applicable law or agreed to in writing, software distributed under",
9
+ "the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS",
10
+ "OF ANY KIND, either express or implied. See the License for the specific language",
11
+ "governing permissions and limitations under the License."
12
+ ],
13
+ "$id": "https://ns.adobe.com/helix/shared/mountpoint",
14
+ "$schema": "http://json-schema.org/draft-07/schema#",
15
+ "title": "MountPoint",
16
+ "description": "Defines the target URL where content should be retrieved from.",
17
+ "type": "object",
18
+ "required": [
19
+ "url"
20
+ ],
21
+ "properties": {
22
+ "path": {
23
+ "type": "string",
24
+ "description": "The mount path"
25
+ },
26
+ "url": {
27
+ "type": "string",
28
+ "format": "uri"
29
+ },
30
+ "type": {
31
+ "type": "string",
32
+ "description": "mountpoint type",
33
+ "enum": ["onedrive", "google", "markup"]
34
+ },
35
+ "suffix": {
36
+ "type": "string",
37
+ "description": "suffix for markup type"
38
+ },
39
+ "credentials": {
40
+ "type": "array",
41
+ "description": "encrypted credentials.",
42
+ "items": {
43
+ "type": "string"
44
+ }
45
+ },
46
+ "tenantId": {
47
+ "type": "string",
48
+ "description": "Onedrive tenant id. If missing, it is computed from url."
49
+ },
50
+ "contentBusId": {
51
+ "type": "string",
52
+ "description": "computed content-bus id."
53
+ }
54
+ },
55
+ "additionalProperties": false
56
+ }
@@ -48,6 +48,11 @@
48
48
  "type": "string",
49
49
  "description": "Production host use by the slack bot to display project information."
50
50
  },
51
+ "blueprint": {
52
+ "type": "string",
53
+ "description": "configuration blueprint repository in the owner/repo format.",
54
+ "examples": [ "adobe/helix-website" ]
55
+ },
51
56
  "slack": {
52
57
  "description": "the slack teamId/channelID(s) where the slack bot is used.",
53
58
  "oneOf": [
@@ -0,0 +1,93 @@
1
+ /*
2
+ * Copyright 2023 Adobe. All rights reserved.
3
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License. You may obtain a copy
5
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+ *
7
+ * Unless required by applicable law or agreed to in writing, software distributed under
8
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ * OF ANY KIND, either express or implied. See the License for the specific language
10
+ * governing permissions and limitations under the License.
11
+ */
12
+
13
+ // NOTE: this file is autogenerated via 'npm run docs:types'
14
+ // note that the MountConfig here slightly differs from the one in '@adobe/helix-shared-config'
15
+ // by adding the contentBusId to the mountpoints
16
+
17
+ /**
18
+ * Internal configuration aggregate consisting of fstab.yaml and head.html
19
+ */
20
+ export interface HelixConfig {
21
+ /**
22
+ * The embedded fstab.yaml
23
+ */
24
+ fstab?: {
25
+ /**
26
+ * The last modified date
27
+ */
28
+ lastModified: string;
29
+ data: MountConfig;
30
+ };
31
+ /**
32
+ * The embedded head.html
33
+ */
34
+ head?: {
35
+ /**
36
+ * The last modified date
37
+ */
38
+ lastModified: string;
39
+ data: {
40
+ /**
41
+ * The contents of the head.html
42
+ */
43
+ html?: string;
44
+ };
45
+ additionalProperties?: false;
46
+ };
47
+ }
48
+ /**
49
+ * Defines a mapping between mount points and source URLs. Mount points **must** start with a slash (`/`) but may not end with one.
50
+ */
51
+ export interface MountConfig {
52
+ mountpoints: MountPoint[];
53
+ /**
54
+ * Mapping from subtrees to single sources for catch-all folder support.
55
+ */
56
+ folders?: {
57
+ /**
58
+ * This interface was referenced by `undefined`'s JSON-Schema definition
59
+ * via the `patternProperty` "^/.*[^/]$".
60
+ */
61
+ [k: string]: string;
62
+ };
63
+ }
64
+ /**
65
+ * Defines the target URL where content should be retrieved from.
66
+ */
67
+ export interface MountPoint {
68
+ /**
69
+ * The mount path
70
+ */
71
+ path?: string;
72
+ url: string;
73
+ /**
74
+ * mountpoint type
75
+ */
76
+ type?: 'onedrive' | 'google' | 'markup';
77
+ /**
78
+ * suffix for markup type
79
+ */
80
+ suffix?: string;
81
+ /**
82
+ * encrypted credentials.
83
+ */
84
+ credentials?: string[];
85
+ /**
86
+ * Onedrive tenant id. If missing, it is computed from url.
87
+ */
88
+ tenantId?: string;
89
+ /**
90
+ * computed content-bus id.
91
+ */
92
+ contentBusId?: string;
93
+ }
@@ -29,6 +29,10 @@ export interface ProjectConfig {
29
29
  * Production host use by the slack bot to display project information.
30
30
  */
31
31
  host?: string;
32
+ /**
33
+ * configuration blueprint repository in the owner/repo format.
34
+ */
35
+ blueprint?: string;
32
36
  /**
33
37
  * the slack teamId/channelID(s) where the slack bot is used.
34
38
  */