pan-scm-cli 0.1.0__tar.gz
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.
- pan_scm_cli-0.1.0/PKG-INFO +513 -0
- pan_scm_cli-0.1.0/README.md +496 -0
- pan_scm_cli-0.1.0/pyproject.toml +43 -0
- pan_scm_cli-0.1.0/src/scm_cli/__init__.py +21 -0
- pan_scm_cli-0.1.0/src/scm_cli/cli/__init__.py +4 -0
- pan_scm_cli-0.1.0/src/scm_cli/cli/main.py +1036 -0
- pan_scm_cli-0.1.0/src/scm_cli/cli/network/__init__.py +0 -0
- pan_scm_cli-0.1.0/src/scm_cli/cli/network/interface/__init__.py +0 -0
- pan_scm_cli-0.1.0/src/scm_cli/cli/object/__init__.py +1 -0
- pan_scm_cli-0.1.0/src/scm_cli/cli/object/address_group/__init__.py +0 -0
- pan_scm_cli-0.1.0/src/scm_cli/cli/object/address_object/__init__.py +3 -0
- pan_scm_cli-0.1.0/src/scm_cli/cli/object/address_object/commands.py +690 -0
- pan_scm_cli-0.1.0/src/scm_cli/cli/object/address_object/models.py +638 -0
- pan_scm_cli-0.1.0/src/scm_cli/docs/README.md +58 -0
- pan_scm_cli-0.1.0/src/scm_cli/docs/__init__.py +1 -0
- pan_scm_cli-0.1.0/src/scm_cli/docs/cli.md +115 -0
- pan_scm_cli-0.1.0/src/scm_cli/docs/config.md +90 -0
- pan_scm_cli-0.1.0/src/scm_cli/docs/db.md +153 -0
- pan_scm_cli-0.1.0/src/scm_cli/docs/imports.md +194 -0
- pan_scm_cli-0.1.0/src/scm_cli/docs/mock_sdk.md +146 -0
- pan_scm_cli-0.1.0/src/scm_cli/docs/sdk_client.md +164 -0
- pan_scm_cli-0.1.0/src/scm_cli/examples/__init__.py +1 -0
- pan_scm_cli-0.1.0/src/scm_cli/models/__init__.py +1 -0
- pan_scm_cli-0.1.0/src/scm_cli/utils/__init__.py +4 -0
- pan_scm_cli-0.1.0/src/scm_cli/utils/config.py +80 -0
- pan_scm_cli-0.1.0/src/scm_cli/utils/db.py +191 -0
- pan_scm_cli-0.1.0/src/scm_cli/utils/db_utils.py +95 -0
- pan_scm_cli-0.1.0/src/scm_cli/utils/decorators.py +142 -0
- pan_scm_cli-0.1.0/src/scm_cli/utils/logging.py +94 -0
- pan_scm_cli-0.1.0/src/scm_cli/utils/mock_sdk.py +260 -0
- pan_scm_cli-0.1.0/src/scm_cli/utils/sdk_client.py +52 -0
- pan_scm_cli-0.1.0/src/scm_cli/utils/state_manager.py +691 -0
|
@@ -0,0 +1,513 @@
|
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
|
+
Name: pan-scm-cli
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Network Engineer-friendly CLI for Palo Alto Networks Security Content Management
|
|
5
|
+
Author: Calvin Remsburg
|
|
6
|
+
Author-email: calvin@cdot.io
|
|
7
|
+
Requires-Python: >=3.12,<3.13
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
10
|
+
Requires-Dist: cmd2 (>=2.4.3,<3.0.0)
|
|
11
|
+
Requires-Dist: pan-scm-sdk (>=0.3.18)
|
|
12
|
+
Requires-Dist: pydantic (>=2.9.2,<3.0.0)
|
|
13
|
+
Requires-Dist: python-dotenv (>=1.0.0,<2.0.0)
|
|
14
|
+
Requires-Dist: pyyaml (>=6.0.1,<7.0.0)
|
|
15
|
+
Requires-Dist: rich (>=13.7.0,<14.0.0)
|
|
16
|
+
Description-Content-Type: text/markdown
|
|
17
|
+
|
|
18
|
+
# PAN-SCM-CLI
|
|
19
|
+
|
|
20
|
+
<div align="center">
|
|
21
|
+
|
|
22
|
+

|
|
23
|
+

