Skip to content

[high] fix: naics, china-defence-universities and gsma-motif galaxy are never written by their generators - #1280

Open
elhoim wants to merge 1 commit into
MISP:mainfrom
elhoim:fix/generator-output-paths
Open

elhoim wants to merge 1 commit into
MISP:mainfrom
elhoim:fix/generator-output-paths

Conversation

@elhoim

@elhoim elhoim commented Aug 30, 2026

Copy link
Copy Markdown
Member

BLUF — Three generators never write the clusters and galaxy they claim to maintain, and say nothing

  • Problemgenerate_naics_clusters.py writes a misspelled naisc_cluster.json into the current directory, gen_defence_university.py writes china-defence-universities.json into the current directory, and gen_gsma_motif.py has its galaxy write commented out while still printing success. Maintainers get a stray file in tools/ and stale clusters/naics.json, clusters/china-defence-universities.json and the gsma-motif galaxy, with no error.
  • Fix — Point all three at ../clusters/ and ../galaxies/ with utf-8, indent=2, sort_keys and a trailing newline, so output already matches jq_all_the_things.sh, and make the silent ones print the path written.
  • Effect — Running a generator actually updates its cluster or galaxy, and says where.

Problem

Three generators do not write to the files they claim to maintain.

tools/generate_naics_clusters.py:100 — writes a misspelled filename into the current directory:

jsonFile = open("naisc_cluster.json", "w")   # "naisc", and no path

clusters/naics.json is never touched. Running the generator produces a stray file in tools/ and leaves the real cluster untouched — while reporting nothing.

tools/gen_defence_university.py:290 — same shape:

with open("china-defence-universities.json", "w") as g:

clusters/china-defence-universities.json is never updated.

tools/gen_gsma_motif.py:281-284 — the galaxy write is commented out, but the script still prints a success message:

# with open(os.path.join('..', 'galaxies', galaxy_fname), 'w') as f:
#     # sort_keys, even if it breaks the kill_chain_order, but jq_all_the_things requires sorted keys
#     json.dump(json_galaxy, f, indent=2, sort_keys=True, ensure_ascii=False)

with open(os.path.join('..', 'clusters', galaxy_fname), 'w') as f:   # cluster IS written
    ...
print("All done, please don't forget to ./jq_all_the_things.sh, commit, and then ./validate_all.sh.")

So the cluster is regenerated and the galaxy silently is not.

Fix

All three now write to ../clusters/... / ../galaxies/... — the same relative form the other generators in tools/ use — with encoding='utf-8', indent=2, sort_keys=True and a trailing newline, so their output already matches what jq_all_the_things.sh would produce. The two that were silent now print the path they wrote.

The commented-out concern in gen_gsma_motif.py was unfounded: sort_keys orders dict keys, not list elements, so the kill_chain_order phase sequence is unaffected. Verified — dumping the committed galaxy with those exact options round-trips byte-identically:

galaxies/ write uncommented: True
sort_keys=True round-trip is byte-identical to the committed file: True
kill_chain_order phase order preserved: ['Reconnaissance', 'Resource-Development', 'Initial-Access'] ...

One coupled change

Pointing gen_defence_university.py at the real cluster makes its per-entry uuid.uuid4() destructive — a first real run would replace all 159 universities with new uuids and orphan every related edge. So this PR also has it reuse the uuid already committed for each university, minting a fresh one only for a genuinely new entry:

committed values: 159 | uuid map entries: 159
values whose committed uuid would be reused: 159 / 159

Without that, the path fix would be a regression rather than a fix.

Verification

=== write paths now point at the committed files ===
  generate_naics_clusters.py    -> clusters/naics.json                        OK
  gen_defence_university.py     -> clusters/china-defence-universities.json   OK
  gen_gsma_motif.py             -> galaxies/gsma-motif.json                   OK

No stray current-directory open() calls remain (the old paths survive only inside explanatory comments). All three compile.

🤖 Generated with Claude Code

generate_naics_clusters.py:100 wrote "naisc_cluster.json" -- a misspelling
of naics, with no path -- into the current directory, so clusters/naics.json
was never updated. gen_defence_university.py:290 had the same shape.
gen_gsma_motif.py:281 had its galaxies/ write commented out while still
printing "All done", so the cluster was regenerated and the galaxy was not.

All three now write to ../clusters/... / ../galaxies/... as the other
generators in tools/ do, with encoding='utf-8', indent=2, sort_keys=True and
a trailing newline so the output already matches jq_all_the_things.sh.

The commented-out concern in gen_gsma_motif ("sort_keys breaks the
kill_chain_order") was unfounded: sort_keys orders dict keys, not list
elements. Dumping the committed galaxy with those exact options round-trips
byte-identically.

Pointing gen_defence_university at the real cluster makes its per-entry
uuid4() destructive, so it now reuses the uuid already committed for each
university (159/159 preserved) and mints only for genuinely new entries --
without that, the path fix would be a regression.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HZGwPoa8MMfkhCw47rDLA4
@elhoim elhoim changed the title fix: naics, china-defence-universities and gsma-motif galaxy are never written by their generators [high] fix: naics, china-defence-universities and gsma-motif galaxy are never written by their generators Sep 3, 2026
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.

1 participant