mcp-souschef 2.0.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,8 @@
1
+ souschef/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ souschef/cli.py,sha256=G_dZEo8ZvBbsoLhMFPv0TbebUfYAj4tCa2hzYZHZPM4,11651
3
+ souschef/server.py,sha256=NP1XOkz12bZrhWpNV--2XjDn2eQuu9U9MTmrPxmNUxs,257067
4
+ mcp_souschef-2.0.1.dist-info/METADATA,sha256=mohV3vEuHyIufKPPRCZ5Ors0gZlmYymzHCcRlgkmK-8,28593
5
+ mcp_souschef-2.0.1.dist-info/WHEEL,sha256=zp0Cn7JsFoX2ATtOhtaFYIiE2rmFAD4OcMhtUki8W3U,88
6
+ mcp_souschef-2.0.1.dist-info/entry_points.txt,sha256=CKlj3OhURaO6qPn3jrFiKe9hCIP5laDMAkRsiUZVWA0,80
7
+ mcp_souschef-2.0.1.dist-info/licenses/LICENSE,sha256=t31dYSuvYYNw6trj-coWSsLK-Tg_Iyl8ObcolQcrUKM,1078
8
+ mcp_souschef-2.0.1.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: poetry-core 2.2.1
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,4 @@
1
+ [console_scripts]
2
+ souschef=souschef.server:main
3
+ souschef-cli=souschef.cli:main
4
+
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 SousChef Contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
souschef/__init__.py ADDED
File without changes
souschef/cli.py ADDED
@@ -0,0 +1,435 @@
1
+ """
2
+ Command-line interface for SousChef.
3
+
4
+ Provides easy access to Chef cookbook parsing and conversion tools.
5
+ """
6
+
7
+ import json
8
+ import sys
9
+ from pathlib import Path
10
+ from typing import NoReturn
11
+
12
+ import click
13
+
14
+ from souschef.server import (
15
+ convert_inspec_to_test,
16
+ convert_resource_to_task,
17
+ generate_inspec_from_recipe,
18
+ list_cookbook_structure,
19
+ list_directory,
20
+ parse_attributes,
21
+ parse_custom_resource,
22
+ parse_inspec_profile,
23
+ parse_recipe,
24
+ parse_template,
25
+ read_cookbook_metadata,
26
+ read_file,
27
+ )
28
+
29
+
30
+ @click.group()
31
+ @click.version_option(version="0.1.0", prog_name="souschef")
32
+ def cli() -> None:
33
+ """
34
+ SousChef - Chef to Ansible conversion toolkit.
35
+
36
+ Parse Chef cookbooks and convert resources to Ansible playbooks.
37
+ """
38
+
39
+
40
+ @cli.command()
41
+ @click.argument("path", type=click.Path(exists=True))
42
+ @click.option(
43
+ "--format",
44
+ "output_format",
45
+ type=click.Choice(["text", "json"]),
46
+ default="text",
47
+ )
48
+ def recipe(path: str, output_format: str) -> None:
49
+ """
50
+ Parse a Chef recipe file and extract resources.
51
+
52
+ PATH: Path to the recipe (.rb) file
53
+ """
54
+ result = parse_recipe(path)
55
+ _output_result(result, output_format)
56
+
57
+
58
+ @cli.command()
59
+ @click.argument("path", type=click.Path(exists=True))
60
+ @click.option(
61
+ "--format",
62
+ "output_format",
63
+ type=click.Choice(["text", "json"]),
64
+ default="json",
65
+ )
66
+ def template(path: str, output_format: str) -> None:
67
+ """
68
+ Parse a Chef ERB template and convert to Jinja2.
69
+
70
+ PATH: Path to the template (.erb) file
71
+ """
72
+ result = parse_template(path)
73
+ _output_result(result, output_format)
74
+
75
+
76
+ @cli.command()
77
+ @click.argument("path", type=click.Path(exists=True))
78
+ @click.option(
79
+ "--format",
80
+ "output_format",
81
+ type=click.Choice(["text", "json"]),
82
+ default="text",
83
+ )
84
+ def attributes(path: str, output_format: str) -> None:
85
+ """
86
+ Parse Chef attributes file.
87
+
88
+ PATH: Path to the attributes (.rb) file
89
+ """
90
+ result = parse_attributes(path)
91
+ _output_result(result, output_format)
92
+
93
+
94
+ @cli.command()
95
+ @click.argument("path", type=click.Path(exists=True))
96
+ @click.option(
97
+ "--format",
98
+ "output_format",
99
+ type=click.Choice(["text", "json"]),
100
+ default="json",
101
+ )
102
+ def resource(path: str, output_format: str) -> None:
103
+ """
104
+ Parse a custom resource or LWRP file.
105
+
106
+ PATH: Path to the custom resource (.rb) file
107
+ """
108
+ result = parse_custom_resource(path)
109
+ _output_result(result, output_format)
110
+
111
+
112
+ @cli.command()
113
+ @click.argument("path", type=click.Path(exists=True))
114
+ def metadata(path: str) -> None:
115
+ """
116
+ Parse cookbook metadata.rb file.
117
+
118
+ PATH: Path to the metadata.rb file
119
+ """
120
+ result = read_cookbook_metadata(path)
121
+ click.echo(result)
122
+
123
+
124
+ @cli.command()
125
+ @click.argument("path", type=click.Path(exists=True))
126
+ def structure(path: str) -> None:
127
+ """
128
+ List the structure of a Chef cookbook.
129
+
130
+ PATH: Path to the cookbook root directory
131
+ """
132
+ result = list_cookbook_structure(path)
133
+ click.echo(result)
134
+
135
+
136
+ @cli.command()
137
+ @click.argument("path", type=click.Path(exists=True))
138
+ def ls(path: str) -> None:
139
+ """
140
+ List contents of a directory.
141
+
142
+ PATH: Path to the directory
143
+ """
144
+ result = list_directory(path)
145
+ if isinstance(result, list):
146
+ for item in result:
147
+ click.echo(item)
148
+ else:
149
+ click.echo(result, err=True)
150
+ sys.exit(1)
151
+
152
+
153
+ @cli.command()
154
+ @click.argument("path", type=click.Path(exists=True))
155
+ def cat(path: str) -> None:
156
+ """
157
+ Read and display file contents.
158
+
159
+ PATH: Path to the file
160
+ """
161
+ result = read_file(path)
162
+ click.echo(result)
163
+
164
+
165
+ @cli.command()
166
+ @click.argument("resource_type")
167
+ @click.argument("resource_name")
168
+ @click.option("--action", default="create", help="Chef action (default: create)")
169
+ @click.option(
170
+ "--properties",
171
+ default="",
172
+ help="Additional properties (JSON string)",
173
+ )
174
+ @click.option(
175
+ "--format",
176
+ "output_format",
177
+ type=click.Choice(["yaml", "json"]),
178
+ default="yaml",
179
+ )
180
+ def convert(
181
+ resource_type: str,
182
+ resource_name: str,
183
+ action: str,
184
+ properties: str,
185
+ output_format: str,
186
+ ) -> None:
187
+ """
188
+ Convert a Chef resource to Ansible task.
189
+
190
+ RESOURCE_TYPE: Chef resource type (e.g., package, service, template)
191
+
192
+ RESOURCE_NAME: Resource name (e.g., nginx, /etc/config.conf)
193
+
194
+ Examples:
195
+ souschef convert package nginx --action install
196
+
197
+ souschef convert service nginx --action start
198
+
199
+ souschef convert template /etc/nginx/nginx.conf --action create
200
+
201
+ """
202
+ result = convert_resource_to_task(resource_type, resource_name, action, properties)
203
+
204
+ if output_format == "json":
205
+ # Parse YAML and convert to JSON for consistency
206
+ try:
207
+ import yaml
208
+
209
+ data = yaml.safe_load(result)
210
+ click.echo(json.dumps(data, indent=2))
211
+ except ImportError:
212
+ click.echo("Warning: PyYAML not installed, outputting as YAML", err=True)
213
+ click.echo(result)
214
+ except Exception:
215
+ # If parsing fails, output as-is
216
+ click.echo(result)
217
+ else:
218
+ click.echo(result)
219
+
220
+
221
+ def _display_recipe_summary(recipe_file: Path) -> None:
222
+ """Display a summary of a recipe file."""
223
+ click.echo(f"\n {recipe_file.name}:")
224
+ recipe_result = parse_recipe(str(recipe_file))
225
+ lines = recipe_result.split("\n")
226
+ click.echo(" " + "\n ".join(lines[:10]))
227
+ if len(lines) > 10:
228
+ click.echo(f" ... ({len(lines) - 10} more lines)")
229
+
230
+
231
+ def _display_resource_summary(resource_file: Path) -> None:
232
+ """Display a summary of a custom resource file."""
233
+ click.echo(f"\n {resource_file.name}:")
234
+ resource_result = parse_custom_resource(str(resource_file))
235
+ try:
236
+ data = json.loads(resource_result)
237
+ click.echo(f" Type: {data.get('resource_type')}")
238
+ click.echo(f" Properties: {len(data.get('properties', []))}")
239
+ click.echo(f" Actions: {', '.join(data.get('actions', []))}")
240
+ except json.JSONDecodeError:
241
+ click.echo(f" {resource_result[:100]}")
242
+
243
+
244
+ def _display_template_summary(template_file: Path) -> None:
245
+ """Display a summary of a template file."""
246
+ click.echo(f"\n {template_file.name}:")
247
+ template_result = parse_template(str(template_file))
248
+ try:
249
+ data = json.loads(template_result)
250
+ variables = data.get("variables", [])
251
+ click.echo(f" Variables: {len(variables)}")
252
+ if variables:
253
+ click.echo(f" {', '.join(variables[:5])}")
254
+ if len(variables) > 5:
255
+ click.echo(f" ... and {len(variables) - 5} more")
256
+ except json.JSONDecodeError:
257
+ click.echo(f" {template_result[:100]}")
258
+
259
+
260
+ @cli.command()
261
+ @click.argument("cookbook_path", type=click.Path(exists=True))
262
+ @click.option(
263
+ "--output",
264
+ "-o",
265
+ type=click.Path(),
266
+ help="Output directory for converted playbook",
267
+ )
268
+ @click.option("--dry-run", is_flag=True, help="Show what would be done")
269
+ def cookbook(cookbook_path: str, output: str | None, dry_run: bool) -> None:
270
+ """
271
+ Analyze an entire Chef cookbook.
272
+
273
+ COOKBOOK_PATH: Path to the cookbook root directory
274
+
275
+ This command analyzes the cookbook structure, metadata, recipes,
276
+ attributes, templates, and custom resources.
277
+ """
278
+ cookbook_dir = Path(cookbook_path)
279
+
280
+ click.echo(f"Analyzing cookbook: {cookbook_dir.name}")
281
+ click.echo("=" * 50)
282
+
283
+ # Parse metadata
284
+ metadata_file = cookbook_dir / "metadata.rb"
285
+ if metadata_file.exists():
286
+ click.echo("\nšŸ“‹ Metadata:")
287
+ click.echo("-" * 50)
288
+ metadata_result = read_cookbook_metadata(str(metadata_file))
289
+ click.echo(metadata_result)
290
+
291
+ # List structure
292
+ click.echo("\nšŸ“ Structure:")
293
+ click.echo("-" * 50)
294
+ structure_result = list_cookbook_structure(str(cookbook_dir))
295
+ click.echo(structure_result)
296
+
297
+ # Parse recipes
298
+ recipes_dir = cookbook_dir / "recipes"
299
+ if recipes_dir.exists():
300
+ click.echo("\nšŸ§‘ā€šŸ³ Recipes:")
301
+ click.echo("-" * 50)
302
+ for recipe_file in recipes_dir.glob("*.rb"):
303
+ _display_recipe_summary(recipe_file)
304
+
305
+ # Parse custom resources
306
+ resources_dir = cookbook_dir / "resources"
307
+ if resources_dir.exists():
308
+ click.echo("\nšŸ”§ Custom Resources:")
309
+ click.echo("-" * 50)
310
+ for resource_file in resources_dir.glob("*.rb"):
311
+ _display_resource_summary(resource_file)
312
+
313
+ # Parse templates
314
+ templates_dir = cookbook_dir / "templates" / "default"
315
+ if templates_dir.exists():
316
+ click.echo("\nšŸ“„ Templates:")
317
+ click.echo("-" * 50)
318
+ for template_file in templates_dir.glob("*.erb"):
319
+ _display_template_summary(template_file)
320
+
321
+ if output and not dry_run:
322
+ click.echo(f"\nšŸ’¾ Would save results to: {output}")
323
+ click.echo("(Full conversion not yet implemented)")
324
+
325
+
326
+ @cli.command()
327
+ @click.argument("path", type=click.Path(exists=True))
328
+ @click.option(
329
+ "--format",
330
+ "output_format",
331
+ type=click.Choice(["text", "json"]),
332
+ default="json",
333
+ )
334
+ def inspec_parse(path: str, output_format: str) -> None:
335
+ """
336
+ Parse an InSpec profile or control file.
337
+
338
+ PATH: Path to InSpec profile directory or .rb control file
339
+ """
340
+ result = parse_inspec_profile(path)
341
+ _output_result(result, output_format)
342
+
343
+
344
+ @cli.command()
345
+ @click.argument("path", type=click.Path(exists=True))
346
+ @click.option(
347
+ "--format",
348
+ "output_format",
349
+ type=click.Choice(["testinfra", "ansible_assert"]),
350
+ default="testinfra",
351
+ help="Output format for converted tests",
352
+ )
353
+ def inspec_convert(path: str, output_format: str) -> None:
354
+ """
355
+ Convert InSpec controls to test format.
356
+
357
+ PATH: Path to InSpec profile directory or .rb control file
358
+ """
359
+ result = convert_inspec_to_test(path, output_format)
360
+ click.echo(result)
361
+
362
+
363
+ @cli.command()
364
+ @click.argument("path", type=click.Path(exists=True))
365
+ @click.option(
366
+ "--format",
367
+ "output_format",
368
+ type=click.Choice(["text", "json"]),
369
+ default="text",
370
+ )
371
+ def inspec_generate(path: str, output_format: str) -> None:
372
+ """
373
+ Generate InSpec controls from Chef recipe.
374
+
375
+ PATH: Path to Chef recipe (.rb) file
376
+ """
377
+ result = generate_inspec_from_recipe(path)
378
+ _output_result(result, output_format)
379
+
380
+
381
+ def _output_json_format(result: str) -> None:
382
+ """Output result as JSON format."""
383
+ try:
384
+ data = json.loads(result)
385
+ click.echo(json.dumps(data, indent=2))
386
+ except json.JSONDecodeError:
387
+ click.echo(result)
388
+
389
+
390
+ def _output_dict_as_text(data: dict) -> None:
391
+ """Output a dictionary in human-readable text format."""
392
+ for key, value in data.items():
393
+ if isinstance(value, list):
394
+ click.echo(f"{key}:")
395
+ for item in value:
396
+ click.echo(f" - {item}")
397
+ else:
398
+ click.echo(f"{key}: {value}")
399
+
400
+
401
+ def _output_text_format(result: str) -> None:
402
+ """Output result as text format, pretty-printing JSON if possible."""
403
+ try:
404
+ data = json.loads(result)
405
+ if isinstance(data, dict):
406
+ _output_dict_as_text(data)
407
+ else:
408
+ click.echo(result)
409
+ except json.JSONDecodeError:
410
+ click.echo(result)
411
+
412
+
413
+ def _output_result(result: str, output_format: str) -> None:
414
+ """
415
+ Output result in specified format.
416
+
417
+ Args:
418
+ result: Result string (may be JSON or plain text).
419
+ output_format: Output format ('text' or 'json').
420
+
421
+ """
422
+ if output_format == "json":
423
+ _output_json_format(result)
424
+ else:
425
+ _output_text_format(result)
426
+
427
+
428
+ def main() -> NoReturn:
429
+ """Run the CLI."""
430
+ cli()
431
+ sys.exit(0)
432
+
433
+
434
+ if __name__ == "__main__":
435
+ main()