client

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package client is the HTTP client for the AgentStore server.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetCommitPageLimitForTest

func SetCommitPageLimitForTest(n int)

SetCommitPageLimitForTest overrides the commit page size; for tests only.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client communicates with one AgentStore server.

func New

func New(repoURL string, id *Identity) (*Client, error)

New returns a Client for the given repo URL, signing requests with id (may be nil).

func (*Client) AddAdmin

func (c *Client) AddAdmin(username string) error

AddAdmin grants the admin role (admin only).

func (*Client) AddMember

func (c *Client) AddMember(username string) error

AddMember adds a directory principal to the repo (admin only).

func (*Client) Authz

func (c *Client) Authz() (server.AuthzResponse, error)

Authz returns the caller's repo-wide authority.

func (*Client) CreateRepo

func (c *Client) CreateRepo() error

CreateRepo sends POST /<repo> to create a new repo on the server.

func (*Client) DownloadObject

func (c *Client) DownloadObject(hash string) ([]byte, error)

DownloadObject fetches GET /<repo>/objects/<hash> and returns the raw bytes.

func (*Client) Export

func (c *Client) Export() (server.ExportResponse, error)

Export fetches the repo's access control state (grants + roles) — admin only.

func (*Client) GetAllCommits

func (c *Client) GetAllCommits(since int64) ([]server.CommitJSON, error)

GetAllCommits fetches every commit with seq > since, paginating past the per-request page limit. Used by clone, pull, and mirror so large repos are never silently truncated. Stubs (redacted commits) carry a seq too, so the cursor advances correctly across pages even when some commits are filtered.

func (*Client) GetCommits

func (c *Client) GetCommits(since int64) ([]server.CommitJSON, error)

GetCommits fetches one page of GET /<repo>/commits?since=<seq> (up to commitPageLimit commits, oldest-first). Most callers want GetAllCommits.

func (*Client) GetHeads

func (c *Client) GetHeads() ([]server.HeadJSON, error)

GetHeads fetches GET /<repo>/heads.

func (*Client) GetPrincipals

func (c *Client) GetPrincipals() ([]server.PrincipalJSON, error)

GetPrincipals fetches GET /<repo>/principals — the member roster.

func (*Client) Grant

func (c *Client) Grant(principal, permission, path string) error

Grant sets a grant on the remote.

func (*Client) ListAdmins

func (c *Client) ListAdmins() ([]string, error)

ListAdmins returns the usernames of repo admins.

func (*Client) ListDirectory

func (c *Client) ListDirectory() ([]server.DirectoryEntryResponse, error)

ListDirectory enumerates every principal registered in the remote's directory. Like LookupDirectory it hits the public directory plane, so it is unauthenticated (no repo or identity context required).

func (*Client) ListMembers

func (c *Client) ListMembers() ([]server.PrincipalJSON, error)

ListMembers returns the repo roster.

func (*Client) LookupDirectory

func (c *Client) LookupDirectory(username string) (server.DirectoryEntryResponse, error)

LookupDirectory resolves a username to its directory entry on the remote. The directory is public, so this is unauthenticated (the client may have no identity yet — this is how `bind` discovers an existing principal_id).

func (*Client) Mirror

Mirror uploads a full repo state to an empty target (bootstrap). The request is self-authenticated against the roster carried in the payload. It returns the signer's resulting identity on the target (principal_id preserved; username may be auto-renamed) plus any roster renames.

func (*Client) Permissions

func (c *Client) Permissions(path string) ([]server.PermissionEntry, error)

Permissions lists the grants matching a path.

func (*Client) Push

func (c *Client) Push(req server.PushRequest) (PushResult, error)

Push sends POST /<repo>/commits and returns the result.

func (*Client) Register

func (c *Client) Register(username, publicKey string) (string, error)

Register sends POST /register with a username and public key (the open endpoint). Returns the server-assigned principal_id.

func (*Client) Rekey

func (c *Client) Rekey(publicKey string) error

Rekey sends POST /rekey (signed) to rotate the caller's public key.

func (*Client) RemoveMember

func (c *Client) RemoveMember(username string) error

RemoveMember removes a member from the repo (admin only).

func (*Client) RepoURL

func (c *Client) RepoURL() string

RepoURL returns the full URL of the repo.

func (*Client) Revoke

func (c *Client) Revoke(principal, path string) error

Revoke removes a grant on the remote.

func (*Client) RevokeAdmin

func (c *Client) RevokeAdmin(username string) error

RevokeAdmin revokes the admin role (admin only).

func (*Client) UploadObject

func (c *Client) UploadObject(hash string, data []byte) error

UploadObject sends PUT /<repo>/objects/<hash> with the raw content.

func (*Client) WatchStream

func (c *Client) WatchStream(ctx context.Context, pathPrefix, events string, cursor int64, onEvent func(server.EventJSON)) error

WatchStream opens the watch WebSocket and delivers events to onEvent until the connection closes or ctx is cancelled. It is a single connection — callers add reconnect-with-cursor on top (see RunWatch in the cli package).

func (*Client) WhoAmI

func (c *Client) WhoAmI() (server.WhoAmIResponse, error)

WhoAmI sends GET /whoami (signed) and returns the resolved username.

type Identity

type Identity struct {
	PrincipalID string
	PrivateKey  ed25519.PrivateKey
}

Identity signs requests. When nil, requests are sent unsigned (only valid for the open `register` endpoint).

type PushResult

type PushResult struct {
	ID        string
	Seq       int64
	Conflicts []server.ConflictFile // non-empty on OCC rejection
}

PushResult is the outcome of a Push call.

Jump to

Keyboard shortcuts

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