Skip to content

Commit

Permalink
Move powerpipe specific resources from pipe-fittings #534
Browse files Browse the repository at this point in the history
- Powerpipe specific interfaces moved  from pipe-fittings:
    - RuntimeDependencyProvider
    - WithProvider
    - QueryProvider
    - DashboardLeafNode
    - NodeAndEdgeProvider
- Added app-specific config:
    - modconfig.AppSpecificNewModResourcesFunc - constructor for app specific ModResources implementation
    - parse.ModDecoderFunc  - constructor for app specific decoder
    - parse.AppSpecificGetResourceSchemaFunc to return app specific resource schema
  • Loading branch information
kaidaguerre authored Oct 30, 2024
1 parent dfbd402 commit 38cdc51
Show file tree
Hide file tree
Showing 102 changed files with 8,907 additions and 513 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/01-powerpipe-pre-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
# this is required, check golangci-lint-action docs
- uses: actions/setup-go@v5
with:
go-version: '1.22'
go-version: '1.23'
cache: false # setup-go v4 caches by default, do not change this parameter, check golangci-lint-action doc: https://github.com/golangci/golangci-lint-action/pull/704

- name: Build
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/02-powerpipe-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ jobs:
# this is required, check golangci-lint-action docs
- uses: actions/setup-go@v5
with:
go-version: '1.22'
go-version: '1.23'
cache: false # setup-go v4 caches by default, do not change this parameter, check golangci-lint-action doc: https://github.com/golangci/golangci-lint-action/pull/704

- name: Build
Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/10-test-lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ jobs:
with:
repository: turbot/pipe-fittings
path: pipe-fittings
ref: v1.6.x
ref: develop

# this is required, check golangci-lint-action docs
- uses: actions/setup-go@v5
with:
go-version: '1.22'
go-version: '1.23'
cache: false # setup-go v4 caches by default, do not change this parameter, check golangci-lint-action doc: https://github.com/golangci/golangci-lint-action/pull/704

- name: golangci-lint
Expand All @@ -38,3 +38,4 @@ jobs:
version: v1.61.0
args: --timeout=10m
working-directory: powerpipe
skip-cache: true
4 changes: 2 additions & 2 deletions .github/workflows/11-test-acceptance.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ jobs:
with:
repository: turbot/pipe-fittings
path: pipe-fittings
ref: v1.6.x
ref: develop

# this is required, check golangci-lint-action docs
- uses: actions/setup-go@v5
with:
go-version: '1.22'
go-version: '1.23'
cache: false # setup-go v4 caches by default, do not change this parameter, check golangci-lint-action doc: https://github.com/golangci/golangci-lint-action/pull/704

- name: Build
Expand Down
14 changes: 7 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module github.com/turbot/powerpipe

go 1.22.4
go 1.23.2

// replace github.com/turbot/pipe-fittings => ../pipe-fittings
replace github.com/turbot/pipe-fittings => ../pipe-fittings

