Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .github/workflows/lighthouse.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:

steps:
- name: Check out repository
uses: actions/checkout@v6
uses: actions/checkout@v7

- name: Verify embedded ApplicationSet Studio runtime
run: python3 scripts/embed-applicationset-studio-runtime.py --check
Expand All @@ -33,6 +33,9 @@ jobs:
- name: Test JSON and YAML comparison
run: node --test scripts/json-diff.test.cjs

- name: Test YAML parser compatibility
run: node --test scripts/yaml-compatibility.test.cjs

- name: Test timestamp parsing and comparison
run: node --test scripts/timestamp-converter.test.cjs

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/redirects.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
timeout-minutes: 10
steps:
- name: Check out repository
uses: actions/checkout@v6
uses: actions/checkout@v7

- name: Check deployed redirects and canonical destinations
run: python3 scripts/check-redirects.py
8 changes: 4 additions & 4 deletions .github/workflows/terraform-modules.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ jobs:

steps:
- name: Check out repository
uses: actions/checkout@v6
uses: actions/checkout@v7

- name: Install JSON Schema validator
run: python3 -m pip install --disable-pip-version-check check-jsonschema==0.38.0
run: python3 -m pip install --disable-pip-version-check check-jsonschema==0.39.0

- name: Validate catalogue schema
run: check-jsonschema --schemafile terraform-modules/modules.schema.json terraform-modules/modules.json
Expand All @@ -59,10 +59,10 @@ jobs:

steps:
- name: Check out repository
uses: actions/checkout@v6
uses: actions/checkout@v7

- name: Install JSON Schema validator
run: python3 -m pip install --disable-pip-version-check check-jsonschema==0.38.0
run: python3 -m pip install --disable-pip-version-check check-jsonschema==0.39.0

- name: Refresh Registry and GitHub metadata
env:
Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ Git, or an SCM provider, and generated output should be verified with the
ApplicationSet controller before production use.

The Studio ships one embedded v1 browser runtime so it also works on enterprise
networks that block JavaScript file responses. It includes js-yaml 5.2.2. After
networks that block JavaScript file responses. It embeds the shared js-yaml
5.5.0 browser bundle from `yaml-formatter/vendor/`. After
changing `app.js` or upgrading the vendored parser, refresh and verify the page:

