Skip to content

Commit cd898f7

Browse files
authored
Merge pull request #51 from f5devcentral/1.5.0
1.5.0
2 parents bfddaf1 + 4baea4c commit cd898f7

20 files changed

Lines changed: 8286 additions & 7576 deletions

.github/workflows/main.yml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ on:
55
branches: [main]
66

77
env:
8-
NODE_VERSION: 16
8+
NODE_VERSION: 22
99

1010
jobs:
1111

@@ -16,12 +16,13 @@ jobs:
1616
os: [windows-latest, ubuntu-latest, macos-latest]
1717
name: Test on ${{ matrix.os }}
1818
steps:
19-
- uses: actions/checkout@v3
20-
- uses: actions/setup-node@v3
19+
- uses: actions/checkout@v4
20+
- uses: actions/setup-node@v4
2121
with:
2222
node-version: ${{ env.NODE_VERSION }}
2323

24-
- run: npm install
24+
- run: npm ci
25+
- run: npm test
2526

2627
release-publish:
2728
runs-on: ubuntu-latest
@@ -33,10 +34,10 @@ jobs:
3334
steps:
3435

3536
- name: Checkout code
36-
uses: actions/checkout@v3
37+
uses: actions/checkout@v4
3738

3839
- name: setup node.js ${{ env.NODE_VERSION }}
39-
uses: actions/setup-node@v3
40+
uses: actions/setup-node@v4
4041
with:
4142
node-version: ${{ env.NODE_VERSION }}
4243

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,18 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how
2121

2222
### Fixed
2323

24+
---
25+
26+
## [1.5.0] - (10.30.2025)
27+
28+
### Changed
2429

30+
- Updated all dependencies to latest versions
31+
- Major updates: f5-conx-core (1.2.0), deepmerge-ts (7.1.5), fast-xml-parser (5.3.0), uuid (13.0.0), glob (11.0.3), yargs (18.0.0), mocha (11.7.4), nyc (17.1.0), eslint (9.38.0), @typescript-eslint (8.46.2)
32+
- Moved tar package from dependencies to devDependencies (only used in tests)
33+
- Updated TypeScript target from ES6 to ES2022
34+
- Updated @types packages to match parent package versions
35+
- Removed @types/glob and @types/uuid (now have built-in types)
2536

2637
---
2738

CLAUDE.md

