Skip to content

feat: Save diagram YAML content as PNG metadata and add extract CLI command - #294

Open
herley-shaori wants to merge 1 commit into
awslabs:mainfrom
herley-shaori:feat/png-metadata
Open

feat: Save diagram YAML content as PNG metadata and add extract CLI command#294
herley-shaori wants to merge 1 commit into
awslabs:mainfrom
herley-shaori:feat/png-metadata

Conversation

@herley-shaori

Copy link
Copy Markdown
Contributor

Summary

This PR adds support for embedding the diagram-as-code YAML configuration inside the generated PNG image as metadata, and adds an extract subcommand to the CLI to retrieve it. This resolves #258.

Rationale

Currently, when diagram images are uploaded to wikis, blogs, or other platforms, it is difficult to find the original YAML code used to generate them if it is not explicitly attached or tracked. Storing the configuration directly inside the image metadata (similar to how PlantUML works) allows seamless retrieval of the source design.

Changes

  1. PNG Metadata Chunk Injection: Implemented manual parsing of PNG bytes to inject a standard tEXt chunk right after the IHDR chunk. The chunk uses the keyword awsdac and stores a base64-encoded representation of the source YAML.
  2. Metadata Extraction CLI Subcommand: Added an extract subcommand to awsdac to scan PNG chunks, locate the awsdac metadata chunk, base64-decode the content, and output the original YAML to stdout.
  3. YAML Preservation:
    • For DAC YAML files, the rendered/processed YAML is embedded.
    • For CloudFormation templates, the template is marshaled back into equivalent DAC YAML and embedded.
  4. Unit Tests: Added comprehensive tests covering embedding, extraction, and validation of PNG metadata.

Verification

All unit tests and integration tests compile and pass successfully:

go test ./...

Manual testing verified:

# Build the binary
go build -o awsdac cmd/awsdac/main.go

# Generate diagram with YAML metadata embedded
./awsdac examples/span-resources.yaml -o test_output.png -f

# Extract metadata
./awsdac extract test_output.png

The extraction successfully prints the exact YAML contents of the original diagram design file.

…ommand

- Implement PNG chunk parser and writer in internal/ctl/metadata.go to embed base64-encoded YAML in standard tEXt chunks.
- Store rendered/processed YAML content in CreateOptions during diagram generation.
- Encode and write PNG files with embedded metadata chunks in createDiagram.
- Add 'extract' subcommand to awsdac CLI to decode and print embedded YAML metadata from generated PNG images.
- Add unit tests for embedding, extraction, and validation of PNG metadata.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Save diagram content as metadata of the PNG file

1 participant