actions

package
v0.65.0 Latest Latest
Warning

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

Go to latest
Published: May 17, 2022 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LogOutputExtension = ".log"
	LogOutputLocation  = "_lakefs/actions/log"
)
View Source
const (
	HeadersPropertyKey = "headers"
)

Variables

View Source
var (
	ErrInvalidAction         = errors.New("invalid action")
	ErrInvalidEventParameter = errors.New("invalid event parameter")
)
View Source
var ErrIteratorClosed = errors.New("iterator closed")
View Source
var ErrNotFound = errors.New("not found")
View Source
var ErrUnknownHookType = errors.New("unknown hook type")

Functions

func FormatHookOutputPath

func FormatHookOutputPath(runID, hookRunID string) string

func FormatRunManifestOutputPath

func FormatRunManifestOutputPath(runID string) string

func NewHookRunID

func NewHookRunID(actionIdx, hookIdx int) string

Types

type Action

type Action struct {
	Name        string                           `yaml:"name"`
	Description string                           `yaml:"description"`
	On          map[graveler.EventType]*ActionOn `yaml:"on"`
	Hooks       []ActionHook                     `yaml:"hooks"`
}

func LoadActions

func LoadActions(ctx context.Context, source Source, record graveler.HookRecord) ([]*Action, error)

func MatchedActions

func MatchedActions(actions []*Action, spec MatchSpec) ([]*Action, error)

func ParseAction

func ParseAction(data []byte) (*Action, error)

ParseAction helper function to read, parse and validate Action from a reader

func (*Action) Match

func (a *Action) Match(spec MatchSpec) (bool, error)

func (*Action) Validate

func (a *Action) Validate() error

type ActionHook

type ActionHook struct {
	ID          string     `yaml:"id"`
	Type        HookType   `yaml:"type"`
	Description string     `yaml:"description"`
	Properties  Properties `yaml:"properties"`
}

type ActionOn

type ActionOn struct {
	Branches []string `yaml:"branches"`
}

type Airflow added in v0.47.0

type Airflow struct {
	HookBase
	URL        string
	DagID      string
	Username   string
	Password   SecureString
	DAGConf    map[string]interface{}
	Timeout    time.Duration
	WaitForDAG bool
}

func (*Airflow) Run added in v0.47.0

func (a *Airflow) Run(ctx context.Context, record graveler.HookRecord, buf *bytes.Buffer) error

type DBRunResultIterator

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

func NewDBRunResultIterator

func NewDBRunResultIterator(ctx context.Context, db db.Database, fetchSize int, repositoryID string, branchID, commitID string, after string) *DBRunResultIterator

func (*DBRunResultIterator) Close

func (it *DBRunResultIterator) Close()

func (*DBRunResultIterator) Err

func (it *DBRunResultIterator) Err() error

func (*DBRunResultIterator) Next

func (it *DBRunResultIterator) Next() bool

func (*DBRunResultIterator) Value

func (it *DBRunResultIterator) Value() *RunResult

type DBTaskResultIterator

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

func NewDBTaskResultIterator

func NewDBTaskResultIterator(ctx context.Context, db db.Database, fetchSize int, repositoryID, runID, after string) *DBTaskResultIterator

func (*DBTaskResultIterator) Close

func (it *DBTaskResultIterator) Close()

func (*DBTaskResultIterator) Err

func (it *DBTaskResultIterator) Err() error

func (*DBTaskResultIterator) Next

func (it *DBTaskResultIterator) Next() bool

func (*DBTaskResultIterator) Value

func (it *DBTaskResultIterator) Value() *TaskResult

type DagRunReq added in v0.47.0

type DagRunReq struct {
	// DagRunID Run ID. This together with DAG_ID are a unique key.
	DagRunID string `json:"dag_run_id,omitempty"`
	// Conf JSON object describing additional configuration parameters.
	Conf map[string]interface{} `json:"conf,omitempty"`
}

type EventInfo added in v0.47.0