```sh
Expand All @@ -88,7 +89,7 @@ can copy or download the formatted result.

The shorter `/json-formatter/` alias redirects to this tool.

YAML parsing and serialization use the vendored `js-yaml` 4.1.0 browser
YAML parsing and serialization use the vendored `js-yaml` 5.5.0 browser
bundle, distributed under the MIT license included with the tool.

## JSON & YAML Diff Checker
Expand Down Expand Up @@ -153,7 +154,7 @@ snapshots, generates narrowly scoped RBAC drafts, and exports a Markdown review.
The explorer accepts multi-document YAML, JSON arrays, and Kubernetes `List`
objects. Parsing and analysis stay in the browser. Secret objects are rejected,
and users should never provide a kubeconfig, token, or other credentials. YAML
input uses the existing vendored `js-yaml` 4.1.0 bundle.
input uses the shared vendored `js-yaml` 5.5.0 bundle.

The random sample library demonstrates namespace read-only access, deployment
operations, sensitive cluster access, RBAC administration, aggregated
Expand Down
6 changes: 2 additions & 4 deletions argocd-applicationset-studio/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -799,11 +799,9 @@ spec:
if (text.length > MAX_INPUT_LENGTH) {
throw new Error(`${label} exceeds the 2 MB local preview limit.`);
}
const documents = [];
let documents;
try {
window.jsyaml.loadAll(text, (document) => {
if (document !== null && document !== undefined) documents.push(document);
}, YAML_LOAD_OPTIONS);
documents = window.jsyaml.loadAll(text, YAML_LOAD_OPTIONS).filter((document) => document != null);
} catch (error) {
const location = error.mark
? ` at line ${error.mark.line + 1}, column ${error.mark.column + 1}`
Expand Down
61 changes: 33 additions & 28 deletions argocd-applicationset-studio/index.html

Large diffs are not rendered by default.

32 changes: 0 additions & 32 deletions argocd-applicationset-studio/vendor/js-yaml-5.2.2.umd.min.js

This file was deleted.

21 changes: 0 additions & 21 deletions argocd-applicationset-studio/vendor/js-yaml.LICENSE

This file was deleted.

2 changes: 1 addition & 1 deletion json-diff/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@
const parsed = window.NativeDiff.parse(byId(`${side}-editor`).value, byId(`${side}-format`).value);
byId(`${side}-editor`).value = parsed.format === "json"
? JSON.stringify(parsed.documents[0], null, 2)
: parsed.documents.map((value) => window.jsyaml.dump(value, { schema: window.jsyaml.JSON_SCHEMA, lineWidth: -1, indent: 2 })).join("---\n");
: parsed.documents.map((value) => window.jsyaml.dump(value, { schema: window.NativeCubeYaml.coreSchema(window.jsyaml), lineWidth: -1, indent: 2 })).join("---\n");
byId(`${side}-format`).value = parsed.format;
fileVersions[side]++;
updateEditor(side);
Expand Down
8 changes: 5 additions & 3 deletions json-diff/diff.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
(function (root) {
"use strict";

const yamlSchemas = typeof module !== "undefined" && module.exports
? require("../yaml-formatter/schema.js")
: root.NativeCubeYaml;
const MAX_SOURCE = 1024 * 1024;
const MAX_DEPTH = 80;
const MAX_NODES = 50000;
Expand Down Expand Up @@ -96,9 +99,8 @@
documents = [parseJson(source)];
} else {
if (!yaml) throw new Error("The YAML parser could not load. Reload this page to try again.");
documents = yaml.loadAll(source, null, {
schema: yaml.JSON_SCHEMA,
onWarning(warning) { throw warning; },
documents = yaml.loadAll(source, {
schema: yamlSchemas.coreSchema(yaml),
});
if (!documents.length) throw new Error("No YAML document found.");
// An empty YAML document has the same value as an explicit null.
Expand Down
9 changes: 5 additions & 4 deletions json-diff/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,12 @@
<title>JSON Diff Checker – Compare JSON &amp; YAML Online | Native Cube</title>
<link rel="stylesheet" href="../yaml-formatter/styles.css?v=3" />
<link rel="stylesheet" href="./styles.css?v=6" />
<script src="../yaml-formatter/vendor/js-yaml.min.js?v=4.1.0" defer></script>
<script src="./diff.js?v=1" defer></script>
<script src="./source-map.js?v=1" defer></script>
<script src="../yaml-formatter/vendor/js-yaml.min.js?v=5.5.0" defer></script>
<script src="../yaml-formatter/schema.js?v=1" defer></script>
<script src="./diff.js?v=2" defer></script>
<script src="./source-map.js?v=2" defer></script>
<script src="./examples.js?v=1" defer></script>
<script src="./app.js?v=5" defer></script>
<script src="./app.js?v=6" defer></script>
<script type="application/ld+json">
[
{
Expand Down
154 changes: 113 additions & 41 deletions json-diff/source-map.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
(function (root) {
"use strict";

const yamlSchemas = typeof module !== "undefined" && module.exports
? require("../yaml-formatter/schema.js")
: root.NativeCubeYaml;
const pointer = (path, key) => `${path}/${String(key).replace(/~/g, "~0").replace(/\//g, "~1")}`;
const decode = (key) => key.replace(/~1/g, "/").replace(/~0/g, "~");

Expand Down Expand Up @@ -54,54 +57,123 @@
return [locations];
}

function yamlLocations(source, yaml) {
const stack = [];
const roots = [];
yaml.loadAll(source, null, {
schema: yaml.JSON_SCHEMA,
listener(event, state) {
if (event === "open") stack.push({ start: state.position, children: [] });
else {
const node = stack.pop();
Object.assign(node, { end: state.position, kind: state.kind, value: state.result });
if (stack.length) stack[stack.length - 1].children.push(node);
else roots.push(node);
}
function yamlMappingKeys(source, events, yaml) {
const map = yaml.legacyMapTag;
const maps = [];
const keysByMap = new WeakMap();
const recordingMap = {
...map,
create(tagName) {
const value = map.create(tagName);
const keys = [];
keysByMap.set(value, keys);
maps.push(keys);
return value;
},
addPair(value, key, item) {
// Let the same tag used by the loader resolve numeric and alias keys.
const field = Object.create(null);
const error = map.addPair(field, key, null);
if (error) return error;
const [name] = Object.keys(field);
keysByMap.get(value).push(name);
return map.addPair(value, name, item);
},
};
yaml.constructFromEvents(events, {
source,
schema: yamlSchemas.coreSchema(yaml).withTags(recordingMap),
});
function trimStart(start, end) {
while (start < end) {
if (/\s/.test(source[start])) start++;
else if (source[start] === "#") {
const newline = source.indexOf("\n", start);
start = newline < 0 ? end : newline + 1;
return maps;
}

function yamlLocations(source, yaml) {
const events = yaml.parseEvents(source);
const maps = yamlMappingKeys(source, events, yaml);
const type = yaml.EVENT_ID;
const style = yaml.SCALAR_STYLE;
const documents = [];
let index = 0;
let mapIndex = 0;
let cursor = 0;

function flowEnd(closer) {
let index = cursor;
while (index < source.length) {
if (/[\s,]/.test(source[index])) index++;
else if (source[index] === "#") {
while (index < source.length && !/[\r\n]/.test(source[index])) index++;
} else break;
}
return start;
return source[index] === closer ? index + 1 : cursor;
}
return roots.map((node) => {
const locations = new Map();
function visit(current, path, keyStart) {
const start = trimStart(current.start, current.end);
let end = current.end;
while (end > start && /\s/.test(source[end - 1])) end--;
locations.set(path, { start, end, keyStart: keyStart ?? start, alias: current.kind === null });
// js-yaml can wrap a flow collection while probing for a block mapping.
let children = current.children;
while (children.length === 1 && children[0].value === current.value && children[0].kind === current.kind) children = children[0].children;
if (current.kind === "mapping") {
for (let index = 0; index + 1 < children.length; index += 2) {
const key = children[index];
const value = children[index + 1];
visit(value, pointer(path, String(key.value)), trimStart(key.start, key.end));
}
} else if (current.kind === "sequence") {
children.forEach((child, index) => visit(child, pointer(path, index)));

function scalarStart(event) {
if (event.valueStart < 0) {
if (event.tagStart >= 0) return event.tagStart;
if (event.anchorStart >= 0) return event.anchorStart - 1;
return cursor;
}
if (event.style === style.SINGLE_QUOTED || event.style === style.DOUBLE_QUOTED) return event.valueStart - 1;
if (event.style === style.LITERAL_BLOCK || event.style === style.FOLDED_BLOCK) {
let lineEnd = event.valueStart;
while (lineEnd > 0 && /[\r\n]/.test(source[lineEnd - 1])) lineEnd--;
const lineStart = Math.max(source.lastIndexOf("\n", lineEnd - 1), source.lastIndexOf("\r", lineEnd - 1)) + 1;
const from = Math.max(cursor, lineStart, event.anchorEnd, event.tagEnd);
const header = source.indexOf(event.style === style.LITERAL_BLOCK ? "|" : ">", from);
if (header >= 0 && header < lineEnd) return header;
}
return event.valueStart;
}

function readNode(locations, path, keyStart) {
const event = events[index++];
let start;
let end;
if (event.type === type.ALIAS) {
start = event.anchorStart - 1;
end = event.anchorEnd;
} else if (event.type === type.SCALAR) {
start = scalarStart(event);
const quoted = event.style === style.SINGLE_QUOTED || event.style === style.DOUBLE_QUOTED;
end = event.valueEnd < 0 ? Math.max(start, event.anchorEnd, event.tagEnd) : event.valueEnd + Number(quoted);
} else {
start = event.start;
const mapping = event.type === type.MAPPING;
const keys = mapping ? maps[mapIndex++] : null;
const opening = mapping ? "{" : "[";
const flow = event.style === yaml.COLLECTION_STYLE.FLOW && source[start] === opening;
cursor = Math.max(cursor, start + Number(flow));
for (let item = 0; events[index].type !== type.POP; item++) {
const key = mapping ? readNode(locations, null) : null;
readNode(locations, path === null ? null : pointer(path, mapping ? keys[item] : item), key?.start);
}
index++;
end = flow ? flowEnd(mapping ? "}" : "]") : cursor;
}
visit(node, "");
return locations;
});

if (event.tagStart >= 0) start = Math.min(start, event.tagStart);
if (event.anchorStart >= 0) start = Math.min(start, event.anchorStart - 1);
cursor = Math.max(cursor, end);
while (end > start && /\s/.test(source[end - 1])) end--;
if (path !== null) locations.set(path, { start, end, keyStart: keyStart ?? start, alias: event.type === type.ALIAS });
return { start, end };
}

while (index < events.length) {
const document = events[index++];
const root = events[index];
if (document.explicitStart && root.type === type.SCALAR && root.valueStart < 0) {
const marker = /(?:^|[\r\n])---(?=\s|$)/g;
marker.lastIndex = Math.max(0, cursor - 1);
if (marker.test(source)) cursor = marker.lastIndex;
}
const locations = new Map();
readNode(locations, "");
index++;
documents.push(locations);
}
return documents;
}

// Build only after NativeDiff.parse has validated the input and its size limits.
Expand Down
7 changes: 3 additions & 4 deletions kubernetes-rbac-explorer/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

if (typeof document === "undefined") return;

const yamlSchema = window.jsyaml && window.NativeCubeYaml.configurationSchema(window.jsyaml);
const SUPPORTED_KINDS = new Set([
"Role",
"ClusterRole",
Expand Down Expand Up @@ -300,11 +301,9 @@ roleRef:
if (!text.trim()) throw new Error("Paste or choose RBAC YAML or JSON first.");
if (!window.jsyaml) throw new Error("The local YAML parser could not be loaded.");

const parsed = [];
let parsed;
try {
window.jsyaml.loadAll(text, (documentValue) => {
if (documentValue !== undefined && documentValue !== null) parsed.push(documentValue);
});
parsed = window.jsyaml.loadAll(text, { schema: yamlSchema }).filter((documentValue) => documentValue != null);
} catch (error) {
const location = error.mark
? ` at line ${error.mark.line + 1}, column ${error.mark.column + 1}`
Expand Down
5 changes: 3 additions & 2 deletions kubernetes-rbac-explorer/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,9 @@
<link rel="icon" href="/favicon.svg" type="image/svg+xml" />
<title>Kubernetes RBAC Explorer | Native Cube</title>
<link rel="stylesheet" href="./styles.css?v=2" />
<script src="../yaml-formatter/vendor/js-yaml.min.js?v=4.1.0" defer></script>
<script src="./app.js?v=2" defer></script>
<script src="../yaml-formatter/vendor/js-yaml.min.js?v=5.5.0" defer></script>
<script src="../yaml-formatter/schema.js?v=1" defer></script>
<script src="./app.js?v=3" defer></script>
<script type="application/ld+json">
[
{
Expand Down
6 changes: 5 additions & 1 deletion scripts/embed-applicationset-studio-runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,16 @@
ROOT = Path(__file__).resolve().parent.parent
PAGE_PATH = ROOT / "argocd-applicationset-studio/index.html"
RUNTIMES = {
"yaml-runtime-v1": ROOT / "argocd-applicationset-studio/vendor/js-yaml-5.2.2.umd.min.js",
"yaml-runtime-v1": ROOT / "yaml-formatter/vendor/js-yaml.min.js",
"applicationset-studio-runtime-v1": ROOT / "argocd-applicationset-studio/app.js",
}


def embed_runtime(page, runtime_id, source):
if runtime_id == "yaml-runtime-v1":
# The upstream bundle uses a literal NEL in its YAML escape table.
# Escaping it here keeps the inline script valid HTML.
source = source.replace(b"\xc2\x85", b"\\u0085")
opening = f'<script id="{runtime_id}">\n'.encode()
closing = b"\n </script>"
opening_index = page.find(opening)
Expand Down
Loading
Loading