Lines changed: 205 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,205 @@
1+
# CLAUDE.md
2+
3+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4+
5+
## Project Overview
6+
7+
f5-corkscrew is a TypeScript-based tool for extracting and parsing F5 BIG-IP TMOS configurations from various archive formats (.conf, .ucs, .qkview, .tar.gz). The tool converts TMOS configuration into structured JSON for analysis, application extraction, and migration workflows (e.g., to AS3).
8+
9+
## Development Commands
10+
11+
### Build and Compile
12+
13+
```bash
14+
npm run compile # Compile TypeScript to dist/
15+
npm run watch # Watch mode compilation
16+
npm run build-package # Compile and create npm package
17+
```
18+
19+
### Testing
20+
21+
```bash
22+
npm test # Run all Mocha tests with coverage (nyc)
23+
```
24+
25+
Individual test files can be run with:
26+
27+
```bash
28+
npx mocha -r ts-node/register tests/<test-file>.tests.ts
29+
```
30+
31+
Test timeout is configured to 120 seconds in package.json.
32+
33+
### Linting
34+
35+
```bash
36+
npm run lint # TypeScript check + ESLint
37+
```
38+
39+
### CLI Usage
40+
41+
The compiled CLI tool can be tested locally:
42+
43+
```bash
44+
node dist/cli.js --file <path-to-config>
45+
```
46+
47+
After npm install:
48+
49+
```bash
50+
corkscrew --file <path-to-conf|ucs|qkview>
51+
```
52+
53+
CLI options include `--no_sources`, `--no_file_store`, `--no_command_logs`, `--no_process_logs`, `--includeXmlStats`.
54+
55+
## Architecture Overview
56+
57+
### Core Data Flow
58+
59+
1. **Input Processing** ([unPackerStream.ts](src/unPackerStream.ts))
60+
- Handles multiple input formats: .conf files, .ucs archives, .qkview archives, .tar.gz
61+
- Streams archives to avoid loading entire files into memory
62+
- Emits 'conf' events for config files and 'stat' events for qkview XML stats
63+
- Returns non-conf files (certs, keys, license) for tree attachment
64+
65+
2. **Config Parsing** ([ltm.ts](src/ltm.ts) - BigipConfig class)
66+
- Main class that orchestrates all parsing operations
67+
- `loadParseAsync()`: Entry point that loads and parses archives
68+
- `parseConf()`: Converts TMOS config into nested JSON structure (configObject)
69+
- Uses EventEmitter for progress tracking ('parseFile', 'parseObject' events)
70+
71+
3. **Object Structure** ([tmos2json.ts](src/tmos2json.ts), [deepParse.ts](src/deepParse.ts))
72+
- Converts TMOS parent objects (e.g., "ltm virtual /Common/vs_name { ... }") into JSON hierarchy
73+
- Parent objects extracted via regex, then merged into main configObject tree
74+
- Deep parsing applied to specific object types (GTM servers, LTM virtuals, pools, etc.)
75+
76+
4. **Application Extraction** ([digConfigs.ts](src/digConfigs.ts))
77+
- `digVsConfig()`: Extracts complete application configs by crawling virtual server dependencies
78+
- Follows references: pools → members → nodes → monitors, profiles, iRules, policies, persistence
79+
80+
5. **Object Counting** ([objCounter.ts](src/objCounter.ts))
81+
- Counts different object types (virtuals, pools, nodes, etc.) across ltm/gtm/apm/asm
82+
83+
### Key Classes and Modules
84+
85+
- **BigipConfig** ([ltm.ts](src/ltm.ts)): Main class exposing the public API
86+
- Properties: `configObject`, `configFiles`, `stats`, `hostname`, `tmosVersion`, `fileStore`
87+
- Key methods: `loadParseAsync()`, `parseConf()`, `explode()`, `apps()`, `logs()`
88+
89+
- **UnPacker** ([unPackerStream.ts](src/unPackerStream.ts)): Archive extraction using streaming
90+
- Emits events for incremental processing
91+
- Handles tar/gzip decompression without full memory load
92+
93+
- **RegExTree** ([regex.ts](src/regex.ts)): Version-specific regex patterns for parsing TMOS objects
94+
- Organized hierarchically: ltm/gtm/apm/asm
95+
- Supports TMOS version-specific parsing variations
96+
97+
- **Logger** ([logger.ts](src/logger.ts)): Collects logs during processing
98+
- All errors caught and logged rather than polluting output
99+
- Logs returned via `BigipConfig.logs()` method
100+
101+
- **XmlStats** ([xmlStats.ts](src/xmlStats.ts)): Parses qkview XML statistics files
102+
103+
### Data Structures
104+
105+
The main configObject follows this pattern:
106+
107+
```typescript
108+
{
109+
ltm: {
110+
virtual: { [name: string]: { destination, pool, profiles, rules, ... } },
111+
pool: { [name: string]: { members, monitor, ... } },
112+
node: { [name: string]: { address, ... } },
113+
monitor: { ... },
114+
profile: { ... },
115+
rule: { ... },
116+
...
117+
},
118+
gtm: { ... },
119+
apm: { ... },
120+
asm: { ... }
121+
}
122+
```
123+
124+
Each object contains:
125+
126+
- `name`, `partition`, `folder` (if applicable)
127+
- `line`: the original TMOS config string
128+
- Type-specific properties (destination, pool, members, etc.)
129+
130+
### TypeScript Types
131+
132+
Main types defined in [models.ts](src/models.ts):
133+
134+
- `BigipConfObj`: The main nested config structure
135+
- `ConfigFile`: Represents a file with fileName, size, content
136+
- `Explosion`: Return type of explode() method
137+
- `Stats`: Processing statistics and object counts
138+
139+
## Important Implementation Notes
140+
141+
### Memory and Performance
142+
143+
- Nodejs heap limited to 2GB (512MB in VSCode extension context)
144+
- Streaming approach used to avoid loading entire archives into memory
145+
- Typical configs: 6MB file → 340KB compressed, rarely >100K objects
146+
- Target: Handle configs with ~10K virtual servers
147+
148+
### Regex and Parsing
149+
150+
- Uses XRegExp for advanced regex features
151+
- [balancedMatch](node_modules/balanced-match) used for bracket matching in nested TMOS objects
152+
- Parent objects extracted first, then deep-parsed for specific types
153+
- Original config strings preserved in `line` property for reference
154+
155+
### Testing Approach
156+
157+
- Tests in [tests/](tests/) use Mocha with artifacts in [tests/artifacts/](tests/artifacts/)
158+
- Test files follow pattern: `NNN_description.tests.ts`
159+
- Coverage tracked with nyc (istanbul), configured for 50% thresholds
160+
161+
### Versioning
162+
163+
- TMOS version detected from config files, stored in `tmosVersion`
164+
- Regex tree can be modified based on version differences
165+
- Currently handles v11-v17+ configurations
166+
167+
## Project Structure
168+
169+
- **src/**: TypeScript source
170+
- Core: ltm.ts, index.ts, models.ts, cli.ts
171+
- Parsing: regex.ts, tmos2json.ts, deepParse.ts, unPackerStream.ts
172+
- Extraction: digConfigs.ts, digGslb.ts, digCerts.ts, digDoClassesAuto.ts
173+
- Utils: logger.ts, objCounter.ts, objects.ts, pools.ts, xmlStats.ts
174+
- **tests/**: Mocha test files and artifacts
175+
- **dist/**: Compiled JavaScript output (generated)
176+
177+
## Configuration Files
178+
179+
- **package.json**: Scripts, dependencies, nyc coverage config, mocha timeout (120s)
180+
- **tsconfig.json**: Target ES6, CommonJS modules, output to dist/
181+
- **.eslintrc**: Embedded in package.json, uses @typescript-eslint
182+
183+
## Common Tasks
184+
185+
### Adding Support for New TMOS Objects
186+
187+
1. Update type definitions in [models.ts](src/models.ts) (BigipConfObj type)
188+
2. Add regex patterns in [regex.ts](src/regex.ts)
189+
3. Implement deep parsing logic in [deepParse.ts](src/deepParse.ts) if needed
190+
4. Update [objCounter.ts](src/objCounter.ts) to count new object type
191+
5. Add tests with sample configs in tests/artifacts/
192+
193+
### Debugging Parsing Issues
194+
195+
1. Check logs via `BigipConfig.logs()` method
196+
2. Inspect `configObject` tree structure directly
197+
3. Test regex patterns in [regex.ts](src/regex.ts)
198+
4. Add event listeners: `device.on('parseFile', ...)` and `device.on('parseObject', ...)`
199+
200+
### Working with Archives
201+
202+
- .conf: Direct file read
203+
- .ucs: Extracts config/ directory from tar.gz
204+
- .qkview: Extracts config/ and processes XML stats
205+
- All formats stream through UnPacker class

0 commit comments

Comments
 (0)