xsoar-cli 0.0.3__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.

Potentially problematic release.


This version of xsoar-cli might be problematic. Click here for more details.

xsoar_cli/utilities.py ADDED
@@ -0,0 +1,94 @@
1
+ import json
2
+ from functools import update_wrapper
3
+ from pathlib import Path
4
+ from typing import Callable
5
+
6
+ import click
7
+ from xsoar_client.xsoar_client import Client
8
+
9
+
10
+ def get_config_file_template_contents() -> dict:
11
+ return {
12
+ "default_environment": "dev",
13
+ "default_new_case_type": "",
14
+ "custom_pack_authors": ["SOMEONE"],
15
+ "server_config": {
16
+ "dev": {
17
+ "base_url": "https://xsoar.example.com",
18
+ "api_token": "YOUR API TOKEN HERE",
19
+ "artifacts_location": "S3",
20
+ "s3_bucket_name": "xsoar-cicd",
21
+ "verify_ssl": "/path/to/your/CA_bundle.pem",
22
+ "server_version": 6,
23
+ },
24
+ "prod": {
25
+ "base_url": "https://xsoar.example.com",
26
+ "api_token": "YOUR API TOKEN HERE",
27
+ "artifacts_location": "S3",
28
+ "s3_bucket_name": "xsoar-cicd-prod",
29
+ "verify_ssl": False,
30
+ "server_version": 6,
31
+ },
32
+ },
33
+ }
34
+
35
+
36
+ def validate_environments(*args, **kwargs) -> bool: # noqa: ANN002, ANN003
37
+ return all(env in kwargs["ctx"].obj["server_envs"] for env in args)
38
+
39
+
40
+ def get_config_file_path() -> Path:
41
+ homedir = Path.home()
42
+ config_file_path = homedir / ".config/xsoar-cli"
43
+ config_file_name = "config.json"
44
+ return Path(config_file_path / config_file_name)
45
+
46
+
47
+ def get_config_file_contents(filepath: Path): # noqa: ANN201
48
+ return json.load(filepath.open("r"))
49
+
50
+
51
+ def load_config(f: Callable) -> Callable:
52
+ """
53
+ This function is only to be used as a decorator for various xsoar-cli subcommands. Loads and parses the config file if
54
+ exists, or prompts the user to create one otherwise.
55
+ If an illegal environment is provided by the user, i.e by invoking "xsoar-cli command --environment illegal subcommand",
56
+ then prints out helpful error message and returns non-zero exit value.
57
+ """
58
+
59
+ @click.pass_context
60
+ def wrapper(ctx: click.Context, *args, **kwargs) -> Callable: # noqa: ANN002, ANN003
61
+ config_file_path = get_config_file_path()
62
+ if not config_file_path.is_file():
63
+ click.echo(
64
+ 'Config file not found. Please create a template config file using "xsoar-cli config create" and replace placeholder values before retrying.',
65
+ )
66
+ ctx.exit(1)
67
+ config = get_config_file_contents(config_file_path)
68
+ parse_config(config, ctx)
69
+ if "environment" in ctx.params and ctx.params["environment"] not in ctx.obj["server_envs"]:
70
+ click.echo(f"Invalid environment: {ctx.params['environment']}")
71
+ click.echo(f"Available environments as defined in config file are: {list(ctx.obj['server_envs'])}")
72
+ ctx.exit(1)
73
+ return ctx.invoke(f, *args, **kwargs)
74
+
75
+ return update_wrapper(wrapper, f)
76
+
77
+
78
+ def parse_config(config: dict, ctx: click.Context) -> None:
79
+ # Set the two XSOAR client objects in Click Context for use in later functions
80
+ ctx.obj = {}
81
+ ctx.obj["default_environment"] = config["default_environment"]
82
+ ctx.obj["custom_pack_authors"] = config["custom_pack_authors"]
83
+ ctx.obj["server_envs"] = {}
84
+ for key in config["server_config"]:
85
+ ctx.obj["server_envs"][key] = Client(
86
+ api_token=config["server_config"][key]["api_token"],
87
+ server_url=config["server_config"][key]["base_url"],
88
+ verify_ssl=config["server_config"][key]["verify_ssl"],
89
+ custom_pack_authors=config["custom_pack_authors"],
90
+ xsiam_auth_id=config["server_config"][key].get("xsiam_auth_id", ""),
91
+ server_version=config["server_config"][key]["server_version"],
92
+ artifacts_location=config["server_config"][key]["artifacts_location"],
93
+ s3_bucket_name=config["server_config"][key]["s3_bucket_name"],
94
+ )
@@ -0,0 +1,128 @@
1
+ Metadata-Version: 2.4
2
+ Name: xsoar-cli
3
+ Version: 0.0.3
4
+ Project-URL: Documentation, https://github.com/tlium/xsoar-cli#readme
5
+ Project-URL: Issues, https://github.com/tliumb/xsoar-cli/issues
6
+ Project-URL: Source, https://github.com/tlium/xsoar-cli
7
+ Author-email: Torbjørn Lium <torben@lium.org>
8
+ License-Expression: MIT
9
+ License-File: LICENSE.txt
10
+ Classifier: Development Status :: 4 - Beta
11
+ Classifier: Programming Language :: Python
12
+ Classifier: Programming Language :: Python :: 3.8
13
+ Classifier: Programming Language :: Python :: 3.9
14
+ Classifier: Programming Language :: Python :: 3.10
15
+ Classifier: Programming Language :: Python :: 3.11
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Programming Language :: Python :: Implementation :: CPython
18
+ Classifier: Programming Language :: Python :: Implementation :: PyPy
19
+ Requires-Python: >=3.8
20
+ Requires-Dist: click==8.1.8
21
+ Requires-Dist: pyyaml>=6.0.2
22
+ Requires-Dist: xsoar-client>=1.0.0
23
+ Requires-Dist: xsoar-dependency-graph>=0.0.3
24
+ Description-Content-Type: text/markdown
25
+
26
+ # xsoar-cli
27
+ -----
28
+ This tool is made to help provide a smoother workflow for developers, but also for power users to get useful information out of XSOAR from
29
+ the terminal. Merge requests are very welcome and appreciated!
30
+
31
+ *IMPORTANT NOTE* This CLI tools is made to be run from the root of a content repository. Some commands depends on files located in your
32
+ content repository or expects a certain directory structure to be available from your currently working directory.
33
+
34
+ ## Installation
35
+ ```
36
+ pip install xsoar-cli
37
+ ```
38
+ ## Upgrading
39
+ ```
40
+ pip install --upgrade xsoar-cli
41
+ ```
42
+
43
+
44
+ ## Configuration
45
+ The xsoar-cli config file is located in `~/.config/xsoar-cli/config.json`. To create a configuration file from template, please run
46
+ ```
47
+ xsoar-cli config create
48
+ ```
49
+ Open up the newly created configuration file and add values that correspond with your environment.
50
+ *IMPORTANT NOTE*: the configuration key `"custom_pack_authors": ["SOMEONE"]` is needed in order for `xsoar-cli` to be able to
51
+ determine which content packs are your own custom content packs and which are supplied from Palo Alto upstream. Use whateve values you may have set in
52
+ pack_metadata.json in the content packs in your content repository.
53
+
54
+ ## Usage
55
+ ```
56
+ xsoar-cli <command> <sub-command> <args>
57
+ ```
58
+ For information about available commands, run `xsoar-cli` without arguments.
59
+
60
+ For more information on a specific command execute `xsoar-cli <command> --help.`
61
+
62
+ ### Commands
63
+ 1. [case](src/xsoar_cli/case/README.md)
64
+ 2. [config](src/xsoar_cli/config/README.md)
65
+ 3. [manifest](src/xsoar_cli/manifest/README.md)
66
+ 4. [pack](src/xsoar_cli/pack/README.md)
67
+ 5. [playbook](src/xsoar_cli/playbook/README.md)
68
+ 6. [plugins](src/xsoar_cli/plugins/README.md)
69
+
70
+ ## Plugin System
71
+
72
+ xsoar-cli supports a plugin system that allows you to extend the CLI with custom commands. Plugins are Python files that you place in `~/.local/xsoar-cli/plugins/` and they're automatically discovered and loaded.
73
+
74
+ ### Quick Start with Plugins
75
+
76
+ 1. **Create an example plugin**:
77
+ ```bash
78
+ xsoar-cli plugins create-example
79
+ ```
80
+
81
+ 2. **List available plugins**:
82
+ ```bash
83
+ xsoar-cli plugins list
84
+ ```
85
+
86
+ 3. **Test the example plugin**:
87
+ ```bash
88
+ xsoar-cli example hello --name "World"
89
+ ```
90
+
91
+ ### Plugin Management Commands
92
+
93
+ - `xsoar-cli plugins list` - List all plugins
94
+ - `xsoar-cli plugins info <plugin>` - Show plugin information
95
+ - `xsoar-cli plugins validate` - Validate all plugins
96
+ - `xsoar-cli plugins reload <plugin>` - Reload a specific plugin
97
+ - `xsoar-cli plugins create-example` - Create an example plugin
98
+ - `xsoar-cli plugins open` - Open the plugins directory
99
+
100
+ ### Creating Your Own Plugins
101
+
102
+ Create a Python file in `~/.local/xsoar-cli/plugins/` that inherits from `XSOARPlugin`:
103
+
104
+ ```python
105
+ import click
106
+ from xsoar_cli.plugins import XSOARPlugin
107
+
108
+ class MyPlugin(XSOARPlugin):
109
+ @property
110
+ def name(self) -> str:
111
+ return "myplugin"
112
+
113
+ @property
114
+ def version(self) -> str:
115
+ return "1.0.0"
116
+
117
+ def get_command(self) -> click.Command:
118
+ @click.command(help="My custom command")
119
+ def mycommand():
120
+ click.echo("Hello from my plugin!")
121
+ return mycommand
122
+ ```
123
+
124
+ For detailed documentation, see [Plugin System Documentation](src/xsoar_cli/plugins/README.md).
125
+
126
+ ## License
127
+
128
+ `xsoar-cli` is distributed under the terms of the [MIT](https://spdx.org/licenses/MIT.html) license.
@@ -0,0 +1,31 @@
1
+ xsoar_cli/__about__.py,sha256=PoiGgrfyfU1ozayN6GC8FLvwV9BYI1Jnh0eokMjDDyI,127
2
+ xsoar_cli/__init__.py,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
3
+ xsoar_cli/cli.py,sha256=iAlSeZe2iR6ciTVrJYLt-CDZk7b5I-hzHFXbYoXhupA,1342
4
+ xsoar_cli/utilities.py,sha256=_gfgwBV5p1_QwNl6qw1fluO6kP7jGW_oItAEJnaR3rA,3860
5
+ xsoar_cli/case/README.md,sha256=MTfgVeW3qJXRPNFo8CkZvulm2vwbN8sgiW86V-qXRFw,1342
6
+ xsoar_cli/case/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
7
+ xsoar_cli/case/commands.py,sha256=q1rHb8UQ0NvN6kLh6NRWla5s6qG35PV0xhIOIR325Eg,3233
8
+ xsoar_cli/config/README.md,sha256=pcO858PDL9c0qtwj3_a6B8q2CGvcka3dwclVnwi2vlA,516
9
+ xsoar_cli/config/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
10
+ xsoar_cli/config/commands.py,sha256=SJqIBUBq4tHmnXusycXuIOkmHhyc-vKvQwFMjIHh3Cc,3884
11
+ xsoar_cli/graph/README.md,sha256=kyWIGs2Sd-OdqAaCWJjyvGpAhXhFcuqQwVqFBgzgWzk,861
12
+ xsoar_cli/graph/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
13
+ xsoar_cli/graph/commands.py,sha256=LKOpUu8r6KThJ5HdyjZlhpwLKRgMcEu7btBOQXwDkMs,1069
14
+ xsoar_cli/manifest/README.md,sha256=Ha84Ozlj7KwSj9FsK42sSZVYoWllmPKsjtkB-53Anpg,913
15
+ xsoar_cli/manifest/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
16
+ xsoar_cli/manifest/commands.py,sha256=jShmi0s7GOSXJt9DQbEoFSu4ZsC0Givv1vJj7qfwI2g,8697
17
+ xsoar_cli/pack/README.md,sha256=CA7jAEphHxK0gh58rLRKL-u3wx29QgNAXojd_tGBXnY,46
18
+ xsoar_cli/pack/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
19
+ xsoar_cli/pack/commands.py,sha256=bLbKCC_TROqqysEfmk6G9qqKJuXkt0nqwUHoP_LauD8,1899
20
+ xsoar_cli/playbook/README.md,sha256=8y_YhvZtLP7KzYG83jiVBF-wBAEh8UTJcgmTOTynmbc,977
21
+ xsoar_cli/playbook/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
22
+ xsoar_cli/playbook/commands.py,sha256=mFmXJ3D8plvrUC9ylMlkrAa2T1yhydByEBhrBVbaZec,2729
23
+ xsoar_cli/plugins/README.md,sha256=qQ_shzxcJcJKHuWfuN_cTVhtaew4BEGBEjn9wxaZG5c,11314
24
+ xsoar_cli/plugins/__init__.py,sha256=81IZsMbZsqrLdB6TjA9t6s3yS8FkuihliBFX4xZUpTo,1753
25
+ xsoar_cli/plugins/commands.py,sha256=HC0sWu149uQG9Ztag4t2CNPKXTM4WJbEdLSvFMEjw80,10660
26
+ xsoar_cli/plugins/manager.py,sha256=7RPk3lAYDifGMLOU-hFOqyPxTVk8ibBVzBqH7R8wy4g,13012
27
+ xsoar_cli-0.0.3.dist-info/METADATA,sha256=OC2qqM6pvUZgS0cx_5sbqvFA2IxIh0e3tVky0_5SLXA,4375
28
+ xsoar_cli-0.0.3.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
29
+ xsoar_cli-0.0.3.dist-info/entry_points.txt,sha256=s6Klu4QRekXsmZaBxMyFlE4Q-4_jIA9uijk4qIYUPvE,48
30
+ xsoar_cli-0.0.3.dist-info/licenses/LICENSE.txt,sha256=l6xnqWKshqwwTXt6ayO6MX8Uvygq0YnkUuFTNnR3ba4,1097
31
+ xsoar_cli-0.0.3.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.27.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ xsoar-cli = xsoar_cli.cli:cli
@@ -0,0 +1,9 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025-present Torbjørn Lium <torben@lium.org>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.