templates

package
v0.1.8 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package templates provides template client services for the remote-signer.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type API

type API interface {
	List(ctx context.Context, filter *ListFilter) (*ListResponse, error)
	Get(ctx context.Context, templateID string) (*Template, error)
	Create(ctx context.Context, req *CreateRequest) (*Template, error)
	Update(ctx context.Context, templateID string, req *UpdateRequest) (*Template, error)
	Delete(ctx context.Context, templateID string) error
	Instantiate(ctx context.Context, templateID string, req *InstantiateRequest) (*InstantiateResponse, error)
	RevokeInstance(ctx context.Context, ruleID string) (*RevokeInstanceResponse, error)
}

API defines the template service interface.

type BudgetConfig

type BudgetConfig struct {
	MaxTotal   string `json:"max_total"`
	MaxPerTx   string `json:"max_per_tx"`
	MaxTxCount int    `json:"max_tx_count,omitempty"`
	AlertPct   int    `json:"alert_pct,omitempty"`
}

BudgetConfig defines budget limits for an instance.

type CreateRequest

type CreateRequest struct {
	Name           string                 `json:"name"`
	Description    string                 `json:"description,omitempty"`
	Type           string                 `json:"type"`
	Mode           string                 `json:"mode"`
	Variables      []TemplateVariable     `json:"variables,omitempty"`
	Config         map[string]interface{} `json:"config"`
	BudgetMetering map[string]interface{} `json:"budget_metering,omitempty"`
	TestVariables  map[string]string      `json:"test_variables,omitempty"`
	Enabled        bool                   `json:"enabled"`
}

CreateRequest represents a request to create a new template.

type InstantiateRequest

type InstantiateRequest struct {
	TemplateName  string            `json:"template_name,omitempty"`
	Name          string            `json:"name,omitempty"`
	Variables     map[string]string `json:"variables"`
	ChainType     *string           `json:"chain_type,omitempty"`
	ChainID       *string           `json:"chain_id,omitempty"`
	APIKeyID      *string           `json:"api_key_id,omitempty"`
	SignerAddress *string           `json:"signer_address,omitempty"`
	ExpiresAt     *time.Time        `json:"expires_at,omitempty"`
	ExpiresIn     *string           `json:"expires_in,omitempty"`
	Budget        *BudgetConfig     `json:"budget,omitempty"`
	Schedule      *ScheduleConfig   `json:"schedule,omitempty"`
}

InstantiateRequest represents a request to create a rule instance from a template.

type InstantiateResponse

type InstantiateResponse struct {
	Rule   json.RawMessage `json:"rule"`
	Budget json.RawMessage `json:"budget,omitempty"`
}

InstantiateResponse represents the response from creating a rule instance.

type ListFilter

type ListFilter struct {
	Type    string
	Source  string
	Enabled *bool
	Limit   int
	Offset  int
}

ListFilter contains filter options for listing templates.

type ListResponse

type ListResponse struct {
	Templates []Template `json:"templates"`
	Total     int        `json:"total"`
}

ListResponse represents the response from listing templates.

type RevokeInstanceResponse

type RevokeInstanceResponse struct {
	Status string `json:"status"`
	RuleID string `json:"rule_id"`
}

RevokeInstanceResponse represents the response from revoking an instance.

type ScheduleConfig

type ScheduleConfig struct {
	Period  string     `json:"period"`
	StartAt *time.Time `json:"start_at,omitempty"`
}

ScheduleConfig defines periodic budget renewal.

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service handles template operations.

func NewService

func NewService(t *transport.Transport) *Service

NewService creates a new template service.

func (*Service) Create

func (s *Service) Create(ctx context.Context, req *CreateRequest) (*Template, error)

Create creates a new rule template (admin only).

func (*Service) Delete

func (s *Service) Delete(ctx context.Context, templateID string) error

Delete deletes a template by ID (admin only).

func (*Service) Get

func (s *Service) Get(ctx context.Context, templateID string) (*Template, error)

Get retrieves a specific template by ID.

func (*Service) Instantiate

func (s *Service) Instantiate(ctx context.Context, templateID string, req *InstantiateRequest) (*InstantiateResponse, error)

Instantiate creates a rule instance from a template (admin only).

func (*Service) List

func (s *Service) List(ctx context.Context, filter *ListFilter) (*ListResponse, error)

List lists rule templates with optional filters.

func (*Service) RevokeInstance

func (s *Service) RevokeInstance(ctx context.Context, ruleID string) (*RevokeInstanceResponse, error)

RevokeInstance revokes (disables) a rule instance created from a template (admin only).

func (*Service) Update

func (s *Service) Update(ctx context.Context, templateID string, req *UpdateRequest) (*Template, error)

Update updates an existing template (admin only).

type Template

type Template struct {
	ID             string             `json:"id"`
	Name           string             `json:"name"`
	Description    string             `json:"description,omitempty"`
	Type           string             `json:"type"`
	Mode           string             `json:"mode"`
	Source         string             `json:"source"`
	Variables      []TemplateVariable `json:"variables,omitempty"`
	Config         json.RawMessage    `json:"config,omitempty"`
	BudgetMetering json.RawMessage    `json:"budget_metering,omitempty"`
	Enabled        bool               `json:"enabled"`
	CreatedAt      time.Time          `json:"created_at"`
	UpdatedAt      time.Time          `json:"updated_at"`
}

Template represents a rule template.

type TemplateVariable

type TemplateVariable struct {
	Name        string `json:"name"`
	Type        string `json:"type"`
	Description string `json:"description,omitempty"`
	Required    bool   `json:"required"`
	Default     string `json:"default,omitempty"`
}

TemplateVariable describes a variable in a rule template.

type UpdateRequest

type UpdateRequest struct {
	Name        string                 `json:"name,omitempty"`
	Description string                 `json:"description,omitempty"`
	Config      map[string]interface{} `json:"config,omitempty"`
	Enabled     *bool                  `json:"enabled,omitempty"`
}

UpdateRequest represents a request to update a template.

Jump to

Keyboard shortcuts

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