Repository navigation
Expand file tree
/
Copy pathsource.go
More file actions
128 lines (117 loc) · 6.93 KB
/
Copy pathsource.go
File metadata and controls
128 lines (117 loc) · 6.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
package pluginsdk
import "context"
// Source is the interface a Marmot plugin implements. Validate checks a
// raw config and returns it (or an error); Discover runs discovery with
// a validated config.
type Source interface {
Validate(config RawConfig) (RawConfig, error)
Discover(ctx context.Context, config RawConfig) (*DiscoveryResult, error)
}
// DataFetcher is an optional Source extension that supplies sample data
// for asset previews. Plugins whose Source implements it are surfaced
// via Meta.SupportsDataPreview.
type DataFetcher interface {
FetchSampleData(ctx context.Context, config RawConfig, a *Asset) (columnNames []string, rows [][]any, err error)
}
// Querier is an optional Source extension that executes queries against the
// underlying engine on behalf of Marmot's data queries. PlanQuery asks the engine
// what a statement would touch without running it; a nil plan with a nil
// error means the engine cannot plan the statement and the host falls back to
// source-level policy. Hosts plan a statement before checking whether the
// caller may run it, so PlanQuery must have no side effects for any input:
// refuse statements that are not reads before handing them to the engine.
// ExecuteQuery runs the statement and pushes result chunks through emit; the
// first chunk carries the column schema and an error returned from emit
// aborts the query. Plugins whose Source implements Querier are surfaced via
// Meta.SupportsQuery.
type Querier interface {
PlanQuery(ctx context.Context, config RawConfig, req QueryRequest) (*QueryPlan, error)
ExecuteQuery(ctx context.Context, config RawConfig, req QueryRequest, emit func(chunk QueryResultChunk) error) error
}
// QueryRequest is a single statement the host wants planned or executed.
// MaxRows caps the rows the plugin returns (0 means no cap beyond the
// host's own) and Identity carries the acting principal's name so engines
// that support it can attribute the query.
type QueryRequest struct {
Statement string `json:"statement"`
MaxRows int64 `json:"max_rows,omitempty"`
Identity string `json:"identity,omitempty"`
}
// QueryPlan describes what a statement would touch, in MRN terms so the
// host can make policy decisions without understanding engine SQL.
type QueryPlan struct {
ReferencedMRNs []string `json:"referenced_mrns,omitempty"`
EstimatedBytes int64 `json:"estimated_bytes,omitempty"`
// Incomplete is set when the statement may read data the plan cannot name, such as through a function that runs its own query. Marmot then requires a grant on the whole source, because grants on the listed tables cannot cover what the statement really reads.
Incomplete bool `json:"incomplete,omitempty"`
}
// QueryColumn describes one column of a query result.
type QueryColumn struct {
Name string `json:"name"`
Type string `json:"type,omitempty"`
}
// QueryResultChunk is one batch of query results. Columns is set on the
// first chunk only.
type QueryResultChunk struct {
Columns []QueryColumn `json:"columns,omitempty"`
Rows [][]any `json:"rows,omitempty"`
}
// Meta describes a plugin to the Marmot host: identity, display
// information, and the config spec used to render its settings form.
// Status is one of "stable", "beta", or "experimental". Features lists
// the asset kinds the plugin produces (e.g. "Assets", "Lineage", "Run
// History"). AssetSchemas documents the metadata the plugin attaches to
// the assets it discovers; build them with AssetSchemaOf.
// SupportsDataPreview, SupportsQuery and SupportsTools are set by Serve
// when the plugin's Source implements DataFetcher, Querier or Toolset, and
// Serve fills Tools and ToolsDigest from an Toolset's manifest; plugin
// authors never set any of them.
//
// MarmotVersion is the semver constraint on the Marmot releases the plugin works with, e.g. ">=0.14.0"; leave it empty to support every release that speaks ProtocolVersion. Prefer a lower bound only: a breaking change to the host interface is a protocol bump, not an upper bound. ProtocolVersion is set by Serve.
type Meta struct {
ID string `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
Icon string `json:"icon"`
Category string `json:"category"`
Status string `json:"status"`
Features []string `json:"features,omitempty"`
ConfigSpec []ConfigField `json:"config_spec"`
AssetSchemas []AssetSchema `json:"asset_schemas,omitempty"`
SupportsDataPreview bool `json:"supports_data_preview,omitempty"`
SupportsQuery bool `json:"supports_query,omitempty"`
SupportsTools bool `json:"supports_tools,omitempty"`
Tools []ToolSpec `json:"tools,omitempty"`
ToolsDigest string `json:"tools_digest,omitempty"`
SupportsTriggers bool `json:"supports_triggers,omitempty"`
Triggers []TriggerSpec `json:"triggers,omitempty"`
TriggersDigest string `json:"triggers_digest,omitempty"`
MarmotVersion string `json:"marmot_version,omitempty"`
ProtocolVersion int `json:"protocol_version,omitempty"`
// IdentityScope says how the systems this plugin reads are told apart,
// which decides the zone used when the config sets none. See the
// IdentityScope constants; empty is IdentityScopeNetwork.
IdentityScope IdentityScope `json:"identity_scope,omitempty"`
// Federates is true for a plugin that catalogues assets other systems own, such as Trino, OpenMetadata or dbt, so that when it and the system's own plugin describe the same asset the owner's description, schema and metadata win.
Federates bool `json:"federates,omitempty"`
// ConnectionTestTimeoutSeconds is how long a connection test may run this plugin's discovery before it is stopped, for a plugin whose discovery is slow even on a small source, such as one that must make its API requests one at a time. Zero leaves the host's default, and the host caps it.
ConnectionTestTimeoutSeconds int `json:"connection_test_timeout_seconds,omitempty"`
}
// IdentityScope says what makes one of a plugin's systems different from
// another of the same technology.
type IdentityScope string
const (
// IdentityScopeNetwork is a server reached over the network, such as
// PostgreSQL or Kafka. Without a zone its assets go to the default
// zone, and Marmot can map its host to a zone.
IdentityScopeNetwork IdentityScope = "network"
// IdentityScopeAccount is a cloud service whose account or project is
// already part of every asset's name, such as BigQuery. The zone is
// rarely needed.
IdentityScopeAccount IdentityScope = "account"
// IdentityScopeFile is a file on whichever machine runs the plugin, such
// as a DuckDB or SQLite database. Two engineers' copies of dev.duckdb are
// different databases, so without a zone the CLI gives each machine
// its own, and only an explicit zone shares one.
IdentityScopeFile IdentityScope = "file"
)