# python-sentry-scrubber
Python library to support Sentry data sanitization

## Requirements

- Python 3.11 or higher
- No runtime dependencies

## Installation

**Note:** This library is compatible with Python 3.11 and higher. The code uses type hints and modern Python features.

There are two ways two install `sentry-scrubber` as a dependency in your application.

### Install using pip (`requirements.txt`)

1. Add `-i https://pypi.theorchard.io/pypi/` to the top of `requirements.txt`.
2. `env/bin/pip install -r requirements.txt`

### Install using uv (`pyproject.toml`)

#### pypi.theorchard.com

1. Update `pyproject.toml` to include:

```toml
[[tool.uv.sources]]
sentry-scrubber = { index = "pde" }

[[tool.uv.index]]
name = "pde"
url = "https://pypi.theorchard.io/pypi/"
```

2. Add this to the `dependencies` section in `pyproject.toml`:
```toml
dependencies = [
    "sentry-scrubber>=0.1.0",
]
```

3. Run `uv sync`

#### git+ssh

1. Add this to the `dependencies` section in `pyproject.toml`:

```toml
dependencies = [
    "sentry-scrubber @ git+ssh://git@github.com/theorchard/python-sentry-scrubber@v0.1.0",
]
```

### Install using Poetry (`pyproject.toml`) - Legacy

**Note:** This project has migrated to uv for faster dependency management. Poetry is still supported but uv is recommended.

#### pypi.theorchard.com

1. Update `pyproject.toml` to include:

```toml
[[tool.poetry.source]]
name = "pde"
url = "https://pypi.theorchard.io/pypi/"
priority = "supplemental"
```

2. Add this to the `[tool.poetry.dependencies]` section in `pyproject.toml`:
```toml
[tool.poetry.dependencies]
...
sentry-scrubber = {version = "^0.1.0", source = "pde"}
```

3. Run `poetry lock`

2. Run `poetry lock`

## Contributing

### Dependencies

This library uses Poetry for dependency management. Please use `poetry add` when adding new dependencies. Always add/commit changes made to the `pyproject.toml` and `poetry.lock` files.

Avoid being overly-restrictive when adding installation requirements. [This](https://packaging.python.org/en/latest/discussions/install-requires-vs-requirements/) has a good overview of considerations when specifying what is required to install sentry-scrubber. A few key quotes:

> It’s best practice to indicate any known lower or upper bounds
> It is not considered best practice to use install_requires to pin dependencies to specific versions, or to specify sub-dependencies (i.e. dependencies of your dependencies). This is overly-restrictive, and prevents the user from gaining the benefit of dependency upgrades.

## Development

This project uses [uv](https://docs.astral.sh/uv/) for fast Python dependency management. uv is significantly faster than Poetry (often 10-100x) and provides better dependency resolution.

### Setup Development Environment

1. Install uv:
```bash
curl -LsSf https://astral.sh/uv/install.sh | sh
```

2. Set up the development environment:
```bash
./setup-dev.sh
# OR manually:
uv sync --group dev
```

### Adding Dependencies

For runtime dependencies:
```bash
uv add <package-name>
```

For development dependencies:
```bash
uv add --group dev <package-name>
```

### Updating Dependencies

Update all dependencies:
```bash
uv sync --upgrade
```

Update specific dependencies:
```bash
uv sync --upgrade-package <package-name>
```

**Legacy Poetry Support:** If you need to use Poetry, indicate development dependencies using `poetry add <the new dependency> --group dev` and run `poetry update` to update dependencies.

### `make` targets

You can always use `make help` to view all the documented targets for working in this library. Some common ones are:

```
make env
make lint
make fmt
make test_unit
make docker-test    # Run tests in Docker
make docker-build   # Build Docker test image
```

### Docker Integration

The project includes Docker support for consistent testing across environments:

- `docker-compose.yaml` - Defines the test service configuration
- `Dockerfile` - Multi-stage Docker image for running tests and linting
- `lint-and-test.sh` - Script that runs both linting and testing in sequence

Run tests in Docker:
```bash
make docker-test
```

This will:
1. Generate a `requirements-dev.txt` from `pyproject.toml`
2. Build a Docker image with all dependencies
3. Run linting (mypy, ruff check, ruff format)
4. Run the full test suite with coverage

### Jenkins CI/CD

The project includes a `Jenkinsfile` for automated CI/CD with the following stages:

1. **Load Shared Libraries** - Loads Jenkins shared library functions
2. **Compliance Checks** - Runs compliance validation
3. **Unit Tests and Style Checks** - Executes `docker compose run --rm --build -T lint-and-test`
4. **Static Application Security Tests** - Runs SAST analysis

The pipeline can be triggered by:
- Push events to the repository
- Pull request comments containing "retest this please"

Jenkins will use Docker Compose to ensure consistent test environments across different build agents.

### Packaging/Versioning

Use semver and [Jenkins Pipeline](https://pipeline.theorchard.io/job/publish-pypi-package-v2/) to build/publish new versions of this library to the private PyPI repository at [pypi.theorchard.io](https://pypi.theorchard.io) (currently only available if you are on our VPN).

After a release tag has been pushed to Github, use the Github UI to Create a Release from the tag. Start from the autogenerated notes, and add salient details to the change(s) being added. This will be used by clients of the library to determine what to expect when upgrading (easy vs breaking?).