require (
github.com/Masterminds/semver/v3 v3.3.0
Expand All @@ -21,13 +21,14 @@ require (
github.com/spf13/cobra v1.8.1
github.com/spf13/pflag v1.0.5 // indirect
github.com/spf13/viper v1.19.0
github.com/stevenle/topsort v0.2.0 // indirect
github.com/stevenle/topsort v0.2.0
github.com/turbot/go-kit v0.10.0-rc.0
github.com/turbot/pipe-fittings v1.6.2
github.com/turbot/steampipe-plugin-sdk/v5 v5.11.0
// develop branch d7decaf1e82d8538970cc7d7821d5a8f1c3994d4 (spp specific resource refactor)
github.com/turbot/pipe-fittings v1.6.6-0.20241030182756-d7decaf1e82d
github.com/turbot/steampipe-plugin-sdk/v5 v5.11.0
github.com/turbot/terraform-components v0.0.0-20231213122222-1f3526cab7a7 // indirect
github.com/xlab/treeprint v1.2.0 // indirect
github.com/zclconf/go-cty v1.14.4 // indirect
github.com/zclconf/go-cty v1.14.4
github.com/zclconf/go-cty-yaml v1.0.3 // indirect
golang.org/x/exp v0.0.0-20240222234643-814bf88cf225
sigs.k8s.io/yaml v1.4.0 // indirect
Expand Down Expand Up @@ -193,7 +194,6 @@ require (
github.com/prometheus/common v0.39.0 // indirect
github.com/prometheus/procfs v0.9.0 // indirect
github.com/rivo/uniseg v0.4.3 // indirect
github.com/robfig/cron/v3 v3.0.1 // indirect
github.com/rs/xid v1.5.0 // indirect
github.com/sagikazarmark/locafero v0.4.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
Expand Down
6 changes: 2 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -739,8 +739,6 @@ github.com/prometheus/procfs v0.9.0/go.mod h1:+pB4zwohETzFnmlpe6yd2lSc+0/46IYZRB
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rivo/uniseg v0.4.3 h1:utMvzDsuh3suAEnhH0RdHmoPbU648o6CvXxTx4SBMOw=
github.com/rivo/uniseg v0.4.3/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs=
github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro=
github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
Expand Down Expand Up @@ -818,8 +816,8 @@ github.com/tkrajina/go-reflector v0.5.6 h1:hKQ0gyocG7vgMD2M3dRlYN6WBBOmdoOzJ6njQ
github.com/tkrajina/go-reflector v0.5.6/go.mod h1:ECbqLgccecY5kPmPmXg1MrHW585yMcDkVl6IvJe64T4=
github.com/turbot/go-kit v0.10.0-rc.0 h1:kd+jp2ibbIV33Hc8SsMAN410Dl9Pz6SJ40axbKUlSoA=
github.com/turbot/go-kit v0.10.0-rc.0/go.mod h1:fFQqR59I5z5JeeBLfK1PjSifn4Oprs3NiQx0CxeSJxs=
github.com/turbot/pipe-fittings v1.6.2 h1:VwAdZ2W42AwR1ZrUjIVI4VlQt1g8BNhsheoWcLVFZPY=
github.com/turbot/pipe-fittings v1.6.2/go.mod h1:1nlRVh18QkYy9eq5pW9gpnoE2VgnQW0Y2zKzrH8Q4kI=
github.com/turbot/pipe-fittings v1.6.6-0.20241030175007-281024164508 h1:qxAyYA755bK7lNICi+5eKIZSPZYhxtMC4jweFyHXIBI=
github.com/turbot/pipe-fittings v1.6.6-0.20241030175007-281024164508/go.mod h1:zqS8HCdNa515xuNohnIOY1uu5WQpUNARmN87Ellrk9A=
github.com/turbot/pipes-sdk-go v0.9.1 h1:2yRojY2wymvJn6NQyE6A0EDFV267MNe+yDLxPVvsBwM=
github.com/turbot/pipes-sdk-go v0.9.1/go.mod h1:Mb+KhvqqEdRbz/6TSZc2QWDrMa5BN3E4Xw+gPt2TRkc=
github.com/turbot/steampipe-plugin-code v0.7.0 h1:SROYIo/TI/Q/YNfXK+sAIS71umypUFm1Uz851TmoJkM=
Expand Down
4 changes: 2 additions & 2 deletions internal/cmd/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
"github.com/turbot/pipe-fittings/constants"
"github.com/turbot/pipe-fittings/contexthelpers"
"github.com/turbot/pipe-fittings/error_helpers"
"github.com/turbot/pipe-fittings/modconfig"
"github.com/turbot/pipe-fittings/statushooks"
"github.com/turbot/pipe-fittings/utils"
localcmdconfig "github.com/turbot/powerpipe/internal/cmdconfig"
Expand All @@ -27,6 +26,7 @@ import (
"github.com/turbot/powerpipe/internal/controlstatus"
"github.com/turbot/powerpipe/internal/display"
localqueryresult "github.com/turbot/powerpipe/internal/queryresult"
"github.com/turbot/powerpipe/internal/resources"
"github.com/turbot/steampipe-plugin-sdk/v5/sperr"
)

Expand All @@ -35,7 +35,7 @@ var checkOutputMode = localconstants.CheckOutputModeText

// generic command to handle benchmark and control execution
func checkCmd[T controlinit.CheckTarget]() *cobra.Command {
typeName := modconfig.GenericTypeToBlockType[T]()
typeName := resources.GenericTypeToBlockType[T]()
argsSupported := cobra.ExactArgs(1)
if typeName == "benchmark" {
argsSupported = cobra.MinimumNArgs(1)
Expand Down
5 changes: 3 additions & 2 deletions internal/cmd/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/turbot/powerpipe/internal/controlstatus"
"github.com/turbot/powerpipe/internal/dashboardexecute"
"github.com/turbot/powerpipe/internal/initialisation"
"github.com/turbot/powerpipe/internal/resources"
"github.com/turbot/steampipe-plugin-sdk/v5/logging"
)

Expand Down Expand Up @@ -119,7 +120,7 @@ func dashboardRun(cmd *cobra.Command, args []string) {
ctx = createSnapshotContext(ctx, dashboardName)

statushooks.SetStatus(ctx, "Initializing…")
initData := initialisation.NewInitData[*modconfig.Dashboard](ctx, cmd, dashboardName)
initData := initialisation.NewInitData[*resources.Dashboard](ctx, cmd, dashboardName)

if len(viper.GetStringSlice(constants.ArgExport)) > 0 {
err := initData.RegisterExporters(dashboardExporters()...)
Expand All @@ -142,7 +143,7 @@ func dashboardRun(cmd *cobra.Command, args []string) {
// so a dashboard name was specified - just call GenerateSnapshot
target, err := initData.GetSingleTarget()
error_helpers.FailOnError(err)
snap, err := dashboardexecute.GenerateSnapshot(ctx, initData.WorkspaceEvents, target, inputs)
snap, err := dashboardexecute.GenerateSnapshot(ctx, initData.Workspace, target, inputs)
error_helpers.FailOnError(err)
// display the snapshot result (if needed)
displaySnapshot(snap)
Expand Down
8 changes: 4 additions & 4 deletions internal/cmd/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"github.com/turbot/pipe-fittings/constants"
"github.com/turbot/pipe-fittings/error_helpers"
"github.com/turbot/pipe-fittings/export"
"github.com/turbot/pipe-fittings/modconfig"
"github.com/turbot/pipe-fittings/steampipeconfig"
"github.com/turbot/pipe-fittings/workspace"
localcmdconfig "github.com/turbot/powerpipe/internal/cmdconfig"
Expand All @@ -26,6 +25,7 @@ import (
"github.com/turbot/powerpipe/internal/display"
"github.com/turbot/powerpipe/internal/initialisation"
"github.com/turbot/powerpipe/internal/queryresult"
"github.com/turbot/powerpipe/internal/resources"
"github.com/turbot/steampipe-plugin-sdk/v5/logging"
"github.com/turbot/steampipe-plugin-sdk/v5/sperr"
)
Expand Down Expand Up @@ -105,7 +105,7 @@ func queryRun(cmd *cobra.Command, args []string) {
return
}

initData := initialisation.NewInitData[*modconfig.Query](ctx, cmd, args...)
initData := initialisation.NewInitData[*resources.Query](ctx, cmd, args...)
// shutdown the service on exit
defer initData.Cleanup(ctx)
error_helpers.FailOnError(initData.Result.Error)
Expand Down Expand Up @@ -134,7 +134,7 @@ func queryRun(cmd *cobra.Command, args []string) {
exitCode = constants.ExitCodeInitializationFailed
error_helpers.FailOnError(err)
}
snap, err := dashboardexecute.GenerateSnapshot(ctx, initData.WorkspaceEvents, target, nil)
snap, err := dashboardexecute.GenerateSnapshot(ctx, initData.Workspace, target, nil)
if err != nil {
exitCode = constants.ExitCodeSnapshotCreationFailed
error_helpers.FailOnError(err)
Expand Down Expand Up @@ -218,7 +218,7 @@ func setExitCodeForQueryError(err error) {

func snapshotToQueryResult(snap *steampipeconfig.SteampipeSnapshot, startTime time.Time) (*queryresult.Result, error) {
// the table of a snapshot query has a fixed name
tablePanel, ok := snap.Panels[modconfig.SnapshotQueryTableName]
tablePanel, ok := snap.Panels[resources.SnapshotQueryTableName]
if !ok {
return nil, sperr.New("dashboard does not contain table result for query")
}
Expand Down
39 changes: 20 additions & 19 deletions internal/cmd/resource_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/turbot/pipe-fittings/schema"
localconstants "github.com/turbot/powerpipe/internal/constants"
"github.com/turbot/powerpipe/internal/display"
"github.com/turbot/powerpipe/internal/resources"
)

// variable used to assign the output mode flag
Expand All @@ -25,7 +26,7 @@ type ResourceCommandConfig struct {
}

func newResourceCommandConfig[T modconfig.ModTreeItem]() *ResourceCommandConfig {
typeName := modconfig.GenericTypeToBlockType[T]()
typeName := resources.GenericTypeToBlockType[T]()
return &ResourceCommandConfig{
cmd: typeName,
}
Expand Down Expand Up @@ -61,7 +62,7 @@ func resourceCmd[T modconfig.ModTreeItem](opts ...ResourceCommandOption) *cobra.
}

func listCmd[T modconfig.ModTreeItem]() *cobra.Command {
typeName := modconfig.GenericTypeToBlockType[T]()
typeName := resources.GenericTypeToBlockType[T]()
var cmd = &cobra.Command{
Use: "list",
Args: cobra.NoArgs,
Expand All @@ -78,7 +79,7 @@ func listCmd[T modconfig.ModTreeItem]() *cobra.Command {
}

func showCmd[T modconfig.ModTreeItem]() *cobra.Command {
typeName := modconfig.GenericTypeToBlockType[T]()
typeName := resources.GenericTypeToBlockType[T]()

var cmd = &cobra.Command{
Use: showCommandUse(typeName),
Expand All @@ -98,7 +99,7 @@ func showCmd[T modconfig.ModTreeItem]() *cobra.Command {

// determine which resource commands apply to this resource
func getResourceCommands[T modconfig.ModTreeItem]() []*cobra.Command {
typeName := modconfig.GenericTypeToBlockType[T]()
typeName := resources.GenericTypeToBlockType[T]()

var res = []*cobra.Command{listCmd[T](), showCmd[T]()}

Expand All @@ -117,15 +118,15 @@ func getResourceCommands[T modconfig.ModTreeItem]() []*cobra.Command {

func dashboardChildCommands() []*cobra.Command {
res := []*cobra.Command{
resourceCmd[*modconfig.DashboardCard](withCmdName("card")),
resourceCmd[*modconfig.DashboardChart](withCmdName("chart")),
resourceCmd[*modconfig.DashboardContainer](withCmdName("container")),
resourceCmd[*modconfig.DashboardFlow](withCmdName("flow")),
resourceCmd[*modconfig.DashboardGraph](withCmdName("graph")),
resourceCmd[*modconfig.DashboardHierarchy](withCmdName("hierarchy")),
resourceCmd[*modconfig.DashboardImage](withCmdName("image")),
resourceCmd[*modconfig.DashboardTable](withCmdName("table")),
resourceCmd[*modconfig.DashboardText](withCmdName("text")),
resourceCmd[*resources.DashboardCard](withCmdName("card")),
resourceCmd[*resources.DashboardChart](withCmdName("chart")),
resourceCmd[*resources.DashboardContainer](withCmdName("container")),
resourceCmd[*resources.DashboardFlow](withCmdName("flow")),
resourceCmd[*resources.DashboardGraph](withCmdName("graph")),
resourceCmd[*resources.DashboardHierarchy](withCmdName("hierarchy")),
resourceCmd[*resources.DashboardImage](withCmdName("image")),
resourceCmd[*resources.DashboardTable](withCmdName("table")),
resourceCmd[*resources.DashboardText](withCmdName("text")),
}

// set all to hidden
Expand All @@ -139,14 +140,14 @@ func runCmd[T modconfig.HclResource]() *cobra.Command {
var empty T

switch any(empty).(type) {
case *modconfig.Query:
case *resources.Query:
return queryRunCmd()
case *modconfig.Dashboard:
case *resources.Dashboard:
return dashboardRunCmd()
case *modconfig.Benchmark:
return checkCmd[*modconfig.Benchmark]()
case *modconfig.Control:
return checkCmd[*modconfig.Control]()
case *resources.Benchmark:
return checkCmd[*resources.Benchmark]()
case *resources.Control:
return checkCmd[*resources.Control]()
}

return nil
Expand Down
9 changes: 5 additions & 4 deletions internal/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/turbot/pipe-fittings/statushooks"
"github.com/turbot/pipe-fittings/utils"
localconstants "github.com/turbot/powerpipe/internal/constants"
"github.com/turbot/powerpipe/internal/resources"
)

var exitCode int
Expand Down Expand Up @@ -53,10 +54,10 @@ func rootCommand() *cobra.Command {
serverCmd(),
modCmd(),
loginCmd(),
resourceCmd[*modconfig.Benchmark](),
resourceCmd[*modconfig.Control](),
resourceCmd[*modconfig.Dashboard](),
resourceCmd[*modconfig.Query](),
resourceCmd[*resources.Benchmark](),
resourceCmd[*resources.Control](),
resourceCmd[*resources.Dashboard](),
resourceCmd[*resources.Query](),
resourceCmd[*modconfig.Variable](),
)

Expand Down
6 changes: 3 additions & 3 deletions internal/cmd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ import (
"github.com/turbot/pipe-fittings/cmdconfig"
"github.com/turbot/pipe-fittings/constants"
"github.com/turbot/pipe-fittings/error_helpers"
"github.com/turbot/pipe-fittings/modconfig"
"github.com/turbot/pipe-fittings/utils"
localcmdconfig "github.com/turbot/powerpipe/internal/cmdconfig"
localconstants "github.com/turbot/powerpipe/internal/constants"
"github.com/turbot/powerpipe/internal/dashboardassets"
"github.com/turbot/powerpipe/internal/dashboardserver"
"github.com/turbot/powerpipe/internal/initialisation"
"github.com/turbot/powerpipe/internal/resources"
"github.com/turbot/powerpipe/internal/service/api"
"github.com/turbot/steampipe-plugin-sdk/v5/sperr"
"gopkg.in/olahol/melody.v1"
Expand Down Expand Up @@ -75,7 +75,7 @@ func runServerCmd(cmd *cobra.Command, _ []string) {
}

// initialise the workspace
modInitData := initialisation.NewInitData[*modconfig.Dashboard](ctx, cmd)
modInitData := initialisation.NewInitData[*resources.Dashboard](ctx, cmd)
error_helpers.FailOnError(modInitData.Result.Error)

// ensure dashboard assets
Expand All @@ -85,7 +85,7 @@ func runServerCmd(cmd *cobra.Command, _ []string) {
// setup a new webSocket service
webSocket := melody.New()
// create the dashboardServer
dashboardServer, err := dashboardserver.NewServer(ctx, modInitData.WorkspaceEvents, webSocket)
dashboardServer, err := dashboardserver.NewServer(ctx, modInitData.Workspace, webSocket)
error_helpers.FailOnError(err)

// send it over to the powerpipe API Server
Expand Down
11 changes: 10 additions & 1 deletion internal/cmdconfig/app_specific.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ import (
"github.com/turbot/pipe-fittings/connection"
"github.com/turbot/pipe-fittings/error_helpers"
"github.com/turbot/pipe-fittings/filepaths"
"github.com/turbot/pipe-fittings/modconfig"
"github.com/turbot/pipe-fittings/parse"
pparse "github.com/turbot/powerpipe/internal/parse"
"github.com/turbot/powerpipe/internal/resources"
)

// SetAppSpecificConstants sets app specific constants defined in pipe-fittings
Expand All @@ -23,7 +27,7 @@ func SetAppSpecificConstants() {
// set all app specific env var keys
app_specific.SetAppSpecificEnvVarKeys("POWERPIPE_")

// version
// version string
versionString := viper.GetString("main.version")
app_specific.AppVersion = semver.MustParse(versionString)

Expand Down Expand Up @@ -71,6 +75,11 @@ func SetAppSpecificConstants() {
app_specific.VersionCheckPath = "api/cli/version/latest"
app_specific.EnvProfile = "POWERPIPE_PROFILE"

// set app specific parse related constants
modconfig.AppSpecificNewModResourcesFunc = resources.NewModResources
parse.ModDecoderFunc = pparse.NewPowerpipeModDecoder
parse.AppSpecificGetResourceSchemaFunc = pparse.GetResourceSchema

// register supported connection types
registerConnections()
}
Expand Down
Loading

0 comments on commit 38cdc51

Please sign in to comment.