Private
Public Access
feat: initial Go/JS/Rust Origin check-in client SDKs
CI / rust (push) Successful in 3m6s
CI / go (push) Successful in 33s
CI / js (push) Successful in 34s
CI / rust (push) Successful in 3m6s
CI / go (push) Successful in 33s
CI / js (push) Successful in 34s
Standalone clients that resolve a machine unique ID (OS machine ID first, falling back to a generated UUID persisted to disk), detect hostname/IP/ container/orchestrator, and register+re-ping origin.warky.dev's public service-checkin endpoint on a daily interval. Ported from icy2's internal origincheckin package but extended to the full check-in contract and made dependency-light for external reuse. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
# origin-client (Rust)
|
||||
|
||||
```
|
||||
cargo add origin-client
|
||||
```
|
||||
|
||||
Async, built on `tokio` + `reqwest` (rustls, no OpenSSL dependency).
|
||||
|
||||
## Usage
|
||||
|
||||
```rust
|
||||
use origin_client::{Client, Config};
|
||||
use tokio_util::sync::CancellationToken;
|
||||
|
||||
let client = Client::new(Config {
|
||||
service_key: "...".into(),
|
||||
type_: "myservice".into(),
|
||||
version: "1.2.3".into(),
|
||||
name: "myservice-nova".into(),
|
||||
..Default::default()
|
||||
})?;
|
||||
|
||||
let cancel = CancellationToken::new();
|
||||
tokio::spawn({
|
||||
let cancel = cancel.clone();
|
||||
async move { client.run(cancel).await }
|
||||
}); // immediate check-in, then every 24h until cancel.cancel() is called
|
||||
```
|
||||
|
||||
Call `client.checkin_once().await` directly instead of `run` to send a
|
||||
single check-in and observe the result/error.
|
||||
|
||||
## Config
|
||||
|
||||
| Field | Required | Default |
|
||||
|---|---|---|
|
||||
| `service_key` | yes | — |
|
||||
| `type_`, `version`, `name` | yes | — |
|
||||
| `url` | no | `DEFAULT_URL` (`https://origin.warky.dev/api/public/service-checkin`) |
|
||||
| `app_type` | no | `"rust"` |
|
||||
| `hostname` | no | OS hostname |
|
||||
| `container_id` | no | best-effort Docker/cgroup detection |
|
||||
| `orchestrator` | no | best-effort Kubernetes/Docker detection |
|
||||
| `install_id` | no | OS machine ID, else a generated UUID persisted to `install_id_path` |
|
||||
| `interval_hours` | no | `DEFAULT_INTERVAL_HOURS` (24) |
|
||||
| `logger` | no | discards warnings (`NoopLogger`) |
|
||||
|
||||
`site`, `environment`, `database_type`, `database_name`, `port`,
|
||||
`base_url`, `internal_url`, `description` are optional metadata with no
|
||||
default. `Config` implements `Default`, so use struct-update syntax
|
||||
(`..Default::default()`) as shown above.
|
||||
|
||||
`hostname()`, `outbound_ip()`, `container_id()`, `orchestrator()`, and
|
||||
`resolve_machine_id()` are exported standalone for callers that want the
|
||||
detection logic without the HTTP client.
|
||||
|
||||
## Platform notes
|
||||
|
||||
macOS/Windows machine-ID detection is compiled but not exercised by CI
|
||||
(this repo's CI runs on Linux). `cargo build --target ...` for those
|
||||
targets is a reasonable spot-check before release.
|
||||
Reference in New Issue
Block a user