Documentation
¶
Overview ¶
Package enterprisetest has an identity provider and an organization's service for tests, as strict as the real ones (spec_053_enterprise EN-12): the provider checks PKCE, the client and its redirect, and keeps the device code pending once; the service rotates refresh tokens, ends a session whose spent one comes back, and serves the person's models with an ETag.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Browse ¶
Browse follows a sign-in address as the browser would: the provider redirects to Blitz's callback on this computer.
func WorkspaceID ¶
WorkspaceID is the fake service's ID for the workspace handle.
Types ¶
type CatalogFile ¶
type CatalogFile struct {
Kind, Name, Lock, Data string
// Groups are who it's for (everyone when none).
Groups []string
// Corrupt serves contents that don't match the file's hash; Missing
// doesn't serve them at all.
Corrupt, Missing bool
}
CatalogFile is a file of the fake service's catalog.
type File ¶
type File struct {
URN string `json:"urn"`
Kind string `json:"kind"`
Title string `json:"title"`
MediaType string `json:"media_type"`
Size int64 `json:"size"`
}
File is a file under a resource name.
type GoingRun ¶
type GoingRun struct {
ServiceRun
Job string `json:"job"`
JobName string `json:"job_name"`
Workspace string `json:"workspace"`
}
GoingRun is a run going now, with its job and workspace.
type Provider ¶
type Provider struct {
*httptest.Server
Mu sync.Mutex
Clients map[string]string // ID → secret
Polls int
NoDevice bool
IDToken string // the ID token it gives, when not the usual
Denied bool // the device code is refused
Bare bool // the discovery document names no endpoints
// contains filtered or unexported fields
}
Provider is an identity provider as strict as Google's: the authorization code only with the PKCE verifier, the client's secret and the same redirect; the device code pending until it's approved.
func NewProvider ¶
NewProvider is a provider with two clients: "desktop" (secret d-secret) and "device" (v-secret). Its ID token is "id-for-<client>".
type RunChange ¶
type RunChange struct {
Run string `json:"run"`
Job string `json:"job"`
Workspace string `json:"workspace"`
Status string `json:"status"`
}
RunChange is one run's change on the runs' stream.
type Service ¶
type Service struct {
*httptest.Server
Mu sync.Mutex
Ended map[string]bool
Access map[string]string // access token → session
ExpiresIn int
Terms string
Refreshes int
SignIns []string // the client each sign-in named
Offline bool
// ListDown makes listing the workspaces fail (503), as a service
// that's slow or restarting does; set with Mu held.
ListDown bool
Tokenless bool // a sign-in or a run's token answered without tokens
// Key signs the branding; Branding is what it serves (none when nil),
// and Terms the version in force, accepted or not, by person.
Key ed25519.PrivateKey
KeyID string
Branding map[string]any
Version string
// Forged signs the branding and catalog with a key the service
// doesn't publish.
Forged bool
// Catalog is the catalog it serves, by path (none when nil): each
// file's lock and contents, under CatalogPolicy; CatalogExpiry is what
// it says the catalog's expiry is. Announce publishes a version on the
// watch stream.
Catalog map[string]CatalogFile
CatalogPolicy map[string]any
CatalogExpiry time.Time
Announce chan int
FileCalls int
// Workspaces are the organization's workspaces, by handle, each a bare
// repository in repos served through Git's smart HTTP at /git/, which
// takes the access token as the password, as the service's proxy does.
Workspaces map[string]Workspace
// Pushes announces a push to a workspace, by handle, on its watch
// stream.
Pushes chan string
ModelCalls int
ModelsFail bool
// Runs are jobs' runs, by ID, each with its secret: a token for the
// secret is an access token as Ana; Ends are how they ended, as each
// runner said (the secret is no good after).
Runs map[string]string
Ends map[string]map[string]any
// Kept are the files each run kept, by run and path; KeepRefused
// refuses them all, as a service without a store does.
Kept map[string]map[string]Artifact
KeepRefused bool
// MaxRunFiles is how many files the service keeps a run, a new one
// past it refused (blitz-enterprise's jobs.MaxRunFiles, 1,000, when 0).
MaxRunFiles int
// ServiceJobs are the jobs the service runs (GET /api/v1/jobs);
// ServiceRuns their runs, by job ID, newest first; Files the files
// under each resource name, and Contents each file's, by its name.
// A job run now gets a running run; JobsRefused refuses every jobs
// call as a license without jobs does.
ServiceJobs []ServiceJob
// Reads are the workspaces whose main was read on request, in order
// (POST /api/v1/workspaces/{handle}/jobs/read).
Reads []string
ServiceRuns map[string][]ServiceRun
Files map[string][]File
Contents map[string]string
JobsRefused bool
// Going are the runs going now (GET /api/v1/runs); RunChanges are
// sent, each as it comes, on every runs' stream.
Going []GoingRun
RunChanges chan RunChange
// EndRunStreams ends the runs' streams open now, as a service that
// restarts does.
EndRunStreams chan struct{}
// Waiting are the runs paused for the person's answer; Answers each
// answer given, by run.
Waiting []GoingRun
Answers map[string]map[string]any
// Usage is GET /api/v1/usage's answer, as JSON.
Usage map[string]any
// Notices are the person's notice settings (JB-31).
Notices map[string]any
// Reviews are the catalog's reviews (POST makes one, open, with each
// file kept in Published); NotAdmin refuses them as to a member.
Reviews []map[string]any
Published map[string]string
NotAdmin bool
// contains filtered or unexported fields
}
Service is the organization's service, as spec 053 EN-12 gives it: a refresh token is good once, and one used again ends its session.
func NewService ¶
NewService is a service whose identity provider is issuer, taking the ID tokens NewProvider gives; it names itself Acme Assist, offers the gateway and jobs, and signs Ana (ana@acme.com) in.
func (*Service) AddWorkspace ¶
AddWorkspace makes a workspace with a first commit (README.md), with the person in role.
type ServiceJob ¶
type ServiceJob struct {
ID string `json:"id"`
URN string `json:"urn"`
Workspace string `json:"workspace"`
Name string `json:"name"`
Schedule string `json:"schedule"`
Enabled bool `json:"enabled"`
// NextRun is when it runs next (nil: not scheduled).
NextRun *time.Time `json:"next_run,omitempty"`
}
ServiceJob is a job the service runs, as GET /api/v1/jobs answers it.
type ServiceRun ¶
type ServiceRun struct {
Pending map[string]string `json:"pending,omitempty"`
ID string `json:"id"`
URN string `json:"urn"`
Trigger string `json:"trigger"`
Status string `json:"status"`
Note string `json:"note,omitempty"`
Output string `json:"output,omitempty"`
CostUSD float64 `json:"cost_usd"`
Created time.Time `json:"created"`
Branch string `json:"branch,omitempty"`
Artifacts string `json:"artifacts,omitempty"`
Merged bool `json:"merged,omitempty"`
MergeNote string `json:"merge_note,omitempty"`
}
ServiceRun is one of its runs.