Skip to content

About

A Go client for the Chef Supermarket API

Topics

Resources

Stars

2 stars

Watchers

1 watching

Forks

Latest commit

 

History

54 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

cinc-supermarket-api

A Go client for the Chef Supermarket API.

Install

go get github.com/cinc-project/cinc-supermarket-api

Usage

Read endpoints are anonymous:

c, err := supermarket.NewClient(supermarket.Config{})
if err != nil {
    return err
}
cb, _, err := c.Cookbooks.Get(ctx, "apache2")
if err != nil {
    return err
}

Write endpoints (share, delete) use the Chef mixlib-authentication signed-header protocol (version 1.1, SHA-1 — the version the public Supermarket accepts). The credentials are the Supermarket username and the RSA private key registered on that user's Supermarket profile:

key, err := supermarket.LoadKeyFile("/home/me/.chef/me.pem")
if err != nil {
    return err
}
c, err := supermarket.NewClient(supermarket.Config{Username: "me", Key: key})
if err != nil {
    return err
}
if _, _, err := c.Cookbooks.Share(ctx, "apache2", "Web Servers", tarball); err != nil {
    return err
}

A Client with no credentials refuses write calls with ErrUnauthenticatedWrite without contacting the server.

A private Supermarket whose certificate comes from an internal CA is reached by trusting that CA, which keeps certificate verification on:

pem, err := os.ReadFile("/etc/ssl/internal-ca.pem")
if err != nil {
    return err
}
pool := x509.NewCertPool()
if !pool.AppendCertsFromPEM(pem) {
    return errors.New("no certificates in internal-ca.pem")
}
c, err := supermarket.NewClient(
    supermarket.Config{BaseURL: "https://supermarket.example.internal"},
    supermarket.WithRootCAs(pool))
if err != nil {
    return err
}

WithSkipTLSVerify(true) turns verification off entirely. It is off by default and meant for local testing only.

The universe (every version of every cookbook with its dependencies) is tens of megabytes. Universe.Entries decodes it incrementally and yields one version at a time, so memory stays flat:

for e, err := range c.Universe.Entries(ctx) {
    if err != nil {
        return err // request, HTTP, decode or ctx error; iteration has stopped
    }
    fmt.Println(e.Cookbook, e.Version, e.Dependencies)
}

Breaking out of the loop early closes the response body. There is no total request timeout on this path; bound it with ctx.

Version helpers work on the version strings cookbooks return, without a full semver dependency: CompareVersions(a, b) orders two versions, LatestVersion(versions) picks the newest, and VersionFromURL(u) pulls the dotted version out of a /versions/<v> URL (Supermarket encodes the dots as underscores).

Runnable examples, including pagination, ErrNotFound handling and streaming /universe, are on pkg.go.dev.

Coverage

Resource Endpoint Method
Cookbook GET /api/v1/cookbooks List
Cookbook GET /api/v1/cookbooks/:name Get
Cookbook GET /api/v1/cookbooks/:name/contingent Contingent
Cookbook GET /api/v1/cookbooks/:name/versions/:v GetVersion
Cookbook GET /api/v1/cookbooks/:name/versions/:v/download Download
Cookbook POST /api/v1/cookbooks (signed, multipart) Share
Cookbook DELETE /api/v1/cookbooks/:name (signed) Delete
Cookbook DELETE /api/v1/cookbooks/:name/versions/:v (signed) DeleteVersion
Search GET /api/v1/search Cookbooks
Tools GET /api/v1/tools List
Tools GET /api/v1/tools/:slug Get
Tools GET /api/v1/tools-search Search
Users GET /api/v1/users/:username Get
Universe GET /universe Get
Universe GET /universe (streaming) GetStream
Universe GET /universe (one entry per version) Entries
Health GET /api/v1/health Status
Health GET /api/v1/metrics Metrics

Errors

Non-2xx responses are wrapped in an *ErrorResponse that decodes Supermarket's {error_messages, error_code} envelope. Use errors.Is(err, supermarket.ErrNotFound) (and friends) to check the class of failure rather than the HTTP status. The sentinel is derived from error_code first (production returns 404 with error_code=NOT_FOUND for a missing resource) and falls back to the status code.

Testing

go test ./... runs the unit suite: it's fast, deterministic, and needs neither network nor Ruby. It includes:

  • An always-on signing-version guard (internal/signing) asserting we sign with 1.0 or 1.1. Signing with 1.3 got a 401 on every share against supermarket.chef.io in production; the cause is unknown, so the guard pins the versions observed to work.
  • A contract replay suite that decodes recorded production responses under testdata/contract/ through the public types, so a decoder regression fails CI deterministically.

Two extra layers reach for outside resources and are gated so the default run stays fast:

  • Gem-backed verifier test (internal/signing): runs our signed headers through mixlib-authentication's real server-side SignatureVerification (the gold standard). Its 1.3 case only exercises the test harness's own version gate, not mixlib or Supermarket. It needs Ruby plus the mixlib-authentication gem (gem install mixlib-authentication); without them it skips cleanly rather than failing.

  • Live contract suite — the drift alarm against the real API:

    go test -tags contract ./...
    

    It needs network access to https://supermarket.chef.io and hits the anonymous read endpoints (list + pagination, search, cookbook show, a specific version, /universe, tools, and a user record) through the actual client. It asserts on shape, types, and required fields — not volatile values — and fails (naming the field) if production drifts from what the client depends on. It is intentionally excluded from the default suite.

    Coverage boundary: the live suite covers anonymous reads; the signed write path (share/delete) is guarded deterministically by the version guard and the mixlib verifier test. A true live signed upload still needs a Supermarket account or a local instance — future work.

License

Copyright 2026 The Cinc Project and Tim Smith.

Licensed under the Apache License 2.0. See NOTICE.

About

A Go client for the Chef Supermarket API

Topics

Resources

Stars

2 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages