chore: initial commit — AdonisJS v7 TR-069 ACS
- Docker infrastructure (Dockerfile, docker-compose.yml, genieacs-sim) - AdonisJS v7 app with Inertia.js + Vue 3 - MongoDB integration - CWMP/TR-069 state machine engine - Configuration engine with compliance tracking - Branding: ADAM ACS (favicon, navbar, locales) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
commit
d1c65dbf1e
164 files changed
+29127
No files matched your search
@@ -0,0 +1,38 @@
|
||||
import { createHash } from 'node:crypto'
|
||||
import type { Configuration } from '../domain/configuration/configuration.js'
|
||||
|
||||
/**
|
||||
* Computes a 12-character hex content hash of a Configuration's desired state.
|
||||
* The hash is based on the sorted desiredParameters and firmwareTarget.
|
||||
*/
|
||||
export function computeContentHash(config: Configuration): string {
|
||||
const payload = JSON.stringify({
|
||||
desiredParameters: config.desiredParameters
|
||||
.slice()
|
||||
.sort((a, b) => a.name.localeCompare(b.name)),
|
||||
firmwareTarget: config.firmwareTarget || null,
|
||||
})
|
||||
return createHash('sha256').update(payload).digest('hex').substring(0, 12)
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the ProvisioningCode string for a Configuration.
|
||||
* Format: `<identifier>(v<version>)-<hash12>`
|
||||
* Example: `BM632w-standard(v1.0.1)-a1b2c3d4e5f6`
|
||||
*/
|
||||
export function buildProvisioningCode(config: Configuration): string {
|
||||
const hash = computeContentHash(config)
|
||||
return `${config.identifier}(v${config.version})-${hash}`
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses an existing ProvisioningCode string.
|
||||
* Returns null if the format is invalid.
|
||||
*/
|
||||
export function parseProvisioningCode(
|
||||
code: string
|
||||
): { identifier: string; version: string; hash: string } | null {
|
||||
const match = code.match(/^(.+)\(v(.+)\)-([a-f0-9]{12})$/)
|
||||
if (!match) return null
|
||||
return { identifier: match[1], version: match[2], hash: match[3] }
|
||||
}
|
||||
Reference in new issue
Block a user