|
|
24
|
+
[](LICENSE)
|
|
25
|
+
[]()
|
|
26
|
+
|
|
27
|
+
A network engineer-friendly command-line interface for
|
|
28
|
+
Palo Alto Networks Strata Cloud Manager (SCM)
|
|
29
|
+
|
|
30
|
+
</div>
|
|
31
|
+
|
|
32
|
+
## Overview
|
|
33
|
+
|
|
34
|
+
PAN-SCM-CLI provides a familiar networking-style CLI experience for interacting with Palo Alto Networks Strata Cloud Manager (SCM) API. This tool bridges the gap between traditional network engineering workflows and cloud security management, making SCM more accessible for network professionals who prefer CLI environments.
|
|
35
|
+
|
|
36
|
+
The CLI offers command-line shortcuts, tab completion, help menus, and output formatting that will feel familiar to engineers with experience in network CLI environments.
|
|
37
|
+
|
|
38
|
+
## Table of Contents
|
|
39
|
+
|
|
40
|
+
- [Features](#features)
|
|
41
|
+
- [Architecture](#architecture)
|
|
42
|
+
- [Requirements](#requirements)
|
|
43
|
+
- [Installation](#installation)
|
|
44
|
+
- [Authentication](#authentication)
|
|
45
|
+
- [CLI Workflows](#cli-workflows)
|
|
46
|
+
- [Usage Examples](#usage-examples)
|
|
47
|
+
- [Command Reference](#command-reference)
|
|
48
|
+
- [Development](#development)
|
|
49
|
+
- [Project Structure](#project-structure)
|
|
50
|
+
- [Technical Details](#technical-details)
|
|
51
|
+
- [Package Import Structure](#package-import-structure)
|
|
52
|
+
- [License](#license)
|
|
53
|
+
- [Contributing](#contributing)
|
|
54
|
+
|
|
55
|
+
## Features
|
|
56
|
+
|
|
57
|
+
- **Familiar CLI Syntax**: networking-style commands with keyword-based arguments
|
|
58
|
+
- **Context-Sensitive Help**: Use `?` anywhere to get context-specific help
|
|
59
|
+
- **Tab Completion**: Quickly complete commands, folder names, and object names
|
|
60
|
+
- **Command History**: Track and search command history stored in SQLite
|
|
61
|
+
- **Partial Updates**: Update specific fields of existing objects without re-specifying everything
|
|
62
|
+
- **Rich Terminal Output**: Colorized, formatted output with tables and JSON
|
|
63
|
+
- **Authentication**: OAuth2 authentication with the SCM API
|
|
64
|
+
- **Typed API Client**: Type-annotated SDK client for better code quality
|
|
65
|
+
- **API Caching**: Efficient caching system for API responses
|
|
66
|
+
- **Persistent State**: Maintains CLI state between sessions
|
|
67
|
+
|
|
68
|
+
## Architecture
|
|
69
|
+
|
|
70
|
+
The SCM CLI is built with a layered architecture that separates concerns and provides flexibility:
|
|
71
|
+
|
|
72
|
+
```mermaid
|
|
73
|
+
graph TD
|
|
74
|
+
A[User Input] --> B[CLI Layer]
|
|
75
|
+
B --> C[Command Implementation Layer]
|
|
76
|
+
C --> D[SDK Client Layer]
|
|
77
|
+
D --> E[Underlying SCM SDK]
|
|
78
|
+
E --> F[SCM API]
|
|
79
|
+
B <--> G[Database Layer]
|
|
80
|
+
D <--> H[Configuration Layer]
|
|
81
|
+
|
|
82
|
+
classDef primary fill:#9ecae1,stroke:#3182bd,stroke-width:2px;
|
|
83
|
+
classDef secondary fill:#c6dbef,stroke:#6baed6,stroke-width:2px;
|
|
84
|
+
class B,C,D primary;
|
|
85
|
+
class E,F,G,H secondary;
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
1. **CLI Layer**: Handles user input, command parsing, and display
|
|
89
|
+
2. **Command Implementation Layer**: Implements commands for each resource type
|
|
90
|
+
3. **SDK Client Layer**: Abstracts the Palo Alto Networks SCM SDK
|
|
91
|
+
4. **Configuration Layer**: Manages credentials and settings
|
|
92
|
+
5. **Database Layer**: Stores command history and maintains state
|
|
93
|
+
6. **Underlying SDK**: Communicates with the Palo Alto Networks SCM API
|
|
94
|
+
|
|
95
|
+
## Requirements
|
|
96
|
+
|
|
97
|
+
- Python 3.12.9 (managed with pyenv)
|
|
98
|
+
- Poetry for dependency management
|
|
99
|
+
|
|
100
|
+
## Installation
|
|
101
|
+
|
|
102
|
+
```bash
|
|
103
|
+
# Clone the repository
|
|
104
|
+
git clone https://github.com/cdot65/pan-scm-cli.git
|
|
105
|
+
cd pan-scm-cli
|
|
106
|
+
|
|
107
|
+
# Install dependencies
|
|
108
|
+
poetry install
|
|
109
|
+
|
|
110
|
+
# Copy the example .env file and modify with your credentials
|
|
111
|
+
cp .env.example .env
|
|
112
|
+
nano .env # Edit with your credentials
|
|
113
|
+
|
|
114
|
+
# Run the CLI
|
|
115
|
+
poetry run scm-cli
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
## Authentication
|
|
119
|
+
|
|
120
|
+
The SCM CLI requires OAuth credentials to authenticate with the SCM API. These credentials must be provided in a `.env` file in the current directory with the following format:
|
|
121
|
+
|
|
122
|
+
```
|
|
123
|
+
SCM_CLIENT_ID=your_client_id_here
|
|
124
|
+
SCM_CLIENT_SECRET=your_client_secret_here
|
|
125
|
+
SCM_TSG_ID=your_tsg_id_here
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
You can also specify optional settings:
|
|
129
|
+
|
|
130
|
+
```
|
|
131
|
+
SCM_BASE_URL=https://api.strata.paloaltonetworks.com
|
|
132
|
+
SCM_VERIFY_SSL=true
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
## CLI Workflows
|
|
136
|
+
|
|
137
|
+
### Basic Navigation Workflow
|
|
138
|
+
|
|
139
|
+
```mermaid
|
|
140
|
+
sequenceDiagram
|
|
141
|
+
participant User
|
|
142
|
+
participant CLI
|
|
143
|
+
participant SCM
|
|
144
|
+
|
|
145
|
+
User->>CLI: Start SCM CLI
|
|
146
|
+
CLI->>SCM: Initialize connection
|
|
147
|
+
SCM-->>CLI: Connection established
|
|
148
|
+
CLI-->>User: ✅ Client initialized successfully
|
|
149
|
+
|
|
150
|
+
User->>CLI: configure
|
|
151
|
+
CLI-->>User: Entered configuration mode
|
|
152
|
+
|
|
153
|
+
User->>CLI: edit folder Texas
|
|
154
|
+
CLI->>SCM: Verify folder exists
|
|
155
|
+
SCM-->>CLI: Folder verified
|
|
156
|
+
CLI-->>User: Entered folder Texas
|
|
157
|
+
|
|
158
|
+
User->>CLI: exit
|
|
159
|
+
CLI-->>User: Exit to operational mode
|
|
160
|
+
|
|
161
|
+
User->>CLI: quit
|
|
162
|
+
CLI-->>User: Exit CLI
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
### Address Object Management Workflow
|
|
166
|
+
|
|
167
|
+
```mermaid
|
|
168
|
+
sequenceDiagram
|
|
169
|
+
participant User
|
|
170
|
+
participant CLI
|
|
171
|
+
participant SCM API
|
|
172
|
+
participant Database
|
|
173
|
+
|
|
174
|
+
User->>CLI: set address-object name webserver1 type ip-netmask value 192.168.1.10/32
|
|
175
|
+
CLI->>CLI: Parse command
|
|
176
|
+
CLI->>SCM API: Create address object
|
|
177
|
+
SCM API-->>CLI: Object created
|
|
178
|
+
CLI->>Database: Log command
|
|
179
|
+
CLI-->>User: ✅ created address-object webserver1
|
|
180
|
+
|
|
181
|
+
User->>CLI: show address-object webserver1
|
|
182
|
+
CLI->>SCM API: Get object details
|
|
183
|
+
SCM API-->>CLI: Object details
|
|
184
|
+
CLI-->>User: Display object in JSON format
|
|
185
|
+
|
|
186
|
+
User->>CLI: set address-object name webserver1 description "Updated desc"
|
|
187
|
+
CLI->>SCM API: Update address object
|
|
188
|
+
SCM API-->>CLI: Object updated
|
|
189
|
+
CLI->>Database: Log command
|
|
190
|
+
CLI-->>User: ✅ updated address-object webserver1
|
|
191
|
+
|
|
192
|
+
User->>CLI: delete address-object webserver1
|
|
193
|
+
CLI->>SCM API: Delete address object
|
|
194
|
+
SCM API-->>CLI: Object deleted
|
|
195
|
+
CLI->>Database: Log command
|
|
196
|
+
CLI-->>User: ✅ deleted address-object webserver1
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
## Usage Examples
|
|
200
|
+
|
|
201
|
+
### Basic Navigation
|
|
202
|
+
|
|
203
|
+
```bash
|
|
204
|
+
# Start the CLI
|
|
205
|
+
$ poetry run scm-cli
|
|
206
|
+
Entering SCM CLI
|
|
207
|
+
✅ Client initialized successfully
|
|
208
|
+
|
|
209
|
+
# Enter configuration mode
|
|
210
|
+
developer@scm> configure
|
|
211
|
+
|
|
212
|
+
# Edit a specific folder
|
|
213
|
+
developer@scm# edit folder Texas
|
|
214
|
+
|
|
215
|
+
# Exit configuration mode
|
|
216
|
+
developer(Texas)# exit
|
|
217
|
+
|
|
218
|
+
# Exit the CLI
|
|
219
|
+
developer@scm> quit
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
### Managing Address Objects
|
|
223
|
+
|
|
224
|
+
```bash
|
|
225
|
+
# Create a new address object
|
|
226
|
+
developer(Texas)# set address-object name webserver1 type ip-netmask value 192.168.1.10/32 description "Web Server" tags "Production,HTTP"
|
|
227
|
+
✅ - created address-object webserver1
|
|
228
|
+
|
|
229
|
+
# Show details of an address object
|
|
230
|
+
developer(Texas)# show address-object webserver1
|
|
231
|
+
{
|
|
232
|
+
"name": "webserver1",
|
|
233
|
+
"type": "ip-netmask",
|
|
234
|
+
"value": "192.168.1.10/32",
|
|
235
|
+
"description": "Web Server",
|
|
236
|
+
"tags": ["Production", "HTTP"]
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
# Update just one field of an existing address object
|
|
240
|
+
developer(Texas)# set address-object name webserver1 description "Primary Web Server"
|
|
241
|
+
✅ - updated address-object webserver1
|
|
242
|
+
|
|
243
|
+
# List all address objects in current folder
|
|
244
|
+
developer(Texas)# show address-object
|
|
245
|
+
Address Objects in Texas
|
|
246
|
+
┌───────────┬────────────┬────────────────┬────────────────────┬────────────────┐
|
|
247
|
+
│ Name │ Type │ Value │ Description │ Tags │
|
|
248
|
+
├───────────┼────────────┼────────────────┼────────────────────┼────────────────┤
|
|
249
|
+
│ webserver1│ ip-netmask │ 192.168.1.10/32│ Primary Web Server │ Production, HTTP│
|
|
250
|
+
└───────────┴────────────┴────────────────┴────────────────────┴────────────────┘
|
|
251
|
+
|
|
252
|
+
# Delete an address object
|
|
253
|
+
developer(Texas)# delete address-object webserver1
|
|
254
|
+
✅ - deleted address-object webserver1
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
### Using Command History
|
|
258
|
+
|
|
259
|
+
```bash
|
|
260
|
+
# View command history
|
|
261
|
+
developer(Texas)# history
|
|
262
|
+
Command History (last 50 commands)
|
|
263
|
+
┌─────┬────────────────────────────────────────────────────────────────────┬────────────────┐
|
|
264
|
+
│ ID │ Command │ Timestamp │
|
|
265
|
+
├─────┼────────────────────────────────────────────────────────────────────┼────────────────┤
|
|
266
|
+
│ 123 │ set address-object name webserver1 type ip-netmask value 192.168...│ 10 minutes ago │
|
|
267
|
+
│ 124 │ show address-object webserver1 │ 8 minutes ago │
|
|
268
|
+
└─────┴────────────────────────────────────────────────────────────────────┴────────────────┘
|
|
269
|
+
|
|
270
|
+
# Filter history by command content
|
|
271
|
+
developer(Texas)# history --filter "webserver"
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
## Command Reference
|
|
275
|
+
|
|
276
|
+
### Navigation and Mode Commands
|
|
277
|
+
|
|
278
|
+
- `configure` - Enter configuration mode
|
|
279
|
+
- `edit folder <folder-name>` - Edit a specific folder
|
|
280
|
+
- `exit` - Exit current mode or the CLI
|
|
281
|
+
- `quit` - Exit the CLI
|
|
282
|
+
|
|
283
|
+
### Address Object Commands
|
|
284
|
+
|
|
285
|
+
- `set address-object name <n> type <type> value <value> [description <text>] [tags <tags>]` - Create/update an address object
|
|
286
|
+
- `show address-object <n>` - Display address object details
|
|
287
|
+
- `show address-object` - List all address objects in current folder
|
|
288
|
+
- `show address-objects-filter [--name <n>] [--type <type>] [--value <val>] [--tag <tag>]` - Search and filter address objects
|
|
289
|
+
- `delete address-object <n>` - Delete an address object
|
|
290
|
+
|
|
291
|
+
### History Command
|
|
292
|
+
|
|
293
|
+
- `history` - Show the last 50 commands (default)
|
|
294
|
+
- `history --page <n>` - Navigate between pages of history
|
|
295
|
+
- `history --limit <n>` - Change how many commands are shown per page
|
|
296
|
+
- `history --folder <folder>` - Filter history by folder
|
|
297
|
+
- `history --filter <text>` - Filter history by command content
|
|
298
|
+
- `history --id <n>` - Show details of a specific history entry, including command output
|
|
299
|
+
- `history --clear` - Clear the command history
|
|
300
|
+
|
|
301
|
+
### Getting Help
|
|
302
|
+
|
|
303
|
+
```mermaid
|
|
304
|
+
flowchart TD
|
|
305
|
+
A[User needs help] --> B{What type of help?}
|
|
306
|
+
B -->|Command overview| C[Type 'help']
|
|
307
|
+
B -->|Specific command| D[Type 'help <command>']
|
|
308
|
+
B -->|Context-sensitive| E[Type '?' after partial command]
|
|
309
|
+
B -->|Command completion| F[Press TAB key]
|
|
310
|
+
|
|
311
|
+
C --> G[Display all available commands]
|
|
312
|
+
D --> H[Display detailed help for specific command]
|
|
313
|
+
E --> I[Show options available at current position]
|
|
314
|
+
F --> J[Auto-complete current input]
|
|
315
|
+
|
|
316
|
+
style A fill:#f9f9f9,stroke:#666,stroke-width:2px
|
|
317
|
+
style B fill:#e1f5fe,stroke:#0288d1,stroke-width:2px
|
|
318
|
+
style C,D,E,F fill:#e8f5e9,stroke:#2e7d32,stroke-width:1px
|
|
319
|
+
style G,H,I,J fill:#f1f8e9,stroke:#558b2f,stroke-width:1px
|
|
320
|
+
```
|
|
321
|
+
|
|
322
|
+
There are several ways to get help in the SCM CLI:
|
|
323
|
+
|
|
324
|
+
1. **Command help**: Type `help` to see all available commands, or `help <command>` to see detailed help for a specific command.
|
|
325
|
+
|
|
326
|
+
2. **Question mark at end of command**: Type a command followed by a question mark to show help for that command.
|
|
327
|
+
```
|
|
328
|
+
scm> configure?
|
|
329
|
+
```
|
|
330
|
+
|
|
331
|
+
3. **Inline question mark**: Type a partial command with a question mark to get context-sensitive help for the current position.
|
|
332
|
+
```
|
|
333
|
+
scm> set ?
|
|
334
|
+
Available object types:
|
|
335
|
+
address-object - Configure an address object
|
|
336
|
+
```
|
|
337
|
+
|
|
338
|
+
4. **Tab completion**: Press TAB to auto-complete commands, arguments, and values.
|
|
339
|
+
|
|
340
|
+
## Development
|
|
341
|
+
|
|
342
|
+
This project uses Poetry for dependency management and follows modern Python development practices.
|
|
343
|
+
|
|
344
|
+
### Development Commands
|
|
345
|
+
|
|
346
|
+
```bash
|
|
347
|
+
# Install development dependencies
|
|
348
|
+
poetry install
|
|
349
|
+
|
|
350
|
+
# Run tests
|
|
351
|
+
poetry run pytest
|
|
352
|
+
|
|
353
|
+
# Run a specific test
|
|
354
|
+
poetry run pytest tests/test_file.py::test_function -v
|
|
355
|
+
|
|
356
|
+
# Format code
|
|
357
|
+
poetry run black .
|
|
358
|
+
poetry run isort .
|
|
359
|
+
|
|
360
|
+
# Type checking
|
|
361
|
+
poetry run mypy .
|
|
362
|
+
|
|
363
|
+
# Linting
|
|
364
|
+
poetry run flake8 .
|
|
365
|
+
```
|
|
366
|
+
|
|
367
|
+
## Project Structure
|
|
368
|
+
|
|
369
|
+
```mermaid
|
|
370
|
+
graph TD
|
|
371
|
+
A[pan-scm-cli/] --> B[pyproject.toml]
|
|
372
|
+
A --> C[README.md]
|
|
373
|
+
A --> D[src/]
|
|
374
|
+
A --> E[tests/]
|
|
375
|
+
|
|
376
|
+
D --> F[scm_cli/]
|
|
377
|
+
F --> G[__init__.py]
|
|
378
|
+
F --> H[cli/]
|
|
379
|
+
F --> I[models/]
|
|
380
|
+
F --> J[utils/]
|
|
381
|
+
F --> K[docs/]
|
|
382
|
+
|
|
383
|
+
H --> L[main.py]
|
|
384
|
+
H --> M[network/]
|
|
385
|
+
H --> N[object/]
|
|
386
|
+
|
|
387
|
+
N --> O[address_object/]
|
|
388
|
+
N --> P[address_group/]
|
|
389
|
+
O --> Q[commands.py]
|
|
390
|
+
O --> R[models.py]
|
|
391
|
+
|
|
392
|
+
J --> S[config.py]
|
|
393
|
+
J --> T[db.py]
|
|
394
|
+
J --> U[logging.py]
|
|
395
|
+
J --> V[sdk_client.py]
|
|
396
|
+
J --> W[state_manager.py]
|
|
397
|
+
|
|
398
|
+
E --> X[test_cli.py]
|
|
399
|
+
E --> Y[test_config.py]
|
|
400
|
+
|
|
401
|
+
classDef default fill:#ddd,stroke:#333,stroke-width:1px;
|
|
402
|
+
classDef core fill:#d4f1c5,stroke:#333,stroke-width:1px;
|
|
403
|
+
classDef config fill:#f6e8c3,stroke:#333,stroke-width:1px;
|
|
404
|
+
classDef tests fill:#c7eae5,stroke:#333,stroke-width:1px;
|
|
405
|
+
|
|
406
|
+
class B,C config;
|
|
407
|
+
class G,L,Q,R,S,T,U,V,W core;
|
|
408
|
+
class X,Y tests;
|
|
409
|
+
```
|
|
410
|
+
|
|
411
|
+
```
|
|
412
|
+
pan-scm-cli/
|
|
413
|
+
├── pyproject.toml # Project configuration and dependencies
|
|
414
|
+
├── README.md # Project documentation (this file)
|
|
415
|
+
├── src/
|
|
416
|
+
│ └── scm_cli/ # Main package directory
|
|
417
|
+
│ ├── __init__.py # Package initialization
|
|
418
|
+
│ ├── cli/ # CLI implementation
|
|
419
|
+
│ │ ├── main.py # Main CLI entry point
|
|
420
|
+
│ │ ├── network/ # Network-related commands
|
|
421
|
+
│ │ └── object/ # Object management commands
|
|
422
|
+
│ ├── models/ # Data models
|
|
423
|
+
│ ├── utils/ # Utility functions
|
|
424
|
+
│ │ ├── config.py # Configuration management
|
|
425
|
+
│ │ ├── db.py # Database interface
|
|
426
|
+
│ │ ├── logging.py # Logging configuration
|
|
427
|
+
│ │ └── sdk_client.py # SDK client abstraction
|
|
428
|
+
│ └── docs/ # Documentation
|
|
429
|
+
└── tests/ # Test directory
|
|
430
|
+
├── test_cli.py # CLI tests
|
|
431
|
+
└── test_config.py # Configuration tests
|
|
432
|
+
```
|
|
433
|
+
|
|
434
|
+
## Technical Details
|
|
435
|
+
|
|
436
|
+
The SCM CLI is built on the following key components:
|
|
437
|
+
|
|
438
|
+
1. **cmd2**: Extends Python's built-in cmd module with additional features like tab completion, colorization, and more complex command handling.
|
|
439
|
+
|
|
440
|
+
2. **rich**: Provides rich text and beautiful formatting in the terminal, including tables, panels, and syntax highlighting.
|
|
441
|
+
|
|
442
|
+
3. **python-dotenv**: Loads environment variables from .env files for configuration.
|
|
443
|
+
|
|
444
|
+
4. **SQLite**: Stores command history and caches in a local database file.
|
|
445
|
+
|
|
446
|
+
5. **pan-scm-sdk**: The official Palo Alto Networks SDK for interacting with the SCM API.
|
|
447
|
+
|
|
448
|
+
6. **pydantic**: Handles data validation and serialization.
|
|
449
|
+
|
|
450
|
+
## Package Import Structure
|
|
451
|
+
|
|
452
|
+
The project uses a clean, consistent import structure to ensure compatibility when installed as a package:
|
|
453
|
+
|
|
454
|
+
```mermaid
|
|
455
|
+
graph TD
|
|
456
|
+
A[External Code] --> B[scm_cli Package]
|
|
457
|
+
B --> C[CLI Module]
|
|
458
|
+
B --> D[Utils Module]
|
|
459
|
+
B --> E[Models Module]
|
|
460
|
+
|
|
461
|
+
C --> F[Object Commands]
|
|
462
|
+
C --> G[Network Commands]
|
|
463
|
+
|
|
464
|
+
F --> H[Address Object]
|
|
465
|
+
F --> I[Address Group]
|
|
466
|
+
|
|
467
|
+
D --> J[Config]
|
|
468
|
+
D --> K[SDK Client]
|
|
469
|
+
D --> L[Database]
|
|
470
|
+
|
|
471
|
+
classDef external fill:#f9f9f9,stroke:#666,stroke-width:1px;
|
|
472
|
+
classDef package fill:#e3f2fd,stroke:#1565c0,stroke-width:2px;
|
|
473
|
+
classDef modules fill:#e8f5e9,stroke:#2e7d32,stroke-width:1px;
|
|
474
|
+
classDef submodules fill:#f1f8e9,stroke:#558b2f,stroke-width:1px;
|
|
475
|
+
|
|
476
|
+
class A external;
|
|
477
|
+
class B package;
|
|
478
|
+
class C,D,E modules;
|
|
479
|
+
class F,G,H,I,J,K,L submodules;
|
|
480
|
+
```
|
|
481
|
+
|
|
482
|
+
### Import Best Practices
|
|
483
|
+
|
|
484
|
+
When working with this package, follow these import guidelines:
|
|
485
|
+
|
|
486
|
+
1. **External imports** should use the package name without the src prefix:
|
|
487
|
+
```python
|
|
488
|
+
from scm_cli.utils.config import load_oauth_credentials
|
|
489
|
+
```
|
|
490
|
+
|
|
491
|
+
2. **Internal relative imports** should be used within modules for closely related components:
|
|
492
|
+
```python
|
|
493
|
+
from .models import AddressObjectAPI
|
|
494
|
+
```
|
|
495
|
+
|
|
496
|
+
3. **Parent-package imports** should use absolute imports from the package root:
|
|
497
|
+
```python
|
|
498
|
+
from scm_cli.utils.decorators import timeit
|
|
499
|
+
```
|
|
500
|
+
|
|
501
|
+
## License
|
|
502
|
+
|
|
503
|
+
[MIT License](LICENSE)
|
|
504
|
+
|
|
505
|
+
## Contributing
|
|
506
|
+
|
|
507
|
+
Contributions are welcome! Please feel free to submit a Pull Request.
|
|
508
|
+
|
|
509
|
+
1. Fork the repository
|
|
510
|
+
2. Create your feature branch (`git checkout -b feature/amazing-feature`)
|
|
511
|
+
3. Commit your changes (`git commit -m 'Add some amazing feature'`)
|
|
512
|
+
4. Push to the branch (`git push origin feature/amazing-feature`)
|
|
513
|
+
5. Open a Pull Request
|