steampipe_plugin_sdk

package module
v5.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2022 License: Apache-2.0 Imports: 3 Imported by: 0

README

Steampipe Plugin SDK

Godoc  

This SDK makes it easy to write Steampipe plugins.

Join our Slack community to ask questions, voice ideas, and share your projects.

Resources for contributors

Compiling this SDK To compile the SDK repo, you must install protoc.
brew install protoc
brew install protoc-gen-go-grpc

Documentation

Overview

Define the plugin

A plugin is defined by plugin.Plugin.

Create the file <plugin-name>/plugin.go, then implement a plugin.PluginFunc that creates a plugin.Plugin and returns a pointer to it.

Note: The Go files for your plugin (except main.go) should reside in the <plugin-name> folder.

Examples:

Create the plugin entry point

Create main.go in your plugin's 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, and pass the plugin.PluginFunc that you just wrote.

package main

import (
	"github.com/turbot/steampipe-plugin-aws/aws"
	"github.com/turbot/steampipe-plugin-sdk/v5/plugin"
)

func main() {
	plugin.Serve(&plugin.ServeOpts{
		PluginFunc: aws.Plugin})
}

Examples:

Define your first table

By convention, each table lives in a separate file named table_<table name>.go. Each table has 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 set 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.

Every table MUST define a List and/or Get function.

func tableZendeskTicket() *plugin.Table {
	return &plugin.Table{
		Name:        "zendesk_ticket",
		Description: "Tickets enable your customers to communicate with agents in Zendesk Support.",
		List: &plugin.ListConfig{
			Hydrate: listTicket,
		},
		Get: &plugin.GetConfig{
			KeyColumns: plugin.SingleColumn("id"),
			Hydrate:    getTicket,
		},
		Columns: []*plugin.Column{
			{
				Name: "allow_attachments",
				Type: proto.ColumnType_BOOL,
				Description: "Permission for agents to add add attachments to a comment. Defaults to true"
			},
			...
			{
				Name: "via_source_to",
				Type: proto.ColumnType_JSON,
				Transform: transform.FromField("Via.Source.From"),
				Description: "Target that received the ticket"
			},
		},
	}
}

Examples:

Define a List function

This is a plugin.HydrateFunc that calls an API and returns data for all rows for the table.

To define it, set the property plugin.Plugin.ListConfig.

List: &plugin.ListConfig{
	Hydrate: listTicket,
},

Define a Get function

This is a plugin.HydrateFunc that calls an API and returns data for one row of the table. If the API can return a single item keyed by id, you should implement Get so that queries can filter the data as cheaply as possible.

To define it, set the property plugin.Plugin.GetConfig.

Get: &plugin.GetConfig{
	KeyColumns: plugin.SingleColumn("id"),
	Hydrate:    getTicket,
},

Add column definitions

Use plugin.Column to define columns.

Add hydrate functions

A column may be populated by a List or Get call. If a column requires data not provide by List or Get, it may define a plugin.HydrateFunc that makes an additional API call for each row.

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 a hydrate function.

Logging

A plugin.Logger is passed to the plugin via its context.Context. Messages are written to ~/.steampipe/logs, e.g. ~/.steampipe/logs/plugin-2022-01-01.log.

Steampipe uses go-hclog which supports standard log levels: TRACE, DEBUG, INFO, WARN, ERROR. The default is WARN.

logger := plugin.Logger(ctx)
logger.Info("Log message and a variable", myVariable)

Use the STEAMPIPE_LOG_LEVEL environment variable to set the level.

export STEAMPIPE_LOG_LEVEL=TRACE

Define 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.

Dynamic tables (advanced)

Use 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 Steampipe foreign data wrapper (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
Dynamic Tables
error_handling
Error Handling
Error Handling
key_columns
Key Columns
Key Columns
matrix_items
Matrix Items
Matrix Items
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
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

Jump to

Keyboard shortcuts

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