2026-11-01 14:11:00 +01:00
# yetano-clients
Shared Go clients for the external services Yetano programs talk to.
This is a library module (`yetano.dev/yetano/yetano-clients` ), imported
like `core` -- nothing here is built or published as a program.
Today it holds the Atlassian clients that `yareco` , `yabaratla` and
`yamcp` used to carry as three separate copies (owner decision
2026-11-01):
| Package | What |
|---|---|
| `atlassian` | `Options` , `Auth` , `Deployment` , `TLS` , the error types (`APIError` , `StatusOf` , `ErrNotJSON` , `ErrResponseTooLarge` , `ErrInvalidArgument` ) |
| `atlassian/jira` | Jira REST API client (Cloud v3 and Server/Data Center v2) |
| `atlassian/confluence` | small Confluence REST API client (classic content API) |
| `atlassian/internal/transport` | the HTTP machinery both share; not importable from outside |
2026-11-21 19:27:57 +01:00
| `yaiam` | sign a command-line program in at yaiam (device flow, RFC 8628) and keep its tokens (YAIAM-710, 2026-11-09); sign a web application's users in (code flow with PKCE) and read users and groups from yaiam's admin API (2026-11-17); trade a user's token for one at another service, for an agent (token exchange, RFC 8693, 2026-11-21) |
2026-11-01 14:11:00 +01:00
Standard library only, no third-party dependencies.
2026-11-09 21:40:58 +01:00
`yaiam` signs a command-line program in at yaiam (device flow) and keeps
its tokens; see below.
2026-11-01 14:11:00 +01:00
## Usage
```go
c , err := jira . New ( atlassian . Options {
BaseURL : "https://example.atlassian.net" ,
Deployment : atlassian . Cloud , // or atlassian.DataCenter
Auth : atlassian . Auth { Type : atlassian . AuthAPIToken , Username : email , Password : token },
Timeout : 60 * time . Second ,
MaxRetries : 3 ,
})
issues , err := c . SearchAll ( ctx , jira . SearchQuery { JQL : "project = DEV" , Fields : [] string { "summary" }})
```
`New` never sends a request. Every call takes a context; cancelling it
also ends a backoff or rate-limit wait.
## Transport behaviour
One `Options` drives both clients:
- **Auth**: `api_token` (e-mail + API token as basic auth, Cloud),
`basic` , `bearer` /`pat` (Data Center personal access token), `cookie`
(a raw Cookie header). The zero `Type` picks from the fields that are
set. A type whose fields are empty sends no header at all.
- **TLS/proxy**: optional CA bundle, explicit `InsecureSkipVerify` ,
`ProxyURL` or the environment's `HTTPS_PROXY` .
- **Redirects** to another host drop `Authorization` and `Cookie`
(also for downloads, e.g. a signed media URL).
- **Retries**: 5xx and connection errors are retried `MaxRetries`
attempts in total with backoff 2s, 4s, ... (cap 30s). 4xx is never
retried.
- **429**: pauses every request of the client until `Retry-After` and
widens a shared minimum gap between requests, which narrows again on
success; up to 10 such retries that do not count against `MaxRetries` .
`DisableRateLimitRetry` returns the 429 at once instead.
- **APIDelay**: fixed pause after every response.
- **Bodies**: an empty 2xx body reads as `{}` ; a non-JSON 2xx body
(e.g. an SSO login page) is `ErrNotJSON` , never an empty result.
`MaxResponseBytes` caps what is read into memory.
- **Errors**: a non-2xx answer is an `*atlassian.APIError` (method,
path, status, body; `Message()` extracts Atlassian's error text).
Credentials never appear in an error or a log line; a download URL's
query is dropped from errors and logs.
- **Pagination**: `Paginate` walks `startAt` /`maxResults` listings and
advances by the number of items actually returned (Jira may cap
`maxResults` ).
## Jira
Typed calls: `Myself` , `ServerInfo` , `ListProjects` , `Project` ,
`ProjectVersions` , `Version` , `UpdateVersion` , `Fields` , `Issue` ,
`Search` /`SearchAll` (Cloud: `/search/jql` with `nextPageToken` ; Data
Center: `/search` with offsets), `SearchPage` (one classic offset page),
`CommentPage` , `Comments` , `Changelog` , `EditMeta` , `Transitions` ,
`EditIssue` /`UpdateIssue` , `CreateIssue` , `AddComment` , `DoTransition` ,
`AssignIssue` , `LinkIssues` ; `TextBody` encodes plain text as ADF on
Cloud and as a string on Data Center. Field helpers for custom fields:
`OptionValues` , `SprintValues` , `CustomFieldNumber` , `Names` .
Everything else goes through the raw `Get` /`Post` /`Put` /`Delete` /
`Paginate` /`DownloadFile` (paths are absolute, e.g.
`/rest/agile/1.0/board` ).
## Confluence
`Search` (CQL), `Page` , `PageChildren` , `Space` , `ListSpaces` ,
`CurrentUser` , `Ping` , `CreatePage` , `UpdatePage` (re-reads the page and
returns `*VersionConflictError` instead of overwriting a newer version),
`AddComment` , `AddLabel` ; `StorageFromText` turns plain text into an
escaped storage-format body. Kept small on purpose -- see `TODO.md` for
what is not covered.
## Where the code came from
| Part | Origin |
|---|---|
| retry/backoff, 429 throttle, `APIDelay` , `Paginate` , `DownloadFile` , cookie auth | `yabaratla/internal/jira` (via `yareco` , which added contexts and `log/slog` ) |
| typed Jira reads, `Search` with `nextPageToken` , field helpers | `yareco/internal/jira` |
| bearer/PAT/basic auth, CA file, proxy, redirect hardening, response cap, Atlassian error messages, Cloud/Data Center split, Jira writes, the Confluence client | `yamcp/internal/provider/atlassian` |
Program-specific parts stayed in the programs: yareco's German operator
messages and field resolution, yamcp's error taxonomy and MCP output
types, yabaratla's Confluence site-backup client.
## Checks
```sh
make # fmt + vet + test (-race) + vulncheck
make test
```
2026-11-09 21:40:58 +01:00
## yaiam
A command-line program signs its user in at yaiam -- or any OpenID
Connect provider with the device flow -- and keeps the tokens:
```go
c := & yaiam . Client { Issuer : "https://login.example.org/t/default" , ClientID : id }
store := yaiam . FileStore { Path : filepath . Join ( stateDir , "token.json" )}
c . Login ( ctx , store , func ( d * yaiam . DeviceAuth ) error {
fmt . Printf ( "Open %s and enter %s\n" , d . VerificationURI , d . UserCode )
return nil
})
err := c . Authorize ( ctx , store , req ) // Bearer header; refreshes when needed
c . Logout ( ctx , store ) // revokes at the provider, forgets them
```
- Only standards: discovery, device authorization, token endpoint
(device code, refresh token), revocation (RFC 7009), UserInfo. A
public client, no secret.
- `FileStore` keeps the tokens in a 0600 file and refuses one others
may read. A stored token is used only for its own issuer and client;
a refused refresh token removes it (`ErrLoginRequired` ).
- Every endpoint must be https (http only on a loopback host), the
discovery document must name exactly the issuer, redirects are never
followed, answers are capped at 1 MiB. Tokens appear in no error, and
`fmt` prints a `Token` without them.
- Checking tokens on the server side is not here: yaiam's
`pkg/httpauth` (JWT against the issuer's keys, optional
introspection).
The user's guide is yaiam's `docs/manual/yetano-programme.md` ; an
example program is yaiam's `examples/device-login` .
2026-11-17 10:54:53 +01:00
### Web applications
A web application signs its users in with `Web` (authorization code
flow with PKCE, a confidential or a public client):
```go
web := & yaiam . Web {
Client : yaiam . Client { Issuer : "https://login.example.org/t/default" , ClientID : id },
ClientSecret : secret ,
RedirectURL : "https://app.example.org/callback" ,
}
web . SignIn ( ctx , w , r , "/after" ) // GET /login: redirect to yaiam
u , err := web . Callback ( ctx , w , r ) // GET /callback: u.Subject, u.Groups, u.Roles, u.ACR ...
out , _ := web . LogoutURL ( ctx , u . IDToken )
```
- `SignIn` keeps a fresh state, nonce and PKCE verifier in a ten-minute
cookie of the browser (HttpOnly, SameSite=Lax, `__Host-` and Secure
on https); `Callback` checks the state against it and removes it.
The return path is a local path only.
- The ID token comes straight from the token endpoint over TLS, so its
signature is not checked (OpenID Connect Core 3.1.3.7) -- no crypto
here: iss, aud (and azp), exp, iat and the nonce are. Profile, groups
and roles come from UserInfo, which must name the same subject.
- The application keeps its own session and its own data under
`Subject` -- it stays when the user is renamed.
2026-11-20 17:32:32 +01:00
- Any OpenID Connect provider works, not only yaiam: set `Scopes` to
what it offers (e.g. `openid email profile` ; the default asks for
yaiam's groups, roles and attributes). `EmailVerified` is true only
for the JSON boolean `true` (some providers send the string).
- `PublicIssuer` : when the application reaches the provider under
another name than the browser does (a container network), the browser
is sent to the endpoints on the public origin; the server keeps
`Issuer` . `AllowInsecure` (on `Client` ) accepts plain http off
loopback, for a test installation on a closed network only.
2026-11-17 10:54:53 +01:00
`Admin` reads a tenant's users, groups and group members from yaiam's
admin API with a service client's token (client credentials, cached
until a minute before it runs out; a refused one is fetched once more).
An example web application is yaiam's `examples/webapp` ; an end-to-end
test against a real yaiam-authd is yaiam's
`internal/oidcprovider/weblogin_test.go` .
2026-11-21 19:27:57 +01:00
### Acting for a user: token exchange
A confidential client that holds a user's access token -- an
application, a gateway, an agent runner like yaais -- trades it for one
at another client of yaiam, on behalf of the same user (RFC 8693, yaiam
ADR-0045). The target has to allow it (`yaiam-ctl client exchange-from
<target> <this client>` ):
```go
x := & yaiam . Exchanger {
Client : yaiam . Client { Issuer : "https://login.example.org/t/default" , ClientID : yaaisID },
ClientSecret : secret , // its token endpoint auth method is basic
}
agent , err := x . Exchange ( ctx , usersAccessToken , yakpoClientID ) // optional: fewer scopes
// ... the agent calls yakpo with agent.AccessToken ...
x . Revoke ( ctx , agent ) // at the end of its job: only this token ends
```
The new token names the user (`sub` ), this client (`client_id` ,
`act.sub` ) and the target alone (`aud` ). It has no refresh token and
ends no later than the user's token; when that one ends (revoked, the
consent withdrawn), so does the exchanged one. Give an agent the
exchanged token, never the user's. The user's token may be one issued to
this client or one another client got for it as its audience (an MCP
client calling a gateway).
2026-11-01 14:11:00 +01:00
## Versioning
A release is a plain semver git tag (`v0.1.0` , ...) on this repository;
consumers require that tag. Never force-move a tag -- always cut a new
one, even for a one-line fix (see the meta-repository's `AGENTS.md` ).
## License
Proprietary, see [LICENSE ](LICENSE ).