type EventInfo struct {
	EventType      string            `json:"event_type"`
	EventTime      string            `json:"event_time"`
	ActionName     string            `json:"action_name"`
	HookID         string            `json:"hook_id"`
	RepositoryID   string            `json:"repository_id"`
	BranchID       string            `json:"branch_id,omitempty"`
	SourceRef      string            `json:"source_ref,omitempty"`
	TagID          string            `json:"tag_id,omitempty"`
	CommitID       string            `json:"commit_id,omitempty"`
	CommitMessage  string            `json:"commit_message,omitempty"`
	Committer      string            `json:"committer,omitempty"`
	CommitMetadata map[string]string `json:"commit_metadata,omitempty"`
}

type Hook

type Hook interface {
	Run(ctx context.Context, record graveler.HookRecord, buf *bytes.Buffer) error
}

Hook is the abstraction of the basic user-configured runnable building-stone

func NewAirflowHook added in v0.47.0

func NewAirflowHook(h ActionHook, action *Action) (Hook, error)

func NewHook

func NewHook(h ActionHook, a *Action) (Hook, error)

func NewWebhook

func NewWebhook(h ActionHook, action *Action) (Hook, error)

type HookBase added in v0.47.0

type HookBase struct {
	ID         string
	ActionName string
}

type HookOutputWriter

type HookOutputWriter struct {
	StorageNamespace string
	RunID            string
	HookRunID        string
	ActionName       string
	HookID           string
	Writer           OutputWriter
}

func (*HookOutputWriter) OutputWrite

func (h *HookOutputWriter) OutputWrite(ctx context.Context, reader io.Reader, size int64) error

type HookType

type HookType string
const (
	HookTypeWebhook HookType = "webhook"
	HookTypeAirflow HookType = "airflow"
)

type MatchSpec

type MatchSpec struct {
	EventType graveler.EventType
	BranchID  graveler.BranchID
}

type NewHookFunc

type NewHookFunc func(ActionHook, *Action) (Hook, error)

type OutputWriter

type OutputWriter interface {
	OutputWrite(ctx context.Context, storageNamespace, name string, reader io.Reader, size int64) error
}

type Properties added in v0.47.0

type Properties map[string]interface{}

type RunManifest

type RunManifest struct {
	Run      RunResult    `json:"run"`
	HooksRun []TaskResult `json:"hooks,omitempty"`
}

type RunResult

type RunResult struct {
	RunID     string    `db:"run_id" json:"run_id"`
	BranchID  string    `db:"branch_id" json:"branch_id"`
	SourceRef string    `db:"source_ref" json:"source_ref"`
	EventType string    `db:"event_type" json:"event_type"`
	StartTime time.Time `db:"start_time" json:"start_time"`
	EndTime   time.Time `db:"end_time" json:"end_time"`
	Passed    bool      `db:"passed" json:"passed"`
	CommitID  string    `db:"commit_id" json:"commit_id,omitempty"`
}

type RunResultIterator

type RunResultIterator interface {
	Next() bool
	Value() *RunResult
	Err() error
	Close()
}

type SecureString added in v0.48.0

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

SecureString is a string that may be populated from an environment variable. If constructed with a string of the form {{ ENV.EXAMPLE_VARIABLE }}, the value is populated from EXAMPLE_VARIABLE and is considered a secret. Otherwise the value is taken from the string as-is, and is not considered a secret.

func NewSecureString added in v0.48.0

func NewSecureString(s string) (SecureString, error)

NewSecureString creates a new SecureString, reading env var if needed.

func (SecureString) String added in v0.48.0

func (s SecureString) String() string

Returns the string for non-secrets, or asterisks otherwise.

type Service

type Service struct {
	DB     db.Database
	Source Source
	Writer OutputWriter
	// contains filtered or unexported fields
}

func NewService

func NewService(ctx context.Context, db db.Database, source Source, writer OutputWriter, stats stats.Collector, runHooks bool) *Service

func (*Service) GetRunResult

func (s *Service) GetRunResult(ctx context.Context, repositoryID string, runID string) (*RunResult, error)

func (*Service) GetTaskResult

func (s *Service) GetTaskResult(ctx context.Context, repositoryID string, runID string, hookRunID string) (*TaskResult, error)

