Documentation
¶
Overview ¶
Package steampipe_plugin_sdk makes writing [Steampipe] plugins simple.
Create the Plugin Definition ¶
By convention the Go files for your plugin (except main.go) should reside in a folder with the same name as the plugin.
Create the file <plugin-name>/plugin.go. Implement a function that creates a plugin definition of type plugin.Plugin, and returns a pointer to it.
Examples:
Create the Plugin Entry Point ¶
Create main.go in your plugin root directory. Add a main function, which is the entry point for your plugin.
This function must call plugin.Serve to instantiate your plugin's gRPC server. It should pass the plugin creation function you just wrote
package main
import (
"github.com/turbot/steampipe-plugin-aws/aws"
"github.com/turbot/steampipe-plugin-sdk/v4/plugin"
)
func main() {
plugin.Serve(&plugin.ServeOpts{
PluginFunc: aws.Plugin})
}
Examples:
Add Your First Table Definition ¶
By convention, each table should be implemented in a separate file named table_<table name>.go. Each table will have a single table definition function that returns a pointer to a plugin.Table.
The table definition includes the name and description of the table, a list of column definitions, and the functions to call in order to list the data for all the rows, or to get data for a single row.
Use plugin.Table to define a table.
Add a List Call ¶
This is a function of type plugin.HydrateFunc which calls your API to return all rows in the table. To add, set the property plugin.Plugin.ListConfig
Add a Get Call ¶
If the API supports returning a single item keyed by id, implement a Get call To add, set plugin.Plugin.GetConfig
Add Column Definitions ¶
Use plugin.Column to define columns.
Add Hydrate Functions ¶
A column may be populated by a List or Get call. It may alternatively define a plugin.HydrateFunc that makes an additional API call for each row of the table to populate the column.
Add a hydrate function for a column by setting plugin.Column.Hydrate.
Add Transform Functions ¶
Use transform functions to extract and/or reformat data returned by the hydrate functions.
Logging ¶
A logger is passed to the plugin via the context. You can use the logger to write messages to the log at standard log levels:
logger := plugin.Logger(ctx)
logger.Info("Log message and a variable", myVariable)
The plugin logs are not written to the console, but are written to the plugin logs at ~/.steampipe/logs/plugin-YYYY-MM-DD.log, e.g. ~/.steampipe/logs/plugin-2022-01-01.log.
Steampipe uses https://github.com/hashicorp/go-hclog hclog, which uses standard log levels (TRACE, DEBUG, INFO, WARN, ERROR). By default, the log level is WARN. You set it using the STEAMPIPE_LOG_LEVEL environment variable:
export STEAMPIPE_LOG_LEVEL=TRACE
Set Error Handling behaviour (advanced) ¶
(TODO)
Set Hydrate Dependencies (advanced) ¶
Steampipe parallelizes hydrate functions as much as possible. Sometimes, however, one hydrate function requires the output from another. Use plugin.HydrateConfig to define the dependency.
return &plugin.Table{
Name: "hydrate_columns_dependency",
List: &plugin.ListConfig{
Hydrate: hydrateList,
},
HydrateConfig: []plugin.HydrateConfig{
{
Func: hydrate2,
Depends: []plugin.HydrateFunc{hydrate1},
},
},
Columns: []*plugin.Column{
{Name: "id", Type: proto.ColumnType_INT},
{Name: "hydrate_column_1", Type: proto.ColumnType_STRING, Hydrate: hydrate1},
{Name: "hydrate_column_2", Type: proto.ColumnType_STRING, Hydrate: hydrate2},
},
}
Here, hydrate function hydrate2 is dependent on hydrate1. This means hydrate2 will not execute until hydrate1 has completed and the results are available. hydrate2 can refer to the results from hydrate1 as follows:
func hydrate2(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) {
// NOTE: in this case we know the output of hydrate1 is map[string]interface{} so we cast it accordingly.
// the data should be cast to th appropriate type
hydrate1Results := h.HydrateResults["hydrate1"].(map[string]interface{})
.....
}
Note that:
- Multiple dependencies are supported.
- Circular dependencies will be detected and cause a validation failure.
- The Get and List hydrate functions ***CANNOT*** have dependencies.
Dynamic Tables (advanced) ¶
Use a plugin dynamic_tables when you cannot know a table's schema in advance, e.g. the CSV plugin.
Flow of execution ¶
- A user runs a query.
- Postgres parses the query and sends the parsed request to the FDW.
- The FDW determines which tables and columns are required.
- The FDW calls one or more [HydrateFunc] to fetch API data.
- Each table defines special hydrate functions: List and optionally Get. These will always be called before any other hydrate function in the table, as the other functions typically depend on the List or Get.
- One or more transform functions are called for each column. These extract and/or reformat data returned by the hydrate functions.
- The plugin returns the transformed data to the FDW.
- Steampipe FDW returns the results to the database.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package connection is a cache which may be used by the plugin to store connection specific data, for example credentials and hydrate function results
|
Package connection is a cache which may be used by the plugin to store connection specific data, for example credentials and hydrate function results |
|
docs
|
|
|
dynamic_tables
# Dynamic Tables If plugin.SchemaMode is set to `dynamic`, every time Steampipe starts the plugin's schema will be checked for any changes since the last time it loaded, and re-import the schema if it detects any.
|
# Dynamic Tables If plugin.SchemaMode is set to `dynamic`, every time Steampipe starts the plugin's schema will be checked for any changes since the last time it loaded, and re-import the schema if it detects any. |
|
Package error_helpers contains custom error types and error helper functions
|
Package error_helpers contains custom error types and error helper functions |
|
Package grpc contains the definition of the [PluginServer] which runs the GRPC plugin, and the [PluginClient], which provides a simple interface to access the plugin functions.
|
Package grpc contains the definition of the [PluginServer] which runs the GRPC plugin, and the [PluginClient], which provides a simple interface to access the plugin functions. |
|
proto
Package proto contains [protobuf] definitions and auto generated code for the plugin service interface.
|
Package proto contains [protobuf] definitions and auto generated code for the plugin service interface. |
|
shared
Package shared contains types which are shared between plugin implementation and plugin clients
|
Package shared contains types which are shared between plugin implementation and plugin clients |
|
Package logging contains functions to create the plugin [hclog.Logger]
|
Package logging contains functions to create the plugin [hclog.Logger] |
|
Package plugin provides data structures and functions that enable a plugin to read data from an API and stream it into Postgres tables by way of Steampipe's [foreign data wrapper] (FDW).
|
Package plugin provides data structures and functions that enable a plugin to read data from an API and stream it into Postgres tables by way of Steampipe's [foreign data wrapper] (FDW). |
|
context_key
Package context_key provides keys used to retrieve items from the context
|
Package context_key provides keys used to retrieve items from the context |
|
os_specific
Package os_specific provides OS specific functions to set the file limit
|
Package os_specific provides OS specific functions to set the file limit |
|
quals
Package quals is the SDK representation of a SQL query qualifier, i.e.
|
Package quals is the SDK representation of a SQL query qualifier, i.e. |
|
schema
Package schema provides types used to define the plugin.ConnectionConfigSchema
|
Package schema provides types used to define the plugin.ConnectionConfigSchema |
|
transform
Package transform defines functions that modify plugin.Column values.
|
Package transform defines functions that modify plugin.Column values. |
|
Package query_cache is a cache used to store query results.
|
Package query_cache is a cache used to store query results. |
|
Package telemetry provides Open Telemetry support.
|
Package telemetry provides Open Telemetry support. |
|
Package version defines the SDK version
|
Package version defines the SDK version |