-
Notifications
You must be signed in to change notification settings - Fork 2
Planning codebase modernization and reliability improvements #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
Copilot
wants to merge
3
commits into
master
Choose a base branch
from
copilot/modernize-codebase-and-add-tests
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| # OSniffy runtime configuration | ||
| # Copy this file to `.env` and replace placeholders. | ||
| # Never commit real credentials. | ||
|
|
||
| # --- MySQL write path (app runtime user: INSERT/SELECT on target table) --- | ||
| MYSQL_HOST="127.0.0.1" | ||
| DB_NAME="OSniffy" | ||
| TABLE_NAME="packets" | ||
| MYSQL_USER="osniffy_ingest" | ||
| MYSQL_PASS="replace-with-strong-password" | ||
|
|
||
| # --- MySQL read-only path (Grafana datasource user: SELECT only) --- | ||
| MYSQL_USER_GRAFANA="osniffy_grafana_ro" | ||
| MYSQL_PASS_GRAFANA="replace-with-strong-password" | ||
|
|
||
| # --- Grafana --- | ||
| GRAFANA_HOST="127.0.0.1" | ||
| GRAFANA_PORT=3000 | ||
| # Service account token with minimal dashboard/datasource scope | ||
| GRAFANA_API_KEY="replace-with-service-account-token" | ||
|
|
||
| # Optional desktop user for browser launch when app runs as root | ||
| CLIENT="your-local-username" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,132 @@ | ||
| name: CI | ||
|
|
||
| on: | ||
| push: | ||
| branches: ["master", "main"] | ||
| pull_request: | ||
| branches: ["master", "main"] | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| # Cancel in-progress runs for the same branch so merged PRs don't waste runners. | ||
| concurrency: | ||
| group: ${{ github.workflow }}-${{ github.ref }} | ||
| cancel-in-progress: true | ||
|
|
||
| jobs: | ||
| # -------------------------------------------------------------------------- | ||
| # Lint & static analysis | ||
| # -------------------------------------------------------------------------- | ||
| lint: | ||
| name: Lint & Type-check | ||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| - uses: actions/checkout@v4 | ||
|
|
||
| - uses: actions/setup-python@v5 | ||
| with: | ||
| python-version: "3.12" | ||
|
|
||
| - name: Install linting tools | ||
| run: pip install ruff mypy types-requests | ||
|
|
||
| - name: Ruff – lint | ||
| run: ruff check osniffy/ tests/ | ||
|
|
||
| - name: Ruff – format check | ||
| run: ruff format --check osniffy/ tests/ | ||
|
|
||
| - name: Mypy – type check | ||
| run: mypy osniffy/ | ||
|
|
||
| # -------------------------------------------------------------------------- | ||
| # Test matrix | ||
| # -------------------------------------------------------------------------- | ||
| test: | ||
| name: Tests – Python ${{ matrix.python-version }} | ||
| runs-on: ubuntu-latest | ||
| needs: lint | ||
|
|
||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| python-version: ["3.11", "3.12", "3.13"] | ||
|
|
||
| steps: | ||
| - uses: actions/checkout@v4 | ||
|
|
||
| - uses: actions/setup-python@v5 | ||
| with: | ||
| python-version: ${{ matrix.python-version }} | ||
|
|
||
| - name: Install system dependencies | ||
| run: sudo apt-get install -y libpcap-dev | ||
|
|
||
| - name: Install package with dev dependencies | ||
| run: pip install -e ".[dev]" | ||
|
|
||
| - name: Run tests with coverage | ||
| run: pytest --cov=osniffy --cov-report=xml --cov-report=term-missing | ||
|
|
||
| - name: Upload coverage to Codecov | ||
| if: matrix.python-version == '3.12' | ||
| uses: codecov/codecov-action@v5 | ||
| with: | ||
| file: coverage.xml | ||
| fail_ci_if_error: false | ||
|
|
||
| # -------------------------------------------------------------------------- | ||
| # Package build integrity check | ||
| # -------------------------------------------------------------------------- | ||
| package: | ||
|
github-advanced-security[bot] marked this conversation as resolved.
Fixed
|
||
| name: Build package | ||
| runs-on: ubuntu-latest | ||
| needs: lint | ||
|
|
||
| steps: | ||
| - uses: actions/checkout@v4 | ||
|
|
||
| - uses: actions/setup-python@v5 | ||
| with: | ||
| python-version: "3.12" | ||
|
|
||
| - name: Install system dependencies | ||
| run: sudo apt-get install -y libpcap-dev | ||
|
|
||
| - name: Install build tools | ||
| run: pip install build hatchling | ||
|
|
||
| - name: Build sdist and wheel | ||
| run: python -m build | ||
|
|
||
| - name: Verify package contents | ||
| run: | | ||
| pip install dist/*.whl | ||
| python -c "import osniffy; print(osniffy.__version__)" | ||
|
|
||
| # -------------------------------------------------------------------------- | ||
| # Dependency vulnerability scan | ||
| # -------------------------------------------------------------------------- | ||
| security: | ||
|
github-advanced-security[bot] marked this conversation as resolved.
Fixed
|
||
| name: Dependency vulnerability scan | ||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| - uses: actions/checkout@v4 | ||
|
|
||
| - uses: actions/setup-python@v5 | ||
| with: | ||
| python-version: "3.12" | ||
|
|
||
| - name: Install pip-audit | ||
| run: pip install pip-audit | ||
|
|
||
| - name: Install project dependencies | ||
| run: | | ||
| sudo apt-get install -y libpcap-dev | ||
| pip install -e . | ||
|
|
||
| - name: Audit dependencies | ||
| run: pip-audit --progress-spinner=off | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| name: Release | ||
|
|
||
| on: | ||
| push: | ||
| tags: | ||
| - "v*" | ||
|
|
||
| permissions: | ||
| contents: write | ||
|
|
||
| jobs: | ||
| build-and-release: | ||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| - uses: actions/checkout@v4 | ||
|
|
||
| - uses: actions/setup-python@v5 | ||
| with: | ||
| python-version: "3.12" | ||
|
|
||
| - name: Install system dependencies | ||
| run: sudo apt-get install -y libpcap-dev | ||
|
|
||
| - name: Install build dependencies | ||
| run: pip install build | ||
|
|
||
| - name: Build distributions | ||
| run: python -m build | ||
|
|
||
| - name: Generate checksums | ||
| run: sha256sum dist/* > dist/SHA256SUMS.txt | ||
|
|
||
| - name: Create GitHub release | ||
| uses: softprops/action-gh-release@v2 | ||
| with: | ||
| generate_release_notes: true | ||
| files: | | ||
| dist/* | ||
| CHANGELOG.md |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| # Changelog | ||
|
|
||
| All notable changes to this project are documented here. | ||
|
|
||
| ## [Unreleased] | ||
|
|
||
| ### Added | ||
|
|
||
| - Modern Python package layout under `osniffy/` with executable CLI entrypoint. | ||
| - Centralized project metadata and tooling in `pyproject.toml`. | ||
| - Strong test suite for parser, config, CLI, DB repository, reader, dashboard, and sniffer behavior. | ||
| - CI workflow with lint, format-check, type-check, tests, build verification, and dependency audit. | ||
| - Declarative Grafana provisioning assets under `grafana/provisioning/`. | ||
| - Root `.env.example`, `CONTRIBUTING.md`, and architecture/spec updates in `README.md`. | ||
|
|
||
| ### Changed | ||
|
|
||
| - Import-time side effects moved into explicit startup flow. | ||
| - Structured logging and explicit exit-code handling in CLI paths. | ||
| - Packet persistence logic hardened with batching, retries, rollback, and filtering. | ||
|
|
||
| ### Security | ||
|
|
||
| - Added dependency audit in CI. | ||
| - Documented least-privilege DB user model and privileged capture requirements. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| # Contributing | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| - Python 3.11+ | ||
| - Linux recommended for sniffer-mode development | ||
| - `libpcap-dev` installed for `python-libpcap` builds | ||
|
|
||
| ## Local setup | ||
|
|
||
| ```bash | ||
| cp .env.example .env | ||
| pip install -e ".[dev]" | ||
| ``` | ||
|
|
||
| ## Development workflow | ||
|
|
||
| 1. Create a feature branch. | ||
| 2. Make focused changes. | ||
| 3. Run quality gates locally. | ||
| 4. Open a pull request with a clear summary and test evidence. | ||
|
|
||
| ## Required checks | ||
|
|
||
| ```bash | ||
| ruff check osniffy/ tests/ | ||
| ruff format --check osniffy/ tests/ | ||
| mypy osniffy/ | ||
| pytest | ||
| ``` | ||
|
|
||
| ## Testing guidance | ||
|
|
||
| - Add unit tests for parser/config/CLI/DB logic changes. | ||
| - Keep tests deterministic; prefer fixture bytes over live traffic. | ||
| - For integration behavior, use mocks or ephemeral infrastructure. | ||
|
|
||
| ## Security expectations | ||
|
|
||
| - Never commit credentials, API tokens, or real `.env` files. | ||
| - Prefer least-privilege DB roles. | ||
| - Document any raw-socket or privileged runtime assumptions in PRs. |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.