client

package
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: Apache-2.0 Imports: 20 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package client is the REST client of the graphnest command-line tool.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewSecret added in v0.11.0

func NewSecret() string

NewSecret returns 32 random bytes as 43 base64url characters, for PKCE verifiers and state.

func Origin added in v0.11.0

func Origin(serverURL string) (string, error)

Origin returns the scheme and lower-cased host of an http or https URL.

func RevokeLogin added in v0.11.0

func RevokeLogin(ctx context.Context, config Config, login Login) error

RevokeLogin revokes the login's refresh token (RFC 7009).

func StripControl added in v0.11.0

func StripControl(s string) string

StripControl drops control characters from server-provided text before it reaches a terminal.

Types

type Client

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

Client talks to a GraphNest server with a bearer token.

func New

func New(config Config) (*Client, error)

New validates config and builds a client that refuses cross-origin redirects.

func (*Client) GraphStatus

func (c *Client) GraphStatus(ctx context.Context, id int64) (api.GraphStatus, error)

GraphStatus fetches GET /v1/graph/repositories/{id}/status.

func (*Client) Publish

func (c *Client) Publish(ctx context.Context, id int64, commit string, expectedGeneration int64, replaceProducer bool, artifact []byte) (api.GraphPublicationResult, error)

Publish uploads a v2 graph artifact.

func (*Client) Repository

func (c *Client) Repository(ctx context.Context, id int64) (api.RepositorySummary, error)

Repository fetches GET /v1/repositories/{id}.

type Config

type Config struct {
	ServerURL string        // GRAPHNEST_SERVER_URL, required, http or https
	Token     string        // GRAPHNEST_TOKEN, or the trimmed contents of the file named by GRAPHNEST_TOKEN_FILE; at most one may be set; without either, Login supplies the credential
	CAPEM     []byte        // contents of GRAPHNEST_CA_FILE when set
	Timeout   time.Duration // whole-request timeout; zero means 2 minutes
	Login     *Login        // stored OAuth login used instead of Token
	Logins    Logins        // where a refreshed Login is saved
	Source    string        // where the credential came from: "GRAPHNEST_TOKEN", "GRAPHNEST_TOKEN_FILE" or "stored login"
}

Config comes from the environment and the stored login only; a token never comes from arguments.

func FromEnv

func FromEnv(getenv func(string) string, readFile func(string) ([]byte, error), logins Logins) (Config, error)

FromEnv reads Config from environment variables, falling back to the stored login for the server. Errors name variables, never values.

func ServerFromEnv added in v0.11.0

func ServerFromEnv(getenv func(string) string, readFile func(string) ([]byte, error)) (Config, error)

ServerFromEnv reads the server URL and optional CA file. Errors name variables, never values.

type Error

type Error struct {
	Status    int
	Code      string
	Message   string
	Retryable bool
}

Error is the server's error envelope for a non-2xx response.

func (*Error) Error

func (e *Error) Error() string

type Login added in v0.11.0

type Login struct {
	Server             string    `json:"server"`
	ClientID           string    `json:"client_id"`
	AccessToken        string    `json:"access_token"`
	RefreshToken       string    `json:"refresh_token"`
	ExpiresAt          time.Time `json:"expires_at"`
	TokenEndpoint      string    `json:"token_endpoint"`
	RevocationEndpoint string    `json:"revocation_endpoint,omitempty"`
}

Login is a stored OAuth sign-in for one GraphNest server.

type Logins added in v0.11.0

type Logins struct{ Dir string }

Logins stores one <hex sha256(origin)>.json file per server in Dir. The zero value stores nothing.

func (Logins) Delete added in v0.11.0

func (l Logins) Delete(origin string) error

Delete removes the stored login for origin; a missing file is not an error.

func (Logins) Load added in v0.11.0

func (l Logins) Load(origin string) (Login, bool, error)

Load returns the stored login for origin. A missing file, an empty Dir or a file recording another server is not found. Errors never contain file contents.

func (Logins) Save added in v0.11.0

func (l Logins) Save(login Login) error

Save writes login atomically: a synced 0600 temporary file renamed into a 0700 directory.

type OAuth added in v0.11.0

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

OAuth talks to one authorization server whose issuer was verified against the server origin.

func DiscoverOAuth added in v0.11.0

func DiscoverOAuth(ctx context.Context, config Config) (*OAuth, error)

DiscoverOAuth fetches RFC 8414 metadata from the origin of config.ServerURL and checks issuer, PKCE S256 and endpoints.

func (*OAuth) AuthorizationURL added in v0.11.0

func (o *OAuth) AuthorizationURL(clientID, redirectURI, state, verifier string) string

AuthorizationURL builds the authorization request with an S256 challenge for verifier.

func (*OAuth) Exchange added in v0.11.0

func (o *OAuth) Exchange(ctx context.Context, clientID, redirectURI, code, verifier string) (Login, error)

Exchange trades an authorization code for a Login.

func (*OAuth) Register added in v0.11.0

func (o *OAuth) Register(ctx context.Context, redirectURI string) (string, error)

Register creates a public client (RFC 7591) for one login and returns its client_id.

Jump to

Keyboard shortcuts

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