scriptrename

package
v1.171.0 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2026 License: Apache-2.0 Imports: 18 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 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

View Source
const (
	WhyLatest   = "latest"
	WhyRelease  = "release"
	WhyApproved = "approved"
	WhyRun      = "run"
)

The reasons a version can run.

View Source
const KeyPrefix = "script_rename:"

KeyPrefix is what every script rename's key starts with.

Variables

View Source
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

func Message

func Message(err error) string

Message is the text a rename's error is answered with: a refusal for a library's loaders names each of them.

func Properties

func Properties() map[string]any

Properties are the fields' schema.

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.

func (Move) Key

func (m Move) Key() string

Key names the rename exactly.

func (Move) Question

func (m Move) Question() string

Question is what the person is asked.

type PostgresStore

type PostgresStore struct {
	*scriptstore.Store
	// contains filtered or unexported fields
}

PostgresStore renames scripts in the platform's database.

func NewStore

func NewStore(db *sql.DB) *PostgresStore

NewStore is the store over db.

func (*PostgresStore) Loaders

func (s *PostgresStore) Loaders(ctx context.Context, library, exceptID string) ([]Loader, error)

Loaders is every version of a script other than exceptID that can still run and loads the library.

func (*PostgresStore) NameHeld

func (s *PostgresStore) NameHeld(ctx context.Context, name, exceptID string) (bool, error)

NameHeld reports whether a script other than exceptID holds name.

func (*PostgresStore) Outputs

func (s *PostgresStore) Outputs(ctx context.Context, scriptID, principal string) (int, error)

Outputs counts the files the script created that its principal owns.

func (*PostgresStore) ReleasedIn

func (s *PostgresStore) ReleasedIn(ctx context.Context, scriptID string) (string, error)

ReleasedIn is the application whose release pins the script, "" for none.

func (*PostgresStore) Rename

func (s *PostgresStore) Rename(ctx context.Context, sc *script.Script, to string) error

Rename renames the script and moves the files it created to its new principal, in one transaction.

func (*PostgresStore) Running

func (s *PostgresStore) Running(ctx context.Context, scriptID string) (bool, error)

Running reports whether a run of the script is running.

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.

func (*Renamer) Script

func (r *Renamer) Script(ctx context.Context, actor Actor, id string) (*script.Script, error)

Script reads a script by id for actor, refusing one actor does not edit.

func (*Renamer) Tool

func (r *Renamer) Tool(ctx context.Context, req *mcp.CallToolRequest, actor Actor, sc *script.Script, in Fields) *mcp.CallToolResult

Tool renames sc for manage_script update rename_to, asking the person through their client, or filing a request, when the rename waits on them.

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.

Jump to

Keyboard shortcuts

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