sdk

package
v1.0.0-beta1 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2025 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package sdk provides access to the Airflow objects (Variables, Connection, XCom etc) during run time for tasks.

Index

Constants

View Source
const (
	VariableEnvPrefix   = "AIRFLOW_VAR_"
	ConnectionEnvPrefix = "AIRFLOW_CONN_"
)

Variables

View Source
var ConnectionNotFound = errors.New("connection not found")

ConnectionNotFound is an error value used to signal that a connection could not be found (and that there were no communication issues to the API server).

See the “GetConnection“ method of ConnectionClient for an example

View Source
var VariableNotFound = errors.New("variable not found")

VariableNotFound is an error value used to signal that a variable could not be found (and that there were no communication issues to the API server).

See the “GetVariable“ method of VariableClient for an example

View Source
var XComNotFound = errors.New("xcom not found")

Functions

This section is empty.

Types

type Client

type Client interface {
	VariableClient
	ConnectionClient
	XComClient
}

func NewClient

func NewClient() Client

type Connection

type Connection struct {
	ID string

	// The Connection type, as defined in Airflow
	Type string

	Host string
	Port int

	// Login/username of the connection. Optional, can be nil (nil is an indication of no login which is distinct from an empty login)
	Login *string
	// Password of the connection. Optional, can be nil.
	Password *string

	// The path. Called `Schema` in Airflow python code. For database connections this often contains the
	// database name.
	Path string

	Extra map[string]any
}

func (Connection) GetURI

func (c Connection) GetURI() *url.URL

type ConnectionClient

type ConnectionClient interface {
	// GetConnection returns the value of an Airflow Connection.
	//
	// If the conn is not found error will be a wrapped “ConnectionNotFound“:
	//
	//		conn, err := client.GetConnection(ctx, "my-db")
	//		if errors.Is(err, ConnectinNotFound) {
	//				// Handle not found, set default, return custom error etc
	//		} else {
	//				// Other errors here, such as http network timeouts etc.
	//		}
	GetConnection(ctx context.Context, connID string) (Connection, error)
}

type VariableClient

type VariableClient interface {
	// GetVariable returns the value of an Airflow Variable.
	//
	// It will first look in the os.environ for the appropriately named variable, and if not found there will
	// fallback to asking the API server
	//
	// If the variable is not found error will be a wrapped “VariableNotFound“:
	//
	//		val, err := client.GetVariable(ctx, "my-var")
	//		if errors.Is(err, VariableNotFound) {
	//				// Handle not found, set default, return custom error etc
	//		} else {
	//				// Other errors here, such as http network timeouts etc.
	//		}
	GetVariable(ctx context.Context, key string) (string, error)
	UnmarshalJSONVariable(ctx context.Context, key string, pointer any) error
}

type XComClient

type XComClient interface {
	GetXCom(
		ctx context.Context,
		dagId, runId, taskId string,
		mapIndex *int,
		key string,
		value any,
	) (any, error)
	PushXCom(ctx context.Context, ti api.TaskInstance, key string, value any) error
}

Jump to

Keyboard shortcuts

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