Documentation
¶
Overview ¶
Package scriptrename renames a managed script (#2875). A rename keeps the script's id, versions, handlers (an endpoint's name and address are its handler's, not the script's), run history, state, grants, application membership and release pins, and changes which version runs not at all.
What the name is used for moves with it. manage_script and run_script take the new name. A run acts as script:<name>, and the files a script's runs write are owned by that principal and found again by it, so the rename moves the files this script created to the new principal in the same transaction, and the next run adds versions to them rather than making new ones. A name another script holds, whoever owns it, is refused: two scripts with one name would act as one principal. A library is loaded by name, and a saved version never changes, so a library any version that can still run loads is not renamed, and the refusal names those versions.
The owner and administrators rename. An agent's rename of a script that is a part of a released application waits on a person (internal/persondecide).
Index ¶
- Constants
- Variables
- func Message(err error) string
- func Properties() map[string]any
- type Actor
- type Approvals
- type Fields
- type Loader
- type Move
- type PostgresStore
- func (s *PostgresStore) Loaders(ctx context.Context, library, exceptID string) ([]Loader, error)
- func (s *PostgresStore) NameHeld(ctx context.Context, name, exceptID string) (bool, error)
- func (s *PostgresStore) Outputs(ctx context.Context, scriptID, principal string) (int, error)
- func (s *PostgresStore) ReleasedIn(ctx context.Context, scriptID string) (string, error)
- func (s *PostgresStore) Rename(ctx context.Context, sc *script.Script, to string) error
- func (s *PostgresStore) Running(ctx context.Context, scriptID string) (bool, error)
- type Preview
- type RefusedError
- type Renamer
- func (r *Renamer) Preview(ctx context.Context, actor Actor, sc *script.Script, to string) (*Preview, error)
- func (r *Renamer) Rename(ctx context.Context, actor Actor, sc *script.Script, to, decided string) (*Result, error)
- func (r *Renamer) RequestRename(ctx context.Context, actor Actor, m Move, reason string) (*approval.Request, error)
- func (r *Renamer) Script(ctx context.Context, actor Actor, id string) (*script.Script, error)
- func (r *Renamer) Tool(ctx context.Context, req *mcp.CallToolRequest, actor Actor, sc *script.Script, ...) *mcp.CallToolResult
- type Result
- type Store
- type WaitingError
Constants ¶
const ( WhyLatest = "latest" WhyRelease = "release" WhyApproved = "approved" WhyRun = "run" )
The reasons a version can run.
const KeyPrefix = "script_rename:"
KeyPrefix is what every script rename's key starts with.
Variables ¶
var ( // ErrNotAllowed is an actor who neither owns the script nor administers. ErrNotAllowed = errors.New("an automation is renamed by its owner and administrators") // ErrNotFound is no such script. ErrNotFound = errors.New("no such automation") )
Errors a caller reads by identity.
Functions ¶
Types ¶
type Actor ¶
type Actor struct {
Email string
Admin bool
// Agent is true for a call an agent made: every manage_script call, and
// a request a tool call made to the platform's own API.
Agent bool
Roles []string
// Persona is the persona the actor's roles resolve to, which an
// approval request names; "" asks Renamer.PersonaOf.
Persona string
}
Actor is who renames.
type Approvals ¶
type Approvals interface {
RenameApproved(ctx context.Context, purpose, subjectID, stamp string) bool
SubmitRename(ctx context.Context, actor approval.Actor, in approval.SubmitRename) (*approval.Request, error)
}
Approvals is the queue an agent's rename waits on.
type Fields ¶
type Fields struct {
// RenameTo is the script's new name.
RenameTo string `json:"rename_to,omitempty"`
// Reason is why, for the person who approves an agent's rename that
// waits on one.
Reason string `json:"reason,omitempty"`
}
Fields are manage_script update's rename fields.
type Loader ¶
type Loader struct {
ScriptID string `json:"script_id"`
Script string `json:"script" example:"sync-invoices"`
Owner string `json:"owner" example:"sam@example.com"`
Version int `json:"version" example:"12"`
// Why is why the version can run: latest (the latest saved version),
// release (an application release pins it, Application names which),
// approved (approved for a form or a handler) or run (a run queued or
// running executes it).
Why string `json:"why" example:"release"`
Application string `json:"application,omitempty" example:"orders-portal"`
}
Loader is one version that can still run and loads a library.
type Move ¶
type Move struct {
ScriptID, From, To string
// Stamp is approval.RenameStamp of the rename.
Stamp string
Changes []string
}
Move is an agent's rename as the person is asked about it.
type PostgresStore ¶
type PostgresStore struct {
*scriptstore.Store
// contains filtered or unexported fields
}
PostgresStore renames scripts in the platform's database.
func (*PostgresStore) Loaders ¶
Loaders is every version of a script other than exceptID that can still run and loads the library.
func (*PostgresStore) Outputs ¶
Outputs counts the files the script created that its principal owns.
func (*PostgresStore) ReleasedIn ¶
ReleasedIn is the application whose release pins the script, "" for none.
type Preview ¶
type Preview struct {
Script string `json:"script" example:"sync-invoices-dev"`
To string `json:"to" example:"sync-invoices"`
// Problem is why the rename is refused, "" when it is not.
Problem string `json:"problem,omitempty"`
// Loaders are the versions that load the library when the rename is
// refused for them.
Loaders []Loader `json:"loaders"`
// Outputs is how many files the script created that move with it.
Outputs int `json:"outputs" example:"4"`
// Stays, Changes and Unchanged are what the rename keeps, what it
// changes, and what it leaves as it is that a reader may expect it to
// change, one sentence each.
Stays []string `json:"stays"`
Changes []string `json:"changes"`
Unchanged []string `json:"unchanged"`
// WaitsOnPerson is true when the caller is an agent and the rename waits
// on a person's decision.
WaitsOnPerson bool `json:"waits_on_person"`
}
Preview is what a rename changes, said before it is made.
type RefusedError ¶
type RefusedError struct {
Msg string
// Loaders are the versions that load a library a rename was refused
// for.
Loaders []Loader
}
RefusedError is a rename refused for a reason the caller can act on.
func (*RefusedError) Error ¶
func (e *RefusedError) Error() string
type Renamer ¶
type Renamer struct {
Store Store
// Approvals is the queue an agent's rename waits on; nil refuses an
// agent's rename that would wait.
Approvals Approvals
// Audit records each rename; nil records none.
Audit middleware.AuditLogger
// PersonaOf is the persona roles resolve to, which an approval request
// names; nil is none.
PersonaOf func(roles []string) string
// Now is the clock; nil is time.Now.
Now func() time.Time
}
Renamer renames scripts.
func (*Renamer) Preview ¶
func (r *Renamer) Preview(ctx context.Context, actor Actor, sc *script.Script, to string) (*Preview, error)
Preview says what renaming sc to to changes. A rename that would be refused is answered with its Problem, not an error.
func (*Renamer) Rename ¶
func (r *Renamer) Rename(ctx context.Context, actor Actor, sc *script.Script, to, decided string) (*Result, error)
Rename renames sc to to for actor. decided is the key of the rename the person accepted in their client, "" for none. An agent's rename that waits on a person answers a *WaitingError until the person accepts it or a request for it is approved.
func (*Renamer) RequestRename ¶
func (r *Renamer) RequestRename(ctx context.Context, actor Actor, m Move, reason string) (*approval.Request, error)
RequestRename files the request a person decides an agent's rename by, in the portal's Approvals, when the agent's client cannot ask them, with the agent's reason.
type Result ¶
type Result struct {
ID string `json:"id"`
Name string `json:"name" example:"sync-invoices"`
RenamedFrom string `json:"renamed_from" example:"sync-invoices-dev"`
Outputs int `json:"outputs" example:"4"`
Changes []string `json:"changes"`
}
Result is a rename carried out.
type Store ¶
type Store interface {
GetByID(ctx context.Context, id string) (*script.Script, error)
// NameHeld reports whether a script other than exceptID holds name.
NameHeld(ctx context.Context, name, exceptID string) (bool, error)
// Loaders is every version of a script other than exceptID that can
// still run and loads the library named library.
Loaders(ctx context.Context, library, exceptID string) ([]Loader, error)
// Outputs counts the files the script created that its principal owns.
Outputs(ctx context.Context, scriptID, principal string) (int, error)
// ReleasedIn is the application whose release pins the script, "" for
// none.
ReleasedIn(ctx context.Context, scriptID string) (string, error)
// Running reports whether a run of the script is running.
Running(ctx context.Context, scriptID string) (bool, error)
// Rename renames the script from sc.Name to to and moves the files it
// created from its old principal to its new one, in one transaction,
// refusing a script renamed meanwhile.
Rename(ctx context.Context, sc *script.Script, to string) error
}
Store reads and renames scripts.
type WaitingError ¶
type WaitingError struct{ Move Move }
WaitingError is an agent's rename that waits on the person.
func (*WaitingError) Error ¶
func (e *WaitingError) Error() string
func (*WaitingError) Waiting ¶
func (e *WaitingError) Waiting() persondecide.Move
Waiting is the move, which is how internal/persondecide asks the person.