func (*Service) ListRunResults

func (s *Service) ListRunResults(ctx context.Context, repositoryID string, branchID, commitID string, after string) (RunResultIterator, error)

func (*Service) ListRunTaskResults

func (s *Service) ListRunTaskResults(ctx context.Context, repositoryID string, runID string, after string) (TaskResultIterator, error)

func (*Service) PostCommitHook

func (s *Service) PostCommitHook(ctx context.Context, record graveler.HookRecord) error

func (*Service) PostCreateBranchHook added in v0.62.0

func (s *Service) PostCreateBranchHook(_ context.Context, record graveler.HookRecord)

func (*Service) PostCreateTagHook added in v0.62.0

func (s *Service) PostCreateTagHook(_ context.Context, record graveler.HookRecord)

func (*Service) PostDeleteBranchHook added in v0.62.0

func (s *Service) PostDeleteBranchHook(_ context.Context, record graveler.HookRecord)

func (*Service) PostDeleteTagHook added in v0.62.0

func (s *Service) PostDeleteTagHook(_ context.Context, record graveler.HookRecord)

func (*Service) PostMergeHook

func (s *Service) PostMergeHook(ctx context.Context, record graveler.HookRecord) error

func (*Service) PreCommitHook

func (s *Service) PreCommitHook(ctx context.Context, record graveler.HookRecord) error

func (*Service) PreCreateBranchHook added in v0.62.0

func (s *Service) PreCreateBranchHook(ctx context.Context, record graveler.HookRecord) error

func (*Service) PreCreateTagHook added in v0.62.0

func (s *Service) PreCreateTagHook(ctx context.Context, record graveler.HookRecord) error

func (*Service) PreDeleteBranchHook added in v0.62.0

func (s *Service) PreDeleteBranchHook(ctx context.Context, record graveler.HookRecord) error

func (*Service) PreDeleteTagHook added in v0.62.0

func (s *Service) PreDeleteTagHook(ctx context.Context, record graveler.HookRecord) error

func (*Service) PreMergeHook

func (s *Service) PreMergeHook(ctx context.Context, record graveler.HookRecord) error

func (*Service) Run

func (s *Service) Run(ctx context.Context, record graveler.HookRecord) error

Run load and run actions based on the event information

func (*Service) Stop added in v0.45.1

func (s *Service) Stop()

func (*Service) UpdateCommitID

func (s *Service) UpdateCommitID(ctx context.Context, repositoryID string, storageNamespace string, runID string, commitID string) error

UpdateCommitID assume record is a post event, we use the PreRunID to update the commit_id and save the run manifest again

type Source

type Source interface {
	List(ctx context.Context, record graveler.HookRecord) ([]string, error)
	Load(ctx context.Context, record graveler.HookRecord, name string) ([]byte, error)
}

type Task

type Task struct {
	RunID     string
	HookRunID string
	Action    *Action
	HookID    string
	Hook      Hook
	Err       error
	StartTime time.Time
	EndTime   time.Time
}

type TaskResult

type TaskResult struct {
	RunID      string    `db:"run_id" json:"run_id"`
	HookRunID  string    `db:"hook_run_id" json:"hook_run_id"`
	HookID     string    `db:"hook_id" json:"hook_id"`
	ActionName string    `db:"action_name" json:"action_name"`
	StartTime  time.Time `db:"start_time" json:"start_time"`
	EndTime    time.Time `db:"end_time" json:"end_time"`
	Passed     bool      `db:"passed" json:"passed"`
}

func (*TaskResult) LogPath

func (r *TaskResult) LogPath() string

type TaskResultIterator

type TaskResultIterator interface {
	Next() bool
	Value() *TaskResult
	Err() error
	Close()
}

type Webhook

type Webhook struct {
	HookBase
	URL         string
	Timeout     time.Duration
	QueryParams map[string][]SecureString
	Headers     map[string]SecureString
}

func (*Webhook) Run

func (w *Webhook) Run(ctx context.Context, record graveler.HookRecord, buf *bytes.Buffer) (err error)

Jump to

Keyboard shortcuts

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