mdmassets

package
v0.24.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 24, 2026 License: MIT Imports: 25 Imported by: 0

Documentation

Overview

Package mdmassets loads the MDM assets tree that obot-sentry's build publishes and assembles the per-configuration ZIP an admin downloads. The manifest is the whole contract: it declares the platforms (identity + display info), the configurations (per platform+OS, with their rendered-markdown instructions template and asset files), and the field schema the admin form renders from — obot holds no platform-specific knowledge of its own.

A source directory or tarball contains manifest.json plus its referenced files. The controller imports that source into immutable database bundles; HTTP replicas open those bundles through this package and never serve from the source path. The format is defined by these manifest types and produced by obot-sentry's build/mdm-assets.sh.

Index

Constants

View Source
const SchemaVersion = "v1"

SchemaVersion is the manifest format this loader understands. An assets tree declaring anything else is rejected so a newer format can't be misread by an older server.

Variables

This section is empty.

Functions

func ArtifactSlug

func ArtifactSlug(platform, osName string) string

ArtifactSlug returns the stable URL segment for a platform/OS artifact. NewFS rejects manifests whose targets collide after normalization.

func Import

func Import(ctx context.Context, source string) ([]byte, error)

Import reads source, validates the complete assets snapshot, and normalizes it into deterministic archive bytes. HTTP(S) sources are tar archives. Local sources may be either the existing assets directory or a tar archive.

func RedactSource

func RedactSource(source string) string

RedactSource returns a source suitable for status and UI display. Local paths are unchanged. URL credentials, query parameters, and fragments are never exposed, including when a malformed HTTP URL cannot be parsed safely.

Types

type Loader

type Loader struct {
	// contains filtered or unexported fields
}

Loader validates and renders files from one immutable MDM asset bundle.

func NewFS

func NewFS(files fs.FS) (*Loader, error)

NewFS loads and validates an assets snapshot rooted at files. Callers must not mutate files after this function returns.

func OpenArchive

func OpenArchive(content []byte) (*Loader, error)

OpenArchive validates and opens canonical database bundle content without extracting it to disk.

func (*Loader) CompleteValues

func (l *Loader) CompleteValues(values map[string]any) error

CompleteValues drops nulls (null means unset), fills schema defaults, and validates values in place — every rule comes from the manifest. The returned error is safe to surface to the admin.

func (*Loader) Find

func (l *Loader) Find(platform, osName string) (types.MDMAssetConfiguration, error)

Find returns the configuration for (platform, osName). An empty osName matches when the platform has exactly one configuration. The returned error names what is available and is safe to surface to the admin.

func (*Loader) Manifest

func (l *Loader) Manifest() types.MDMAssetManifest

Manifest returns a detached copy of the validated manifest for persistence and API discovery without reopening the archive.

func (*Loader) RenderAll

func (l *Loader) RenderAll(values map[string]any) ([]RenderedArtifact, error)

RenderAll completes and validates values once, then renders every target in the immutable bundle. It returns no partial result if any target fails.

func (*Loader) RenderInstructions

func (l *Loader) RenderInstructions(c types.MDMAssetConfiguration, values map[string]any) (string, error)

RenderInstructions renders the configuration's instructions template with values into the markdown setup guide clients display.

func (*Loader) ValidateTemplates

func (l *Loader) ValidateTemplates(c types.MDMAssetConfiguration, values map[string]any) error

ValidateTemplates executes every rendered asset against completed values without copying binary assets. This catches missing template inputs before a deployment is saved instead of deferring the failure until download.

func (*Loader) Zip

func (l *Loader) Zip(w io.Writer, c types.MDMAssetConfiguration, values map[string]any) error

Zip writes the configuration's download to w: assets ending in .tmpl are rendered as Go text/templates against values (suffix stripped), everything else is copied verbatim. Names in the ZIP are base names — the assemble step guarantees they don't collide.

type RenderedArtifact

type RenderedArtifact struct {
	Platform     string
	OS           string
	Instructions string
	Content      []byte
}

RenderedArtifact contains one fully rendered platform/OS download. Callers persist Content privately and expose only the platform, OS, and instructions.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL