Skip to content

Commit

Permalink
Credential refactoring adjustment in pipe-fittings.
Browse files Browse the repository at this point in the history
  • Loading branch information
vhadianto committed Feb 5, 2024
1 parent b2c1db1 commit 7433a27
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 62 deletions.
3 changes: 2 additions & 1 deletion internal/cmdconfig/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ 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/flowpipeconfig"
"github.com/turbot/pipe-fittings/modconfig"
"github.com/turbot/pipe-fittings/perr"
)

func initGlobalConfig() *modconfig.FlowpipeConfig {
func initGlobalConfig() *flowpipeconfig.FlowpipeConfig {
// load workspace profile from the configured install dir
loader, err := cmdconfig.GetWorkspaceProfileLoader[*modconfig.FlowpipeWorkspaceProfile]()
error_helpers.FailOnError(err)
Expand Down
7 changes: 4 additions & 3 deletions internal/es/db/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"strings"

"github.com/turbot/flowpipe/internal/cache"
"github.com/turbot/pipe-fittings/flowpipeconfig"
"github.com/turbot/pipe-fittings/modconfig"
"github.com/turbot/pipe-fittings/perr"
)
Expand Down Expand Up @@ -91,14 +92,14 @@ func ListAllTriggers() ([]modconfig.Trigger, error) {
return triggers, nil
}

func GetFlowpipeConfig() (*modconfig.FlowpipeConfig, error) {
func GetFlowpipeConfig() (*flowpipeconfig.FlowpipeConfig, error) {
flowpipeConfigCached, found := cache.GetCache().Get("#flowpipeconfig")

if !found {
return modconfig.NewFlowpipeConfig(), nil
return flowpipeconfig.NewFlowpipeConfig(), nil
}

flowpipeConfig, ok := flowpipeConfigCached.(*modconfig.FlowpipeConfig)
flowpipeConfig, ok := flowpipeConfigCached.(*flowpipeconfig.FlowpipeConfig)
if !ok {
return nil, perr.InternalWithMessage("invalid flowpipe config")
}
Expand Down
22 changes: 0 additions & 22 deletions internal/es/estest/mod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2476,28 +2476,6 @@ func (suite *ModTestSuite) TestMultipleCredential() {
assert.Equal("pk_616_L5H36X3CXXXXXXXWEAZZF0NM5", pex.PipelineOutput["clickup_token_val"])
}

func (suite *ModTestSuite) TestBasicCredential() {
assert := assert.New(suite.T())

pipelineInput := modconfig.Input{}

_, pipelineCmd, err := runPipeline(suite.FlowpipeTestSuite, "test_suite_mod.pipeline.cred_basic", 100*time.Millisecond, pipelineInput)

if err != nil {
assert.Fail("Error creating execution", err)
return
}

_, pex, _ := getPipelineExAndWait(suite.FlowpipeTestSuite, pipelineCmd.Event, pipelineCmd.PipelineExecutionID, 100*time.Millisecond, 40, "finished")
if err != nil {
assert.Fail("Error getting pipeline execution", err)
return
}

assert.Equal("foo", pex.PipelineOutput["val_username"])
assert.Equal("bar", pex.PipelineOutput["val_password"])
}

func (suite *ModTestSuite) TestBadContainerStep() {
assert := assert.New(suite.T())

Expand Down
24 changes: 0 additions & 24 deletions internal/es/estest/test_suite_mod/pipelines/credentials.fp
Original file line number Diff line number Diff line change
Expand Up @@ -36,30 +36,6 @@ pipeline "cred_gcp" {
}
}


pipeline "cred_basic" {
param "cred" {
type = string
default = "credentials"
}

step "transform" "basic_username" {
value = credential.basic[param.cred].username
}

step "transform" "basic_password" {
value = credential.basic[param.cred].password
}

output "val_username" {
value = step.transform.basic_username.value
}

output "val_password" {
value = step.transform.basic_password.value
}
}

pipeline "cred_slack" {
param "cred" {
type = string
Expand Down
5 changes: 0 additions & 5 deletions internal/es/estest/test_suite_mod/workspaces.fpc
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@ credential "aws" "aws_profile_to_silverwater" {
profile = "silverwater"
}

credential "basic" "credentials" {
username = "foo"
password = "bar"
}

credential "slack" "slack_static" {
token = "jgdjslgjdljgldjglsdjl"
}
Expand Down
9 changes: 5 additions & 4 deletions internal/es/execution/execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/turbot/flowpipe/internal/store"
"github.com/turbot/flowpipe/internal/types"
pfconstants "github.com/turbot/pipe-fittings/constants"
"github.com/turbot/pipe-fittings/credential"
"github.com/turbot/pipe-fittings/funcs"
"github.com/turbot/pipe-fittings/hclhelpers"
"github.com/turbot/pipe-fittings/modconfig"
Expand Down Expand Up @@ -142,7 +143,7 @@ func (ex *Execution) buildCredentialMapForEvalContext(credentialsInContext []str
}

allCredentials := fpConfig.Credentials
relevantCredentials := map[string]modconfig.Credential{}
relevantCredentials := map[string]credential.Credential{}
dynamicCredsType := map[string]bool{}

for _, credentialName := range credentialsInContext {
Expand Down Expand Up @@ -180,7 +181,7 @@ func (ex *Execution) buildCredentialMapForEvalContext(credentialsInContext []str
return credentialMap, nil
}

func buildCredentialMapForEvalContext(ctx context.Context, allCredentials map[string]modconfig.Credential) (map[string]cty.Value, error) {
func buildCredentialMapForEvalContext(ctx context.Context, allCredentials map[string]credential.Credential) (map[string]cty.Value, error) {
credentialMap := map[string]cty.Value{}

cache := cache.GetCache()
Expand All @@ -190,7 +191,7 @@ func buildCredentialMapForEvalContext(ctx context.Context, allCredentials map[st
return nil, perr.BadRequestWithMessage("invalid credential name: " + c.Name())
}

var credToUse modconfig.Credential
var credToUse credential.Credential

cachedCred, found := cache.Get(c.GetHclResourceImpl().FullName)
if !found {
Expand All @@ -207,7 +208,7 @@ func buildCredentialMapForEvalContext(ctx context.Context, allCredentials map[st
credToUse = newC
} else {
var ok bool
credToUse, ok = cachedCred.(modconfig.Credential)
credToUse, ok = cachedCred.(credential.Credential)
if !ok {
return nil, perr.BadRequestWithMessage("invalid credential type: " + c.Name())
}
Expand Down
3 changes: 2 additions & 1 deletion internal/es/execution/execution_in_memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/turbot/flowpipe/internal/es/event"
"github.com/turbot/pipe-fittings/constants"
pfconstants "github.com/turbot/pipe-fittings/constants"
"github.com/turbot/pipe-fittings/credential"
"github.com/turbot/pipe-fittings/funcs"
"github.com/turbot/pipe-fittings/hclhelpers"
"github.com/turbot/pipe-fittings/modconfig"
Expand Down Expand Up @@ -198,7 +199,7 @@ func (ex *ExecutionInMemory) buildCredentialMapForEvalContext(credentialsInConte
}

allCredentials := fpConfig.Credentials
relevantCredentials := map[string]modconfig.Credential{}
relevantCredentials := map[string]credential.Credential{}
dynamicCredsType := map[string]bool{}

for _, credentialName := range credentialsInContext {
Expand Down
4 changes: 2 additions & 2 deletions internal/service/manager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"syscall"
"time"

"github.com/turbot/pipe-fittings/flowpipeconfig"
"github.com/turbot/pipe-fittings/sanitize"

localconstants "github.com/turbot/flowpipe/internal/constants"
Expand All @@ -40,7 +41,6 @@ import (
"github.com/turbot/pipe-fittings/load_mod"
"github.com/turbot/pipe-fittings/modconfig"
"github.com/turbot/pipe-fittings/perr"
"github.com/turbot/pipe-fittings/steampipeconfig"
"github.com/turbot/pipe-fittings/utils"
"github.com/turbot/pipe-fittings/workspace"
)
Expand Down Expand Up @@ -253,7 +253,7 @@ func (m *Manager) initializeResources() error {
configPath, err := cmdconfig.GetConfigPath()
error_helpers.FailOnError(err)

flowpipeConfig, ew := steampipeconfig.LoadFlowpipeConfig(configPath)
flowpipeConfig, ew := flowpipeconfig.LoadFlowpipeConfig(configPath)
// check for error
error_helpers.FailOnError(ew.Error)
ew.ShowWarnings()
Expand Down

0 comments on commit 7433a27

Please sign in to comment.