qri: github.com/qri-io/qri/startf Index | Files | Directories

package startf

import "github.com/qri-io/qri/startf"

Package startf implements dataset transformations using the starlark programming dialect For more info on starlark check github.com/google/starlark


Package Files

entry_reader.go sandbox.go transform.go


var DefaultModuleLoader = func(thread *starlark.Thread, module string) (dict starlark.StringDict, err error) {
    return starlib.Loader(thread, module)

DefaultModuleLoader is the loader ExecScript will use unless configured otherwise

var ErrNotDefined = fmt.Errorf("not defined")

ErrNotDefined is for when a starlark value is not defined or does not exist

var (

    // ErrNtwkDisabled is returned whenever a network call is attempted but h.NetworkEnabled is false
    ErrNtwkDisabled = fmt.Errorf("network use is disabled. http can only be used during download step")
var Version = version.String

Version is the version of qri that this transform was run with

func AddMutateFieldCheck Uses

func AddMutateFieldCheck(check func(path ...string) error) func(o *ExecOpts)

AddMutateFieldCheck provides a checkFunc to ExecScript

func AddQriRepo Uses

func AddQriRepo(repo repo.Repo) func(o *ExecOpts)

AddQriRepo adds a qri repo to execution options, providing scripted access to assets within the respoitory

func DefaultExecOpts Uses

func DefaultExecOpts(o *ExecOpts)

DefaultExecOpts applies default options to an ExecOpts pointer

func Error Uses

func Error(thread *starlark.Thread, _ *starlark.Builtin, args starlark.Tuple, kwargs []starlark.Tuple) (starlark.Value, error)

Error halts program execution with an error

func ExecScript Uses

func ExecScript(ctx context.Context, next, prev *dataset.Dataset, opts ...func(o *ExecOpts)) error

ExecScript executes a transformation against a starlark script file. The next dataset pointer may be modified, while the prev dataset point is read-only. At a bare minimum this function will set transformation details, but starlark scripts can modify many parts of the dataset pointer, including meta, structure, and transform. opts may provide more ways for output to be produced from this function.

func MutatedComponentsFunc Uses

func MutatedComponentsFunc(dsp *dataset.Dataset) func(path ...string) error

MutatedComponentsFunc returns a function for checking if a field has been modified. it's a kind of data structure mutual exclusion lock TODO (b5) - this should be refactored & expanded

func SetOutWriter Uses

func SetOutWriter(w io.Writer) func(o *ExecOpts)

SetOutWriter provides a writer to record the "stderr" diagnostic output of the transform script

func SetSecrets Uses

func SetSecrets(secrets map[string]string) func(o *ExecOpts)

SetSecrets assigns environment secret key-value pairs for script execution

type EntryReader Uses

type EntryReader struct {
    // contains filtered or unexported fields

EntryReader implements the dsio.EntryReader interface for starlark.Iterable's

func NewEntryReader Uses

func NewEntryReader(st *dataset.Structure, iter starlark.Iterable) *EntryReader

NewEntryReader creates a new Entry Reader

func (*EntryReader) Close Uses

func (r *EntryReader) Close() error

Close finalizes the reader

func (*EntryReader) ReadEntry Uses

func (r *EntryReader) ReadEntry() (e dsio.Entry, err error)

ReadEntry reads one entry from the reader

func (*EntryReader) Structure Uses

func (r *EntryReader) Structure() *dataset.Structure

Structure gives this reader's structure

type ExecOpts Uses

type ExecOpts struct {
    Repo             repo.Repo                  // supply a repo to make the 'qri' module available in starlark
    AllowFloat       bool                       // allow floating-point numbers
    AllowSet         bool                       // allow set data type
    AllowLambda      bool                       // allow lambda expressions
    AllowNestedDef   bool                       // allow nested def statements
    Secrets          map[string]interface{}     // passed-in secrets (eg: API keys)
    Globals          starlark.StringDict        // global values to pass for script execution
    MutateFieldCheck func(path ...string) error // func that errors if field specified by path is mutated
    OutWriter        io.Writer                  // provide a writer to record script "stdout" to
    ModuleLoader     ModuleLoader               // starlark module loader function

ExecOpts defines options for execution

type HTTPGuard Uses

type HTTPGuard struct {
    NetworkEnabled bool

HTTPGuard protects network requests, only allowing when network is enabled

func (*HTTPGuard) Allowed Uses

func (h *HTTPGuard) Allowed(req *http.Request) error

Allowed implements starlib/http RequestGuard

func (*HTTPGuard) DisableNtwk Uses

func (h *HTTPGuard) DisableNtwk()

DisableNtwk prevents network calls from succeeding

func (*HTTPGuard) EnableNtwk Uses

func (h *HTTPGuard) EnableNtwk()

EnableNtwk allows network calls

type ModuleLoader Uses

type ModuleLoader func(thread *starlark.Thread, module string) (starlark.StringDict, error)

ModuleLoader is a function that can load starlark modules


dsPackage ds exposes the qri dataset document model into starlark

Package startf imports 20 packages (graph) and is imported by 1 packages. Updated 2020-01-02. Refresh now. Tools for package owners.