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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ Skillbook and Promptbook load JSON over `fetch`, so use a local server (opening
- **UUID Generator**
- **PEM / SSH Viewer**
- **CIDR Calculator** — IPv4 network, broadcast, mask, host range
- **Azure Resource ID** — parse ARM IDs into subscription, RG, type, name

### Time

Expand Down
1 change: 1 addition & 0 deletions assets/site.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
{ id: "uuid", path: "uuid/", name: "UUID Generator", blurb: "Create v4 UUIDs in bulk and copy them.", cat: "Security" },
{ id: "cert", path: "cert/", name: "PEM / SSH Viewer", blurb: "Inspect PEM blocks and SSH key fingerprints.", cat: "Security" },
{ id: "cidr", path: "cidr/", name: "CIDR Calculator", blurb: "Network, broadcast, mask, and host range from an IPv4 CIDR.", cat: "Security" },
{ id: "azure-id", path: "azure-id/", name: "Azure Resource ID", blurb: "Split subscription, resource group, type, and name from an ARM ID.", cat: "Security" },
{ id: "time", path: "time/", name: "Time Overlay", blurb: "Compare working hours across time zones.", cat: "Time" },
{ id: "timestamp", path: "timestamp/", name: "Unix Timestamp", blurb: "Convert Unix time to human dates and back.", cat: "Time" },
{ id: "cron", path: "cron/", name: "Cron Explainer", blurb: "Read cron expressions and preview next runs.", cat: "Time" },
Expand Down
153 changes: 153 additions & 0 deletions azure-id/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
(function () {
var GUID_RE = /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/;
function isGuid(value) {
return GUID_RE.test(String(value || "").trim());
}
function parseAzureResourceId(input) {
var raw = String(input || "").trim();
if (!raw) throw new Error("Paste an Azure resource ID");
var path = raw;
if ((path.charAt(0) === '"' && path.charAt(path.length - 1) === '"') ||
(path.charAt(0) === "'" && path.charAt(path.length - 1) === "'")) {
path = path.slice(1, -1).trim();
}
if (path.charAt(0) !== "/") throw new Error("Resource ID must start with /");
var segments = path.split("/").filter(Boolean);
if (!segments.length) throw new Error("Resource ID has no segments");
var result = {
input: raw,
normalized: "/" + segments.join("/"),
kind: "unknown",
subscriptionId: null,
resourceGroup: null,
providers: [],
resourceType: null,
name: null,
parent: null,
segments: segments.slice()
};
var i = 0;
function lower(s) { return String(s).toLowerCase(); }
if (lower(segments[0]) === "subscriptions") {
if (segments.length < 2) throw new Error("Missing subscription ID");
result.subscriptionId = segments[1];
if (!isGuid(result.subscriptionId)) throw new Error("Subscription ID should be a GUID");
i = 2;
result.kind = "subscription";
if (i < segments.length && lower(segments[i]) === "resourcegroups") {
if (i + 1 >= segments.length) throw new Error("Missing resource group name");
result.resourceGroup = segments[i + 1];
i += 2;
result.kind = "resourceGroup";
}
} else if (lower(segments[0]) === "providers") {
i = 0;
result.kind = "providerScoped";
} else {
throw new Error("Expected /subscriptions/{id}/... or /providers/{namespace}/...");
}
if (i < segments.length) {
if (lower(segments[i]) !== "providers") {
throw new Error('Unexpected segment "' + segments[i] + '" (expected providers)');
}
if (i + 1 >= segments.length) throw new Error("Missing provider namespace");
var namespace = segments[i + 1];
i += 2;
var typeParts = [];
var nameParts = [];
var expectingType = true;
while (i < segments.length) {
if (expectingType) typeParts.push(segments[i]);
else nameParts.push(segments[i]);
expectingType = !expectingType;
i += 1;
}
if (!typeParts.length) throw new Error("Provider present but resource type is missing");
if (typeParts.length !== nameParts.length) {
throw new Error("Each resource type needs a matching name segment");
}
result.providers = [{ namespace: namespace, types: typeParts.slice(), names: nameParts.slice() }];
result.resourceType = namespace + "/" + typeParts.join("/");
result.name = nameParts[nameParts.length - 1];
if (nameParts.length > 1) {
result.parent = {
resourceType: namespace + "/" + typeParts.slice(0, -1).join("/"),
name: nameParts[nameParts.length - 2]
};
}
result.kind = "resource";
}
return result;
}
function formatAzureIdSummary(info) {
var lines = ["Normalized: " + info.normalized, "Kind: " + info.kind];
if (info.subscriptionId) lines.push("Subscription: " + info.subscriptionId);
if (info.resourceGroup) lines.push("Resource group: " + info.resourceGroup);
if (info.resourceType) lines.push("Type: " + info.resourceType);
if (info.name) lines.push("Name: " + info.name);
if (info.parent) lines.push("Parent: " + info.parent.resourceType + " / " + info.parent.name);
if (info.providers.length) {
var p = info.providers[0];
lines.push("Provider: " + p.namespace);
for (var i = 0; i < p.types.length; i++) {
lines.push(" " + p.types[i] + " = " + p.names[i]);
}
}
return lines.join("\n");
}
function esc(s) {
return String(s)
.replace(/&/g, "&amp;")
.replace(/</g, "&lt;")
.replace(/>/g, "&gt;")
.replace(/"/g, "&quot;");
}
function card(title, value) {
return '<div class="tool-card" style="cursor:default;"><h3>' + esc(title) +
'</h3><p style="font-family:ui-monospace,monospace;word-break:break-all;">' +
esc(value) + "</p></div>";
}
function ready() {
var input = document.getElementById("idInput");
var output = document.getElementById("output");
var status = document.getElementById("status");
var cards = document.getElementById("cards");
function render(info) {
output.value = formatAzureIdSummary(info);
var bits = [];
if (info.subscriptionId) bits.push(card("Subscription", info.subscriptionId));
if (info.resourceGroup) bits.push(card("Resource group", info.resourceGroup));
if (info.resourceType) bits.push(card("Type", info.resourceType));
if (info.name) bits.push(card("Name", info.name));
if (info.parent) bits.push(card("Parent", info.parent.resourceType + " / " + info.parent.name));
bits.push(card("Kind", info.kind));
cards.innerHTML = bits.join("");
RMKR.setStatus(status, "Parsed " + info.kind + ".", "ok");
}
function run() {
try { render(parseAzureResourceId(input.value)); }
catch (e) {
cards.innerHTML = "";
output.value = "";
RMKR.setStatus(status, e.message || String(e), "err");
}
}
document.getElementById("run").onclick = run;
document.getElementById("clear").onclick = function () {
input.value = "";
output.value = "";
cards.innerHTML = "";
RMKR.setStatus(status, "", "");
input.focus();
};
document.getElementById("copyOut").onclick = function () {
var v = output.value;
if (!v) return RMKR.setStatus(status, "Parse first.", "err");
RMKR.copy(v).then(function () { RMKR.setStatus(status, "Copied.", "ok"); });
};
input.addEventListener("keydown", function (e) { if (e.key === "Enter") run(); });
run();
}
if (document.readyState === "loading") document.addEventListener("DOMContentLoaded", ready);
else ready();
})();
32 changes: 32 additions & 0 deletions azure-id/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Azure Resource ID | RMKR Toolkit</title>
<meta name="description" content="Parse Azure ARM resource IDs into subscription, resource group, type, and name — locally in the browser.">
<link rel="icon" type="image/svg+xml" href="../assets/favicon.svg">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;600;700;900&display=swap" rel="stylesheet">
<link rel="stylesheet" href="../assets/site.css">
<script src="../assets/site.js" defer></script>
</head>
<body data-root="../" data-tool="azure-id">
<main class="wrap page-main" id="main">
<h1 class="page-title">Azure Resource ID</h1>
<p class="page-lead">Paste an ARM resource ID. Split subscription, resource group, provider, type, and name without leaving this tab.</p>
<div class="toolbar">
<label for="idInput" style="margin:0;">Resource ID</label>
<input id="idInput" type="text" value="/subscriptions/11111111-1111-1111-1111-111111111111/resourceGroups/demo-rg/providers/Microsoft.Compute/virtualMachines/web-01" placeholder="/subscriptions/{guid}/resourceGroups/{rg}/providers/..." spellcheck="false" style="min-width:12rem;flex:1;">
<button class="btn btn-gold" type="button" id="run">Parse</button>
<button class="btn btn-ghost" type="button" id="copyOut">Copy</button>
<button class="btn btn-ghost" type="button" id="clear">Clear</button>
</div>
<p class="status" id="status" role="status"></p>
<div class="tool-grid" id="cards" style="margin-top:1rem;"></div>
<label for="output">Summary</label>
<textarea id="output" spellcheck="false" readonly rows="14"></textarea>
</main>
<script src="app.js"></script>
</body>
</html>
149 changes: 149 additions & 0 deletions scripts/azure-id-lib.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
/**
* Azure Resource ID helpers for the toolkit parser.
* Pure functions — safe from Node tests and the browser.
*/

const GUID_RE =
/^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/;

export function isGuid(value) {
return GUID_RE.test(String(value || "").trim());
}

/**
* Parse a full or partial Azure resource ID into structured parts.
* Accepts subscription, resource group, provider, and nested type segments.
*/
export function parseAzureResourceId(input) {
const raw = String(input || "").trim();
if (!raw) throw new Error("Paste an Azure resource ID");

let path = raw;
// Allow accidental wrapping quotes or ARM ID prefix noise
if (
(path.startsWith('"') && path.endsWith('"')) ||
(path.startsWith("'") && path.endsWith("'"))
) {
path = path.slice(1, -1).trim();
}
if (!path.startsWith("/")) {
throw new Error("Resource ID must start with /");
}

const segments = path.split("/").filter(Boolean);
if (!segments.length) throw new Error("Resource ID has no segments");

const result = {
input: raw,
normalized: "/" + segments.join("/"),
kind: "unknown",
subscriptionId: null,
resourceGroup: null,
providers: [],
resourceType: null,
name: null,
parent: null,
segments: segments.slice(),
};

let i = 0;
const lower = (s) => String(s).toLowerCase();

if (lower(segments[0]) === "subscriptions") {
if (segments.length < 2) throw new Error("Missing subscription ID");
result.subscriptionId = segments[1];
if (!isGuid(result.subscriptionId)) {
throw new Error("Subscription ID should be a GUID");
}
i = 2;
result.kind = "subscription";

if (i < segments.length && lower(segments[i]) === "resourcegroups") {
if (i + 1 >= segments.length) throw new Error("Missing resource group name");
result.resourceGroup = segments[i + 1];
i += 2;
result.kind = "resourceGroup";
}
} else if (lower(segments[0]) === "providers") {
// Tenant- or management-group scoped
i = 0;
result.kind = "providerScoped";
} else {
throw new Error(
"Expected /subscriptions/{id}/... or /providers/{namespace}/..."
);
}

if (i < segments.length) {
if (lower(segments[i]) !== "providers") {
throw new Error(`Unexpected segment "${segments[i]}" (expected providers)`);
}
if (i + 1 >= segments.length) throw new Error("Missing provider namespace");

const namespace = segments[i + 1];
i += 2;

const typeParts = [];
const nameParts = [];
let expectingType = true;
while (i < segments.length) {
if (expectingType) {
typeParts.push(segments[i]);
expectingType = false;
} else {
nameParts.push(segments[i]);
expectingType = true;
}
i += 1;
}
if (!typeParts.length) {
throw new Error("Provider present but resource type is missing");
}
if (typeParts.length !== nameParts.length) {
throw new Error("Each resource type needs a matching name segment");
}

result.providers = [
{
namespace,
types: typeParts.slice(),
names: nameParts.slice(),
},
];
result.resourceType = namespace + "/" + typeParts.join("/");
result.name = nameParts[nameParts.length - 1];
if (nameParts.length > 1) {
result.parent = {
resourceType: namespace + "/" + typeParts.slice(0, -1).join("/"),
name: nameParts[nameParts.length - 2],
};
}
result.kind = "resource";
}

return result;
}

export function formatAzureIdSummary(info) {
const lines = [
`Normalized: ${info.normalized}`,
`Kind: ${info.kind}`,
];
if (info.subscriptionId) lines.push(`Subscription: ${info.subscriptionId}`);
if (info.resourceGroup) lines.push(`Resource group: ${info.resourceGroup}`);
if (info.resourceType) lines.push(`Type: ${info.resourceType}`);
if (info.name) lines.push(`Name: ${info.name}`);
if (info.parent) {
lines.push(
`Parent: ${info.parent.resourceType} / ${info.parent.name}`
);
}
if (info.providers.length) {
const p = info.providers[0];
lines.push(`Provider: ${p.namespace}`);
for (let i = 0; i < p.types.length; i++) {
lines.push(` ${p.types[i]} = ${p.names[i]}`);
}
}
return lines.join("\n");
}
Loading
Loading