client

package
v3.9.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 6, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrRequestPreviewed = errors.New("request previewed")

Functions

func APIErrorMessage

func APIErrorMessage(status int, body []byte) string

Types

type Client

type Client struct {

	// NoAccountID, when true, omits the accountIdentifier query param from every
	// request made by this Client. Set by callers that build requests via the
	// Get/Post/Put/Delete/etc. shorthand methods, which don't accept per-request options.
	NoAccountID bool
	// contains filtered or unexported fields
}

Client makes authenticated HTTP requests to the Harness API.

func New

func New(cc *cmdctx.Ctx) *Client

New creates a Client from a command context.

func NewWithAuth

func NewWithAuth(ctx context.Context, resolved *auth.ResolvedAuth) *Client

NewWithAuth creates a Client from a bare context and resolved auth, with no CLI command metadata. Used for pre-command flows like login that have no Ctx.

func (*Client) Delete

func (c *Client) Delete(path string, queryParams map[string]string) (any, http.Header, error)

Delete performs a DELETE request.

func (*Client) DeleteWithBody

func (c *Client) DeleteWithBody(path string, queryParams map[string]string, body any) (any, http.Header, error)

DeleteWithBody performs a DELETE request with a JSON body.

func (*Client) DoRaw

func (c *Client) DoRaw(r Request) (*http.Response, error)

DoRaw executes a Request and returns the raw *http.Response. The caller is responsible for closing resp.Body. Use this for binary responses or large downloads.

func (*Client) DoRequest

func (c *Client) DoRequest(r Request) (any, http.Header, error)

DoRequest executes a Request and returns the decoded JSON response body, response headers, and any error. If Body is a string, it is sent as-is using BodyContentType. Otherwise Body is JSON-marshaled and BodyContentType defaults to "application/json". Extra per-request headers may be set via Headers.

func (*Client) DoStream

func (c *Client) DoStream(r Request, timeout time.Duration) (*http.Response, error)

DoStream executes a Request using a long-lived HTTP client suitable for streaming responses (e.g. SSE). Returns the raw *http.Response; the caller is responsible for closing resp.Body.

func (*Client) Get

func (c *Client) Get(path string, queryParams map[string]string) (any, http.Header, error)

Get performs a GET request.

func (*Client) Patch

func (c *Client) Patch(path string, queryParams map[string]string, body any) (any, http.Header, error)

Patch performs a PATCH request with an optional JSON body.

func (*Client) PatchRaw

func (c *Client) PatchRaw(path string, queryParams map[string]string, body, contentType string) (any, http.Header, error)

PatchRaw performs a PATCH request with a raw string body and explicit Content-Type.

func (*Client) Post

func (c *Client) Post(path string, queryParams map[string]string, body any) (any, http.Header, error)

Post performs a POST request with an optional JSON body.

func (*Client) PostRaw

func (c *Client) PostRaw(path string, queryParams map[string]string, body, contentType string) (any, http.Header, error)

PostRaw performs a POST request with a raw string body and explicit Content-Type.

func (*Client) Put

func (c *Client) Put(path string, queryParams map[string]string, body any) (any, http.Header, error)

Put performs a PUT request with an optional JSON body.

func (*Client) PutRaw

func (c *Client) PutRaw(path string, queryParams map[string]string, body, contentType string) (any, http.Header, error)

PutRaw performs a PUT request with a raw string body and explicit Content-Type.

type Request

type Request struct {
	Method      string
	Path        string
	QueryParams map[string]string
	// Body is always fully materialized: string → sent as-is with BodyContentType;
	// any other type → JSON-marshaled, BodyContentType defaults to "application/json".
	Body            any
	BodyContentType string
	Headers         map[string]string
	// NoAccountID, when true, omits the accountIdentifier query param for this request.
	NoAccountID bool
}

Request describes a single HTTP request to the Harness API.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL