pub struct Client { /* private fields */ }Expand description
Client is the cleanlib-client HTTP transport handle. Cheap to clone;
share across verbs in the same process.
Implementations§
Source§impl Client
impl Client
Sourcepub fn from_config(config: &Config) -> Result<Self, CleanLibraryError>
pub fn from_config(config: &Config) -> Result<Self, CleanLibraryError>
Construct from a loaded Config. TLS required for non-localhost
endpoints. Returns TlsRequired for http:// on remote hosts.
Sourcepub fn new(
endpoint: &str,
api_key: Option<String>,
) -> Result<Self, CleanLibraryError>
pub fn new( endpoint: &str, api_key: Option<String>, ) -> Result<Self, CleanLibraryError>
Construct with explicit endpoint + api_key. Intended for integration
tests + ad-hoc invocations (e.g., CLI --endpoint= flag future).
Sourcepub async fn fetch_verdict(
&self,
ecosystem: &str,
package: &str,
version: &str,
) -> Result<Verdict, CleanLibraryError>
pub async fn fetch_verdict( &self, ecosystem: &str, package: &str, version: &str, ) -> Result<Verdict, CleanLibraryError>
Fetch a single verdict per App Rev 4 §9.3 +
GET /v1/customer/verdicts/{ecosystem}/{package}/{version}.
Sourcepub async fn scan(
&self,
req: &ScanRequest,
) -> Result<ScanResponse, CleanLibraryError>
pub async fn scan( &self, req: &ScanRequest, ) -> Result<ScanResponse, CleanLibraryError>
Submit a packages + optional-policy request to
POST /v1/scan — batch-resolve verdicts for a set of packages against
the customer’s active policy. Used by cleanlib scan. The App resolves
each package independently (partial-success: a per-package miss lands as
ScanResult.error, not a whole-batch failure), so the caller derives
the gating decision per ScanResult.verdict and aggregates the exit
code (commands::scan).
Distinct endpoint from Self::policy_preview: /v1/scan needs no
policy_yaml. Routing scan through /v1/policy/preview produced a
422 missing field policy_yaml, and the old PolicyPreviewResponse
({decisions}, #[serde(default)]) silently parsed the App’s
{results} body into an empty vec → scan_exit_code(&[]) == 0, a
fail-open on the security gate. Both are closed here.
Sourcepub async fn policy_preview(
&self,
req: &PolicyPreviewRequest,
) -> Result<PolicyPreviewResponse, CleanLibraryError>
pub async fn policy_preview( &self, req: &PolicyPreviewRequest, ) -> Result<PolicyPreviewResponse, CleanLibraryError>
POST /v1/policy/preview. Used by cleanlib policy preview (with an
explicit candidate policy override). NOTE: cleanlib scan uses
Self::scan (/v1/scan), NOT this endpoint.
CLEANLIB-305 DX-fix: corrected from /v1/customer/policy/preview
(which 404s) to /v1/policy/preview (which the App mounts via
verbs_router). Same class of bug as the cycle-14 /v1/audit
fix (see audit below): the /customer/ prefix is used only by
customer_verdicts_router (/v1/customer/verdicts/*); the
cycle-6 verb surface (scan, audit, policy/preview,
risk-accept, fetch/*) mounts flat under /v1.
Sourcepub async fn fetch_artifact(
&self,
ecosystem: &str,
package: &str,
version: &str,
) -> Result<Vec<u8>, CleanLibraryError>
pub async fn fetch_artifact( &self, ecosystem: &str, package: &str, version: &str, ) -> Result<Vec<u8>, CleanLibraryError>
Fetch the raw artifact bytes for (ecosystem, package, version) via
App’s unified catalog-proxy GET /v1/fetch/{ecosystem}/{package}/{version}
(CLEANLIB-302 / CLEANLIB-368). Returns owned Vec<u8> — caller decides
write target. Emits decision + reason headers to stderr for visibility
(binary stdout stays clean).
CLEANLIB-368 route pivot: prior cycles built per-ecosystem registry
paths (/npm/<pkg>/-/<pkg>-<ver>.tgz, /go/<pkg>/@v/<ver>.zip, …)
against the App’s cycle-3 §C.8 nested per-eco routers. Those paths are
legacy registry-mimic shapes that never surfaced the CLEANLIB-302 audit
row (gcs_hit / gcs_object_path / bytes_served) and hard-coded
pypi wheel-variant assumptions that diverge from the real serve path.
The App unifies both under verbs_router at /v1/fetch/* — that is
now the sole client-side route.
Sourcepub async fn fetch_artifact_stream<W>(
&self,
ecosystem: &str,
package: &str,
version: &str,
writer: &mut W,
) -> Result<u64, CleanLibraryError>where
W: AsyncWrite + Unpin,
pub async fn fetch_artifact_stream<W>(
&self,
ecosystem: &str,
package: &str,
version: &str,
writer: &mut W,
) -> Result<u64, CleanLibraryError>where
W: AsyncWrite + Unpin,
Streaming variant of Self::fetch_artifact — writes chunks to
writer without buffering the full body in memory. Per Client Rev 2
amendment §9.4 cycle-4 §D.5 streaming substrate. Returns total bytes
written. Decision + reason headers surface to stderr before stream.
Hits the same unified /v1/fetch/{ecosystem}/{package}/{version}
proxy as Self::fetch_artifact — see the CLEANLIB-368 route pivot
note there.
Sourcepub async fn audit(
&self,
since: Option<&str>,
decision: Option<&str>,
ecosystem: Option<&str>,
) -> Result<AuditResponse, CleanLibraryError>
pub async fn audit( &self, since: Option<&str>, decision: Option<&str>, ecosystem: Option<&str>, ) -> Result<AuditResponse, CleanLibraryError>
Query customer audit log via GET /v1/audit with optional filters.
Caller passes already-validated filter values.
Cycle-14 DX-fix: corrected from /v1/customer/audit (which 404s) to
/v1/audit (which the App mounts via verbs_router). Verified live
against cleanapp.clnstrt.dev 2026-06-05 — direct probe returns 200
with {window, records, backend_status}.
pub async fn probe_auth(&self) -> Result<(), CleanLibraryError>
Sourcepub async fn send(
&self,
method: Method,
url: Url,
) -> Result<Response, CleanLibraryError>
pub async fn send( &self, method: Method, url: Url, ) -> Result<Response, CleanLibraryError>
Low-level: send a request with auth header. Used internally by verb methods; public for advanced consumers (future).
Sourcepub async fn get_ecosystems(&self) -> Result<Vec<String>, CleanLibraryError>
pub async fn get_ecosystems(&self) -> Result<Vec<String>, CleanLibraryError>
Fetch supported ecosystems from GET /health ecosystems_mounted field.