Add support for connection config. All env vars should have STEAMPIPE_ prefix. Closes #172 Closes #173 (#184)

This commit is contained in:
kaidaguerre
2021-02-17 08:48:35 +00:00
committed by GitHub
parent 02e83971d7
commit ff7ef4d809
18 changed files with 244 additions and 121 deletions

View File

@@ -26,7 +26,7 @@ env:
PG_VERSION: ${{ github.event.inputs.postgres_version }}
PATH_BASE: https://repo1.maven.org/maven2/io/zonky/test/postgres
NAME_PREFIX: embedded-postgres-binaries
SP_DISABLE_UPDATE_CHECK: true
STEAMPIPE_UPDATE_CHECK: false
jobs:
goreleaser:

View File

@@ -5,7 +5,7 @@ on:
- 'v*'
env:
SP_DISABLE_UPDATE_CHECK: true
STEAMPIPE_UPDATE_CHECK: false
jobs:
goreleaser:

View File

@@ -6,7 +6,7 @@ on:
pull_request:
env:
SP_DISABLE_UPDATE_CHECK: true
STEAMPIPE_UPDATE_CHECK: false
jobs:
goreleaser:

View File

@@ -1,11 +0,0 @@
package connection_config
type ConnectionConfig struct {
Connections map[string]*Connection
}
func newConfig() *ConnectionConfig {
return &ConnectionConfig{
Connections: make(map[string]*Connection),
}
}

View File

@@ -1,15 +1,11 @@
package connection_config
// Connection :: structure representing the partially parsed connection.
type Connection struct {
Name string
// connection name
Name string
// FQN of plugin
Plugin string
Config map[string]string
}
func NewConnection() *Connection {
return &Connection{
Name: "",
Plugin: "",
Config: make(map[string]string),
}
// unparsed HCL of plugin specific connection config
Config string
}

View File

@@ -0,0 +1,12 @@
package connection_config
// ConnectionConfigMap :: map of connection name to partially parsed connection config
type ConnectionConfigMap struct {
Connections map[string]*Connection
}
func newConfigMap() *ConnectionConfigMap {
return &ConnectionConfigMap{
Connections: make(map[string]*Connection),
}
}

View File

