Skip to main content

HarmontClient

Struct HarmontClient 

Source
pub struct HarmontClient { /* private fields */ }
Expand description

A configured client for the Harmont Cloud API.

Construct with HarmontClient::new (prod) or HarmontClient::with_base_url (self-hosted / local dev). The bearer token is attached to every request via a preconfigured reqwest::Client.

Implementations§

Source§

impl HarmontClient

Source

pub fn new(token: impl Into<String>) -> Self

Create a client against the production API.

Source

pub fn with_base_url(token: impl Into<String>, base: impl Into<String>) -> Self

Create a client against an explicit base URL.

§Panics

Panics if token contains characters that are invalid for an HTTP header value (e.g. non-ASCII or control characters).

Source

pub fn anonymous(base: impl Into<String>) -> Self

Create a client with no credentials, for anonymous endpoints (the CLI auth flows: redeem/claim). Sends no Authorization header.

Source

pub fn base_url(&self) -> &str

The configured base URL.

Source

pub fn raw(&self) -> &RawClient

The raw generated client, for endpoints the high-level API does not wrap.

Source§

impl HarmontClient

Source

pub async fn submit_build(&self, b: NewBuild) -> Result<Build>

Submit a build from a local worktree. Returns the created Build.

Source

pub async fn submit_repo_build(&self, b: NewRepoBuild) -> Result<Build>

Submit a build addressed by (repo_name, source_slug) — the hm run path. Returns the created Build, whose pipeline_slug is the resolved global slug (use it to watch/cancel). Errors carry the server’s structured code/message, including a missing-pipeline 404.

Source

pub async fn get_build( &self, org: &str, pipeline: &str, number: i64, ) -> Result<Build>

Fetch a build by its pipeline-scoped number.

Source

pub async fn list_jobs( &self, org: &str, pipeline: &str, number: i64, ) -> Result<Vec<Job>>

List the jobs of a build.

Source

pub async fn cancel_build( &self, org: &str, pipeline: &str, number: i64, ) -> Result<()>

Cancel a running build.

Source§

impl HarmontClient

Source

pub async fn log_token( &self, org: &str, pipeline: &str, number: i64, ) -> Result<LogToken>

Mint a build-scoped HMAC log token (authorizes every job in the build).

Source

pub async fn stream_job_logs( &self, log_base: &str, job_id: Uuid, token: &str, ) -> Result<impl Stream<Item = Result<LogEvent>>>

Stream a single job’s logs until the done event. log_base is the host serving /v0/jobs/{id}/logs (the web edge, e.g. the API base); token comes from Self::log_token.

Source§

impl HarmontClient

Source

pub async fn redeem_code(&self, code: &str) -> Result<String>

Redeem a paste code for a bearer token (headless login).

The user obtains the paste code from the SPA (which calls the authed GET /api/v0/auth/cli/code endpoint while logged in) and types it into the CLI. Single-use, expires in 5 minutes.

Source

pub async fn claim_token(&self, nonce: &str) -> Result<String>

Claim a loopback-parked token by nonce (browser login).

The CLI generates a random nonce, opens the browser to the SPA, and polls this endpoint until the token appears (the SPA calls the authed POST /api/v0/auth/cli/transfer endpoint). Single-use, expires in 60 seconds. Callers should retry on crate::HarmontError::Api with code cli_code_invalid until the token is claimed or the window closes.

Source

pub async fn create_api_token(&self, description: &str) -> Result<String>

Mint a personal API token (requires an authenticated client).

The raw token is returned once and never retrievable again. Store it securely (e.g. in the system keychain or ~/.config/harmont/token).

Trait Implementations§

Source§

impl Clone for HarmontClient

Source§

fn clone(&self) -> HarmontClient

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for HarmontClient

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more