@@ -13,30 +13,39 @@ import (
"github.com/turbot/steampipe-plugin-sdk/logging"
)
type ConnectionPluginOptions struct {
PluginFQN string
ConnectionName string
DisableLogger bool
}
// ConnectionPlugin :: structure representing an instance of a plugin
// NOTE: currently this corresponds to a single connection, i.e. we have 1 plugin instance per connection
type ConnectionPlugin struct {
ConnectionName string
PluginName string
Plugin *grpc.PluginClient
Schema *proto.Schema
ConnectionName string
ConnectionConfig string
PluginName string
Plugin *grpc.PluginClient
Schema *proto.Schema
}
func CreateConnectionPlugin(options *ConnectionPluginOptions) (*ConnectionPlugin, error) {
// ConnectionPluginOptions :: struct used as input to CreateConnectionPlugin
// - it contains all details necessary to instantiate a ConnectionPlugin
type ConnectionPluginOptions struct {
PluginFQN string
ConnectionName string
ConnectionConfig string
DisableLogger bool
}
// CreateConnectionPlugin :: instantiate a plugin for a connection, fetch schema and send connection config
// called by hub when
func CreateConnectionPlugin(options *ConnectionPluginOptions) (*ConnectionPlugin, error) {
remoteSchema := options.PluginFQN
connectionName := options.ConnectionName
connectionConfig := options.ConnectionConfig
disableLogger := options.DisableLogger
log.Printf("[DEBUG] createConnectionPlugin name %s, remoteSchema %s \n", connectionName, remoteSchema)
log.Printf("[TRACE] createConnectionPlugin name %s, remoteSchema %s \n", connectionName, remoteSchema)
pluginPath, err := GetPluginPath(remoteSchema)
if err != nil {
return nil, err
}
log.Printf("[DEBUG] found pluginPath %s\n", pluginPath)
log.Printf("[TRACE] found pluginPath %s\n", pluginPath)
// launch the plugin process.
// create the plugin map
@@ -82,14 +91,36 @@ func CreateConnectionPlugin(options *ConnectionPluginOptions) (*ConnectionPlugin
Client: client,
Stub: p,
}
if err = setConnectionConfig(connectionName, connectionConfig, err, pluginClient); err != nil {
pluginClient.Client.Kill()
return nil, err
}
schemaResponse, err := pluginClient.Stub.GetSchema(&proto.GetSchemaRequest{})
if err != nil {
pluginClient.Client.Kill()
return nil, err
return nil, HandleGrpcError(err, connectionName, "GetSchema")
}
schema := schemaResponse.Schema
// now create ConnectionPlugin object and add to map
c := &ConnectionPlugin{ConnectionName: connectionName, PluginName: remoteSchema, Plugin: pluginClient, Schema: schema}
c := &ConnectionPlugin{ConnectionName: connectionName, ConnectionConfig: connectionConfig, PluginName: remoteSchema, Plugin: pluginClient, Schema: schema}
return c, nil
}
// send the connection config to the plugin
func setConnectionConfig(connectionName string, connectionConfig string, err error, pluginClient *grpc.PluginClient) error {
// set the connection config
req := proto.SetConnectionConfigRequest{
ConnectionName: connectionName,
ConnectionConfig: connectionConfig,
}
_, err = pluginClient.Stub.SetConnectionConfig(&req)
if err != nil {
// create a new cleaner error
return HandleGrpcError(err, connectionName, "SetConnectionConfig")
}
return nil
}

View File

@@ -3,6 +3,7 @@ package connection_config
import (
"fmt"
"log"
"reflect"
"github.com/turbot/go-kit/helpers"
"github.com/turbot/steampipe/utils"
@@ -25,18 +26,25 @@ func newConnectionUpdates() *ConnectionUpdates {
}
}
type installedPlugin struct {
type connectionData struct {
// the fully qualified name of the plugin
Plugin string `yaml:"plugin"`
// the checksum of the plugin file
CheckSum string `yaml:"checkSum"`
// connection name
ConnectionName string
// connection data (unparsed)
ConnectionConfig string
}
func (p installedPlugin) equals(other *installedPlugin) bool {
return p.Plugin == other.Plugin && p.CheckSum == other.CheckSum
func (p connectionData) equals(other *connectionData) bool {
return p.Plugin == other.Plugin &&
p.CheckSum == other.CheckSum &&
p.ConnectionName == other.ConnectionName &&
reflect.DeepEqual(p.ConnectionConfig, other.ConnectionConfig)
}
type ConnectionMap map[string]*installedPlugin
type ConnectionMap map[string]*connectionData
// GetConnectionsToUpdate :: returns updates to be made to the database to sync with connection config
func GetConnectionsToUpdate(schemas []string) (*ConnectionUpdates, error) {
@@ -53,7 +61,6 @@ func GetConnectionsToUpdate(schemas []string) (*ConnectionUpdates, error) {
result := newConnectionUpdates()
result.MissingPlugins = missingPlugins
// assume we will end up with the required connections
// TODO is this valid?
result.RequiredConnections = requiredConnections
// connections to create/update
@@ -105,9 +112,11 @@ func getRequiredConnections() (ConnectionMap, []string, error) {
return nil, nil, err
}
requiredConnections[name] = &installedPlugin{
Plugin: remoteSchema,
CheckSum: checksum,
requiredConnections[name] = &connectionData{
Plugin: remoteSchema,
CheckSum: checksum,
ConnectionConfig: config.Config,
ConnectionName: config.Name,
}
}

View File

@@ -0,0 +1,25 @@
package connection_config
import (
"errors"
"log"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
func HandleGrpcError(err error, connection, call string) error {
// if this is a not implemented error we silently swallow it
status, ok := status.FromError(err)
if !ok {
return err
}
// ignore unimplemented error
if status.Code() == codes.Unimplemented {
log.Printf("[INFO] connection '%s' returned 'Unimplemented' error for call '%s' - plugin version does not support this call", connection, call)
return nil
}
return errors.New(status.Message())
}

View File

@@ -3,13 +3,17 @@ package connection_config
import (
"fmt"
"io/ioutil"
"log"
"os"
"path/filepath"
"strings"
"github.com/turbot/steampipe-plugin-sdk/plugin"
"github.com/hashicorp/hcl/v2"
"github.com/hashicorp/hcl/v2/gohcl"
"github.com/hashicorp/hcl/v2/hclparse"
"github.com/hashicorp/hcl/v2/hclsyntax"
"github.com/turbot/steampipe/constants"
"github.com/turbot/steampipe/ociinstaller"
"github.com/turbot/steampipe/schema"
@@ -17,38 +21,57 @@ import (
const configExtension = ".spc"
func Load() (*ConnectionConfig, error) {
func Load() (*ConnectionConfigMap, error) {
return loadConfig(constants.ConfigDir())
}
func loadConfig(configFolder string) (*ConnectionConfig, error) {
var result = newConfig()
func loadConfig(configFolder string) (result *ConnectionConfigMap, err error) {
defer func() {
if r := recover(); r != nil {
if e, ok := r.(error); ok {
err = e
} else {
err = fmt.Errorf("%v", r)
}
}
}()
result = newConfigMap()
// get all the config files in the directory
configPaths, err := getConfigFilePaths(configFolder)
if err != nil {
log.Printf("[WARN] loadConfig: failed to get config file paths: %v\n", err)
return nil, err
}
if len(configPaths) == 0 {
return &ConnectionConfig{}, nil
log.Println("[DEBUG] loadConfig: 0 config file paths returned")
return &ConnectionConfigMap{}, nil
}
body, diags := parseConfigs(configPaths)
fileData, diags := loadFileData(configPaths)
if diags.HasErrors() {
return nil, fmt.Errorf("failed to load all config files: %s", diags.Error())
log.Printf("[WARN] loadConfig: failed to get config file paths: %v\n", err)
return nil, plugin.DiagsToError("failed to load all config files", diags)
}
body, diags := parseConfigs(fileData)
if diags.HasErrors() {
return nil, plugin.DiagsToError("failed to load all config files", diags)
}
// do a partial decode
content, _, moreDiags := body.PartialContent(configSchema)
if moreDiags.HasErrors() {
diags = append(diags, moreDiags...)
return nil, diags
return nil, plugin.DiagsToError("failed to decode config", diags)
}
for _, block := range content.Blocks {
switch block.Type {
case "connection":
connection, moreDiags := parseConnection(block)
connection, moreDiags := parseConnection(block, fileData)
if moreDiags.HasErrors() {
diags = append(diags, moreDiags...)
continue
@@ -65,15 +88,16 @@ func loadConfig(configFolder string) (*ConnectionConfig, error) {
}
if diags.HasErrors() {
return nil, plugin.DiagsToError("failed to load config", diags)
return nil, fmt.Errorf(diags.Error())
}
return result, nil
}
func parseConfigs(configPaths []string) (hcl.Body, hcl.Diagnostics) {
var parsedConfigFiles []*hcl.File
func loadFileData(configPaths []string) (map[string][]byte, hcl.Diagnostics) {
var diags hcl.Diagnostics
var fileData = map[string][]byte{}
for _, configPath := range configPaths {
data, err := ioutil.ReadFile(configPath)
if err != nil {
@@ -83,8 +107,18 @@ func parseConfigs(configPaths []string) (hcl.Body, hcl.Diagnostics) {
Detail: err.Error()})
continue
}
fileData[configPath] = data
}
return fileData, diags
}
func parseConfigs(fileData map[string][]byte) (hcl.Body, hcl.Diagnostics) {
var parsedConfigFiles []*hcl.File
var diags hcl.Diagnostics
parser := hclparse.NewParser()
for configPath, data := range fileData {
file, moreDiags := parser.ParseHCL(data, configPath)
file, moreDiags := hclsyntax.ParseConfig(data, configPath, hcl.Pos{Byte: 0, Line: 1, Column: 1})
if moreDiags.HasErrors() {
diags = append(diags, moreDiags...)
continue
@@ -95,36 +129,38 @@ func parseConfigs(configPaths []string) (hcl.Body, hcl.Diagnostics) {
return hcl.MergeFiles(parsedConfigFiles), diags
}
func parseConnection(block *hcl.Block) (*Connection, hcl.Diagnostics) {
func parseConnection(block *hcl.Block, fileData map[string][]byte) (*Connection, hcl.Diagnostics) {
connectionBlock, rest, diags := block.Body.PartialContent(connectionSchema)
if diags.HasErrors() {
return nil, diags
}
connection := NewConnection()
// convert this into a fully qualified name plugin name
connection.Name = block.Labels[0]
// get connection name
connectionName := block.Labels[0]
var plugin string
diags = gohcl.DecodeExpression(connectionBlock.Attributes["plugin"].Expr, nil, &plugin)
if diags.HasErrors() {
return nil, diags
}
connection.Plugin = ociinstaller.NewSteampipeImageRef(plugin).DisplayImageRef()
connectionPlugin := ociinstaller.NewSteampipeImageRef(plugin).DisplayImageRef()
// now populate the dynamic connection config
remainingAttributes, diags := rest.JustAttributes()
for name, attribute := range remainingAttributes {
if name != "connection" {
var val string
diags = gohcl.DecodeExpression(attribute.Expr, nil, &val)
if diags.HasErrors() {
return nil, diags
}
connection.Config[name] = val
// now build a string containing the hcl for all other conneciton config properties
restBody := rest.(*hclsyntax.Body)
var configProperties []string
for name, a := range restBody.Attributes {
// if this attribute does not appear in connectionBlock, load the hcl string
if _, ok := connectionBlock.Attributes[name]; !ok {
configProperties = append(configProperties, string(a.SrcRange.SliceBytes(fileData[a.SrcRange.Filename])))
}
}
connectionConfig := strings.Join(configProperties, "\n")
connection := &Connection{
Name: connectionName,
Plugin: connectionPlugin,
Config: connectionConfig,
}
return connection, nil
}

View File

@@ -18,38 +18,38 @@ type getParseConfigTest struct {
var testCasesParseConfig = map[string]getParseConfigTest{
"multiple_connections": {
source: "test_Data/multiple_connections",
expected: &ConnectionConfig{
expected: &ConnectionConfigMap{
Connections: map[string]*Connection{
// todo normalise plugin names here?
"aws_dmi_001": {
Name: "aws_dmi_001",
Plugin: "aws",
Config: map[string]string{
"regions": "- us-east-1\n-us-west-",
"secret_key": "aws_dmi_001_secret_key",
"access_key": "aws_dmi_001_access_key",
},
//Config: map[string]string{
// "regions": "- us-east-1\n-us-west-",
// "secret_key": "aws_dmi_001_secret_key",
// "access_key": "aws_dmi_001_access_key",
//},
},
"aws_dmi_002": {
Name: "aws_dmi_002",
Plugin: "aws",
Config: map[string]string{
"regions": "- us-east-1\n-us-west-",
"secret_key": "aws_dmi_002_secret_key",
"access_key": "aws_dmi_002_access_key",
},
//Config: map[string]string{
// "regions": "- us-east-1\n-us-west-",
// "secret_key": "aws_dmi_002_secret_key",
// "access_key": "aws_dmi_002_access_key",
//},
},
}},
},
"single_connection": {
source: "test_Data/single_connection",
expected: &ConnectionConfig{
expected: &ConnectionConfigMap{
Connections: map[string]*Connection{
// todo normalise plugin names here?
"a": {
Name: "a",
Plugin: "test_data/connection-test-1",
Config: map[string]string{},
//Config: map[string]string{},
},
}},
},

View File

@@ -19,7 +19,7 @@ const (
// constants for installing db and fdw images
const (
DatabaseVersion = "12.1.0"
FdwVersion = "0.0.22"
FdwVersion = "0.0.23-beta.0"
// The 12.1.0 image uses the older jar format 12.1.0-v2 is the same version of postgres,
// just packaged as gzipped tar files (consistent with oras, faster to unzip). Once everyone is

View File

@@ -16,7 +16,7 @@ func refreshConnections(client *Client) error {
// first get a list of all existing schemas
schemas := client.schemaMetadata.GetSchemas()
//refresh the connection state file - the removes any connections which do not exist in the list of current schema
// refresh the connection state file - the removes any connections which do not exist in the list of current schema
log.Println("[TRACE] refreshConnections")
updates, err := connection_config.GetConnectionsToUpdate(schemas)
if err != nil {
@@ -32,11 +32,9 @@ func refreshConnections(client *Client) error {
missingCount,
p.Pluralize("plugin", missingCount, false),
strings.Join(updates.MissingPlugins, "\n "))
}
var connectionQueries []string
numUpdates := len(updates.Update)
if numUpdates > 0 {
s := utils.ShowSpinner("Refreshing connections...")
@@ -115,7 +113,7 @@ func getCommentQueries(updates connection_config.ConnectionMap) ([]string, error
pluginFQN := plugin.Plugin
// instantiate the connection plugin, and retrieve schema
go getCommentsQueryAsync(pluginFQN, connectionName, queryChan, errorChan)
go getCommentsQueryAsync(pluginFQN, connectionName, plugin.ConnectionConfig, queryChan, errorChan)
}
for i := 0; i < numUpdates; i++ {
@@ -133,8 +131,13 @@ func getCommentQueries(updates connection_config.ConnectionMap) ([]string, error
return commentQueries, nil
}
func getCommentsQueryAsync(pluginFQN string, connectionName string, queryChan chan []string, errorChan chan error) {
opts := &connection_config.ConnectionPluginOptions{PluginFQN: pluginFQN, ConnectionName: connectionName, DisableLogger: true}
func getCommentsQueryAsync(pluginFQN string, connectionName string, connectionConfig string, queryChan chan []string, errorChan chan error) {
opts := &connection_config.ConnectionPluginOptions{
PluginFQN: pluginFQN,
ConnectionName: connectionName,
ConnectionConfig: connectionConfig,
DisableLogger: true,
}
p, err := connection_config.CreateConnectionPlugin(opts)
if err != nil {
errorChan <- err
@@ -172,7 +175,6 @@ func deleteConnectionQuery(name string) []string {
}
func executeConnectionQueries(schemaQueries []string, updates *connection_config.ConnectionUpdates) error {
client, err := createSteampipeRootDbClient()
if err != nil {
return err

View File

@@ -40,7 +40,7 @@ func ExecuteQuery(queryString string) (*ResultStreamer, error) {
if err = refreshConnections(client); err != nil {
// shutdown the service if something went wrong!!!
shutdown(client)
return nil, fmt.Errorf("failed to refresh connections: %v", err)
return nil, fmt.Errorf("failed to refresh connections: %v", err.Error())
}
if err = refreshFunctions(client); err != nil {
// shutdown the service if something went wrong!!!

13
go.mod
View File

@@ -13,13 +13,13 @@ require (
github.com/dustin/go-humanize v1.0.0
github.com/fatih/color v1.7.0
github.com/gertd/go-pluralize v0.1.7
github.com/go-ole/go-ole v1.2.4 // indirect
github.com/go-ole/go-ole v1.2.5 // indirect
github.com/google/uuid v1.1.5
github.com/hashicorp/go-cleanhttp v0.5.1
github.com/hashicorp/go-hclog v0.14.1
github.com/hashicorp/go-plugin v1.3.0
github.com/hashicorp/go-version v1.2.1
github.com/hashicorp/hcl/v2 v2.6.0
github.com/hashicorp/hcl/v2 v2.8.2
github.com/jedib0t/go-pretty/v6 v6.0.6
github.com/karrick/gows v0.3.0
github.com/kr/text v0.2.0 // indirect
@@ -38,13 +38,16 @@ require (
github.com/spf13/afero v1.2.2 // indirect
github.com/spf13/cobra v1.0.0
github.com/spf13/viper v1.7.1
github.com/turbot/go-kit v0.0.0-20210119154454-db924443f736
github.com/turbot/steampipe-plugin-sdk v0.0.0-20210119154656-52569ae6f10d
github.com/turbot/go-kit v0.1.1
github.com/turbot/steampipe-plugin-sdk v0.0.0-20210120214727-bb3e0ba7e84f
github.com/ulikunitz/xz v0.5.8
github.com/zclconf/go-cty v1.7.0 // indirect
golang.org/x/text v0.3.4
google.golang.org/grpc v1.33.1
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect
gotest.tools/v3 v3.0.3 // indirect
)
replace github.com/c-bata/go-prompt => github.com/turbot/go-prompt v0.2.6-steampipe
// issue-21
replace github.com/turbot/steampipe-plugin-sdk => github.com/turbot/steampipe-plugin-sdk v0.1.2-0.20210216110503-b3467c637d18

21
go.sum
View File

@@ -44,6 +44,7 @@ github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hC
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8=
github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY=
github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8=
github.com/aws/aws-sdk-go v1.15.11 h1:m45+Ru/wA+73cOZXiEGLDH2d9uLN3iHqMc0/z4noDXE=
github.com/aws/aws-sdk-go v1.15.11/go.mod h1:mFuSZ37Z9YOHbQEwBWztmVzqXrEkub65tZoCYDt7FT0=
github.com/beorn7/perks v0.0.0-20160804104726-4c0e84591b9a/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
@@ -142,12 +143,13 @@ github.com/gertd/go-pluralize v0.1.7/go.mod h1:O4eNeeIf91MHh1GJ2I47DNtaesm66NYvj
github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk=
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=
github.com/go-ini/ini v1.25.4 h1:Mujh4R/dH6YL8bxuISne3xX2+qcQ9p0IxKAP6ExWoUo=
github.com/go-ini/ini v1.25.4/go.mod h1:ByCAeIL28uOIIG0E3PJtZPDL8WnHpFKFOtgjp+3Ies8=
github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE=
github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk=
github.com/go-ole/go-ole v1.2.4 h1:nNBDSCOigTSiarFpYE9J/KtEA1IOW4CNeqT9TQDqCxI=
github.com/go-ole/go-ole v1.2.4/go.mod h1:XCwSNxSkXRo4vlyPy93sltvi/qJq0jqQhjqQNIwKuxM=
github.com/go-ole/go-ole v1.2.5 h1:t4MGB5xEDZvXI+0rMjjsfBsD7yAgp/s9ZDkL1JndXwY=
github.com/go-ole/go-ole v1.2.5/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0=
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
github.com/go-test/deep v1.0.3 h1:ZrJSEWsXzPOxaZnFteGEfooLba+ju3FYIbOrS+rQd68=
github.com/go-test/deep v1.0.3/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3aSFNA=
@@ -237,6 +239,8 @@ github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
github.com/hashicorp/hcl/v2 v2.6.0 h1:3krZOfGY6SziUXa6H9PJU6TyohHn7I+ARYnhbeNBz+o=
github.com/hashicorp/hcl/v2 v2.6.0/go.mod h1:bQTN5mpo+jewjJgh8jr0JUguIi7qPHUF6yIfAEN3jqY=
github.com/hashicorp/hcl/v2 v2.8.2 h1:wmFle3D1vu0okesm8BTLVDyJ6/OL9DCLUwn0b2OptiY=
github.com/hashicorp/hcl/v2 v2.8.2/go.mod h1:bQTN5mpo+jewjJgh8jr0JUguIi7qPHUF6yIfAEN3jqY=
github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO+LraFDTW64=
github.com/hashicorp/mdns v1.0.0/go.mod h1:tL+uN++7HEJ6SQLQ2/p+z2pH24WQKWjBPkE0mNTz8vQ=
github.com/hashicorp/memberlist v0.1.3/go.mod h1:ajVTdAv/9Im8oMAAj5G31PhhMCZJV2pPBoIllUwCN7I=
@@ -253,6 +257,7 @@ github.com/jedib0t/go-pretty/v6 v6.0.6/go.mod h1:+nE9fyyHGil+PuISTCrp7avEdo6bqoM
github.com/jhump/protoreflect v1.6.0 h1:h5jfMVslIg6l29nsMs0D8Wj17RDVdNYti0vDN/PZZoE=
github.com/jhump/protoreflect v1.6.0/go.mod h1:eaTn3RZAmMBcV0fifFvlm6VHNz3wSkYyXYWUh7ymB74=
github.com/jmespath/go-jmespath v0.0.0-20160202185014-0b12d6b521d8/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k=
github.com/jmespath/go-jmespath v0.0.0-20160803190731-bd40a432e4c7 h1:SMvOWPJCES2GdFracYbBQh93GXac8fq7HeN6JnpduB8=
github.com/jmespath/go-jmespath v0.0.0-20160803190731-bd40a432e4c7/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k=
github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo=
github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
@@ -454,12 +459,14 @@ github.com/syndtr/gocapability v0.0.0-20170704070218-db04d3cc01c8/go.mod h1:hkRG
github.com/tkrajina/go-reflector v0.5.4 h1:dS9aJEa/eYNQU/fwsb5CSiATOxcNyA/gG/A7a582D5s=
github.com/tkrajina/go-reflector v0.5.4/go.mod h1:9PyLgEOzc78ey/JmQQHbW8cQJ1oucLlNQsg8yFvkVk8=
github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
github.com/turbot/go-kit v0.0.0-20210119154454-db924443f736 h1:j/cfIwIBSX4Z23k50mgu7eLOGVcPi62ebV1Wm98OCyU=
github.com/turbot/go-kit v0.0.0-20210119154454-db924443f736/go.mod h1:hO/mY90fJXLWAJnAoDkYMvi3LVZ/r+z1tiz3E1uPSNA=
github.com/turbot/go-kit v0.1.1 h1:JkLUyVp8m8jEj45C52dzh7Tj9jpxHP90y9+m8cpW1mo=
github.com/turbot/go-kit v0.1.1/go.mod h1:hO/mY90fJXLWAJnAoDkYMvi3LVZ/r+z1tiz3E1uPSNA=
github.com/turbot/go-prompt v0.2.6-steampipe h1:/stkR3dOdxKRk/lKsnKpb9KZA/m3v0/OqLIHwDN8zv4=
github.com/turbot/go-prompt v0.2.6-steampipe/go.mod h1:vFnjEGDIIA/Lib7giyE4E9c50Lvl8j0S+7FVlAwDAVw=
github.com/turbot/steampipe-plugin-sdk v0.0.0-20210119154656-52569ae6f10d h1:/h1X0W74GUatUoaNxoS951scw+DK60CIZ49brL+uzaY=
github.com/turbot/steampipe-plugin-sdk v0.0.0-20210119154656-52569ae6f10d/go.mod h1:jhmUevBAJQhpxCtwP+pnpYI13/ODrZb7eCI8MKd8jZA=
github.com/turbot/steampipe-plugin-sdk v0.1.2-0.20210216103634-dc9924f5c950 h1:Dt2nEilfXmx+a/mFgVFVEg9pb5RxmkmhhWzixMuWYWE=
github.com/turbot/steampipe-plugin-sdk v0.1.2-0.20210216103634-dc9924f5c950/go.mod h1:8rtiNzdYYh/geT7h3N+Eujn4tzDJ0PIS5uPRAT6SSzI=
github.com/turbot/steampipe-plugin-sdk v0.1.2-0.20210216110503-b3467c637d18 h1:l72vOrfZeZd+yXmKO8F+sQIAPf8Ku6ajz07PoPL+eeY=
github.com/turbot/steampipe-plugin-sdk v0.1.2-0.20210216110503-b3467c637d18/go.mod h1:AiJ01KmQeaoLY92y3SjZj98ijzbxUbdoN1sdrzbi7xA=
github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGrc=
github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0=
github.com/ulikunitz/xz v0.5.8 h1:ERv8V6GKqVi23rgu5cj9pVfVzJbOqAY2Ntl88O6c2nQ=
@@ -482,6 +489,8 @@ github.com/yvasiyarov/newrelic_platform_go v0.0.0-20140908184405-b21fdbd4370f/go
github.com/zclconf/go-cty v1.2.0/go.mod h1:hOPWgoHbaTUnI5k4D2ld+GRpFJSCe6bCM7m1q/N4PQ8=
github.com/zclconf/go-cty v1.7.0 h1:yMqLinUwNCYkmiHjEH+luio1yGl35cjqVzjvdRg2WlY=
github.com/zclconf/go-cty v1.7.0/go.mod h1:VDR4+I79ubFBGm1uJac1226K5yANQFHeauxPBoP54+o=
github.com/zclconf/go-cty v1.7.1 h1:AvsC01GMhMLFL8CgEYdHGM+yLnnDOwhPAYcgTkeF0Gw=
github.com/zclconf/go-cty v1.7.1/go.mod h1:VDR4+I79ubFBGm1uJac1226K5yANQFHeauxPBoP54+o=
go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU=
go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU=
go.opencensus.io v0.22.0 h1:C9hSCOW830chIVkdja34wa6Ky+IzWllkUinR+BtRZd4=

View File

@@ -38,10 +38,8 @@ func main() {
// CreateLogger :: create a hclog logger with the level specified by the SP_LOG env var
func createLogger() {
level, ok := os.LookupEnv("SP_LOG")
if !ok {
level = "WARNING"
}
level := logging.LogLevel()
options := &hclog.LoggerOptions{Name: "steampipe", Level: hclog.LevelFromString(level)}
if options.Output == nil {
options.Output = os.Stderr

View File

@@ -4,12 +4,6 @@ import (
"bytes"
"encoding/json"
"fmt"
"github.com/fatih/color"
"github.com/hashicorp/go-cleanhttp"
SemVer "github.com/hashicorp/go-version"
"github.com/olekukonko/tablewriter"
"github.com/turbot/steampipe/constants"
"github.com/turbot/steampipe/version"
"io/ioutil"
"log"
"net/http"
@@ -18,9 +12,17 @@ import (
"runtime"
"strings"
"time"
"github.com/fatih/color"
"github.com/hashicorp/go-cleanhttp"
SemVer "github.com/hashicorp/go-version"
"github.com/olekukonko/tablewriter"
"github.com/turbot/steampipe/constants"
"github.com/turbot/steampipe/version"
)
const disableUpdatesCheckEnvVar = "SP_DISABLE_UPDATE_CHECK"
const legacyDisableUpdatesCheckEnvVar = "SP_DISABLE_UPDATE_CHECK"
const updatesCheckEnvVar = "STEAMPIPE_UPDATE_CHECK"
// the current version of the Steampipe CLI application
var currentVersion = version.Version
@@ -56,8 +58,7 @@ type versionChecker struct {
// check if there is a new version
func checkVersion(id string) {
// if SP_DISABLE_UPDATE_CHECK is set, do nothing
if v, ok := os.LookupEnv(disableUpdatesCheckEnvVar); ok && strings.ToLower(v) == "true" {
if !shouldDoUpdateCheck() {
return
}
@@ -67,6 +68,18 @@ func checkVersion(id string) {
v.Notify()
}
func shouldDoUpdateCheck() bool {
// if legacy env var SP_DISABLE_UPDATE_CHECK is true, do nothing
if v, ok := os.LookupEnv(legacyDisableUpdatesCheckEnvVar); ok && strings.ToLower(v) == "true" {
return false
}
// if STEAMPIPE_UPDATE_CHECK is false, do nothing
if v, ok := os.LookupEnv(updatesCheckEnvVar); ok && strings.ToLower(v) == "false" {
return false
}
return true
}
// RunCheck :: Communicates with the Turbot Artifacts Server retrieves
// the latest released version
func (c *versionChecker) GetVersionResp() {