Skip to content

Commit

Permalink
Comment out broken input step. (#635)
Browse files Browse the repository at this point in the history
  • Loading branch information
vhadianto authored Feb 7, 2024
1 parent 0c56e95 commit 90d08ef
Show file tree
Hide file tree
Showing 5 changed files with 126 additions and 214 deletions.
13 changes: 0 additions & 13 deletions internal/es/estest/mod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1113,19 +1113,6 @@ func (suite *ModTestSuite) TestForEachEmptyAndNonCollection() {
}
}

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

rootMod := suite.manager.RootMod
assert.NotNil(rootMod)

integrations := rootMod.ResourceMaps.Integrations["test_suite_mod.integration.slack.slack_app_from_var"]
if integrations == nil {
assert.Fail("test_suite_mod.integration.slack.slack_app_from_var not found")
return
}
}

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

Expand Down
20 changes: 10 additions & 10 deletions internal/es/estest/test_suite_mod/integrations/integrations.fp
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
integration "slack" "my_slack_app" {
token = "xoxp-111111"
// integration "slack" "my_slack_app" {
// token = "xoxp-111111"

# optional - if you want to verify the source
signing_secret = "Q#$$#@#$$#W"
}
// # optional - if you want to verify the source
// signing_secret = "Q#$$#@#$$#W"
// }

integration "slack" "slack_app_from_var" {
token = var.slack_token
# TODO: this doesn't work
signing_secret = var.slack_signing_secret
}
// integration "slack" "slack_app_from_var" {
// token = var.slack_token
// # TODO: this doesn't work
// signing_secret = var.slack_signing_secret
// }
76 changes: 0 additions & 76 deletions internal/es/estest/test_suite_mod/pipelines/input.fp

This file was deleted.

3 changes: 3 additions & 0 deletions internal/es/execution/execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,9 @@ func (ex *Execution) buildCredentialMapForEvalContext(credentialsInContext []str
relevantCredentials[credentialName] = allCredentials[credentialName]
}

// Why do we bother with these <dynamic> dependencies?
// We don't want to resolve every single available in the system, we only want to resolve the ones that are
// are used. So this is part of how have an educated guess which credentials to resolve.
if strings.Contains(credentialName, "<dynamic>") {
parts := strings.Split(credentialName, ".")
if len(parts) > 0 {
Expand Down
228 changes: 113 additions & 115 deletions internal/primitive/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@ import (
"encoding/json"
"errors"
"fmt"
"github.com/slack-go/slack"
"github.com/turbot/flowpipe/templates"
"github.com/turbot/go-kit/helpers"
"github.com/turbot/go-kit/types"
"github.com/turbot/pipe-fittings/constants"
"html/template"
"net/mail"
"net/smtp"
Expand All @@ -20,6 +15,12 @@ import (
"strings"
"time"

"github.com/slack-go/slack"
"github.com/turbot/flowpipe/templates"
"github.com/turbot/go-kit/helpers"
"github.com/turbot/go-kit/types"
"github.com/turbot/pipe-fittings/constants"

"github.com/turbot/pipe-fittings/modconfig"
"github.com/turbot/pipe-fittings/perr"
"github.com/turbot/pipe-fittings/schema"
Expand Down Expand Up @@ -397,10 +398,6 @@ func (ip *Input) ValidateInput(ctx context.Context, i modconfig.Input) error {
return perr.BadRequestWithMessage("Input type must be a string")
}

if i[schema.AttributeTypeNotifies] == nil {
return perr.BadRequestWithMessage("Input must define at least one notification")
}

// TODO: validate type is one of button, text, select, multiselect, combo, multicombo
// TODO: other validations
// inputType := i[schema.AttributeTypeType].(string)
Expand Down Expand Up @@ -467,116 +464,117 @@ func (ip *Input) Run(ctx context.Context, input modconfig.Input) (*modconfig.Out
}

output := &modconfig.Output{}
base := NewInputIntegrationBase(ip)
var prompt, inputType string
var resOptions []InputIntegrationResponseOption
if it, ok := input[schema.AttributeTypeType].(string); ok {
inputType = it
}
if p, ok := input[schema.AttributeTypePrompt].(string); ok {
prompt = p
}
return output, nil
// base := NewInputIntegrationBase(ip)
// var prompt, inputType string
// var resOptions []InputIntegrationResponseOption
// if it, ok := input[schema.AttributeTypeType].(string); ok {
// inputType = it
// }
// if p, ok := input[schema.AttributeTypePrompt].(string); ok {
// prompt = p
// }

for _, o := range input[schema.AttributeTypeOptions].([]any) {
opt := o.(map[string]any)
option := InputIntegrationResponseOption{}
if l, ok := opt[schema.AttributeTypeLabel].(string); ok {
option.Label = &l
}
if v, ok := opt[schema.AttributeTypeValue].(string); ok {
option.Value = &v
if helpers.IsNil(option.Label) {
option.Label = &v
}
}
if s, ok := opt[schema.AttributeTypeSelected].(bool); ok {
option.Selected = &s
}
resOptions = append(resOptions, option)
}

for _, n := range input[schema.AttributeTypeNotifies].([]any) {
notification := n.(map[string]any)
integration := notification["integration"].(map[string]any)
integrationType := IntegrationType(integration["type"].(string))
switch integrationType {
case IntegrationTypeSlack:
s := NewInputIntegrationSlack(base)
if channel, ok := notification[schema.AttributeTypeChannel].(string); ok {
s.Channel = &channel
}
if tkn, ok := integration[schema.AttributeTypeToken].(string); ok {
s.Token = &tkn
}
if ss, ok := integration[schema.AttributeTypeSigningSecret].(string); ok {
s.SigningSecret = &ss
}
if wu, ok := integration[schema.AttributeTypeWebhookUrl].(string); ok {
s.WebhookUrl = &wu
}
// for _, o := range input[schema.AttributeTypeOptions].([]any) {
// opt := o.(map[string]any)
// option := InputIntegrationResponseOption{}
// if l, ok := opt[schema.AttributeTypeLabel].(string); ok {
// option.Label = &l
// }
// if v, ok := opt[schema.AttributeTypeValue].(string); ok {
// option.Value = &v
// if helpers.IsNil(option.Label) {
// option.Label = &v
// }
// }
// if s, ok := opt[schema.AttributeTypeSelected].(bool); ok {
// option.Selected = &s
// }
// resOptions = append(resOptions, option)
// }

// TODO: Validate?
err := s.PostMessage(inputType, prompt, resOptions)
if err != nil {
return nil, err
}
case IntegrationTypeEmail:
email := NewInputIntegrationEmail(base)
if host, ok := integration[schema.AttributeTypeSmtpHost].(string); ok {
email.Host = &host
}
if port, ok := integration[schema.AttributeTypeSmtpPort].(int64); ok {
email.Port = &port
} else if port, ok := integration[schema.AttributeTypeSmtpPort].(float64); ok {
intPort := int64(port)
email.Port = &intPort
}
if sPort, ok := integration[schema.AttributeTypeSmtpsPort].(int64); ok {
email.SecurePort = &sPort
} else if sPort, ok := integration[schema.AttributeTypeSmtpsPort].(float64); ok {
intPort := int64(sPort)
email.SecurePort = &intPort
}
if tls, ok := integration[schema.AttributeTypeSmtpTls].(string); ok {
email.Tls = &tls
}
if from, ok := integration[schema.AttributeTypeFrom].(string); ok {
email.From = from
}
if to, ok := notification[schema.AttributeTypeTo].(string); ok {
email.To = append(email.To, to)
} else if to, ok := integration[schema.AttributeTypeDefaultRecipient].(string); ok {
email.To = append(email.To, to)
}
if sub, ok := integration[schema.AttributeTypeSubject].(string); ok {
email.Subject = sub
} else if sub, ok := integration[schema.AttributeTypeDefaultSubject].(string); ok {
email.Subject = sub
}
if u, ok := integration[schema.AttributeTypeSmtpUsername].(string); ok {
email.User = &u
}
if p, ok := integration[schema.AttributeTypeSmtpPassword].(string); ok {
email.Pass = &p
}
if resUrl, ok := integration[schema.AttributeTypeResponseUrl].(string); ok {
email.ResponseUrl = resUrl
} else {
email.ResponseUrl = "http://localhost:7103" // TODO: Remove?
}
// for _, n := range input[schema.AttributeTypeNotifies].([]any) {
// notification := n.(map[string]any)
// integration := notification["integration"].(map[string]any)
// integrationType := IntegrationType(integration["type"].(string))
// switch integrationType {
// case IntegrationTypeSlack:
// s := NewInputIntegrationSlack(base)
// if channel, ok := notification[schema.AttributeTypeChannel].(string); ok {
// s.Channel = &channel
// }
// if tkn, ok := integration[schema.AttributeTypeToken].(string); ok {
// s.Token = &tkn
// }
// if ss, ok := integration[schema.AttributeTypeSigningSecret].(string); ok {
// s.SigningSecret = &ss
// }
// if wu, ok := integration[schema.AttributeTypeWebhookUrl].(string); ok {
// s.WebhookUrl = &wu
// }

// TODO: Validate?
o, err := email.PostMessage(ctx, prompt, resOptions)
if err != nil {
return nil, err
}
output = o
default:
return nil, perr.InternalWithMessage(fmt.Sprintf("Unsupported integration type %s", integrationType))
}
}
// // TODO: Validate?
// err := s.PostMessage(inputType, prompt, resOptions)
// if err != nil {
// return nil, err
// }
// case IntegrationTypeEmail:
// email := NewInputIntegrationEmail(base)
// if host, ok := integration[schema.AttributeTypeSmtpHost].(string); ok {
// email.Host = &host
// }
// if port, ok := integration[schema.AttributeTypeSmtpPort].(int64); ok {
// email.Port = &port
// } else if port, ok := integration[schema.AttributeTypeSmtpPort].(float64); ok {
// intPort := int64(port)
// email.Port = &intPort
// }
// if sPort, ok := integration[schema.AttributeTypeSmtpsPort].(int64); ok {
// email.SecurePort = &sPort
// } else if sPort, ok := integration[schema.AttributeTypeSmtpsPort].(float64); ok {
// intPort := int64(sPort)
// email.SecurePort = &intPort
// }
// if tls, ok := integration[schema.AttributeTypeSmtpTls].(string); ok {
// email.Tls = &tls
// }
// if from, ok := integration[schema.AttributeTypeFrom].(string); ok {
// email.From = from
// }
// if to, ok := notification[schema.AttributeTypeTo].(string); ok {
// email.To = append(email.To, to)
// } else if to, ok := integration[schema.AttributeTypeDefaultRecipient].(string); ok {
// email.To = append(email.To, to)
// }
// if sub, ok := integration[schema.AttributeTypeSubject].(string); ok {
// email.Subject = sub
// } else if sub, ok := integration[schema.AttributeTypeDefaultSubject].(string); ok {
// email.Subject = sub
// }
// if u, ok := integration[schema.AttributeTypeSmtpUsername].(string); ok {
// email.User = &u
// }
// if p, ok := integration[schema.AttributeTypeSmtpPassword].(string); ok {
// email.Pass = &p
// }
// if resUrl, ok := integration[schema.AttributeTypeResponseUrl].(string); ok {
// email.ResponseUrl = resUrl
// } else {
// email.ResponseUrl = "http://localhost:7103" // TODO: Remove?
// }

return output, nil
// // TODO: Validate?
// o, err := email.PostMessage(ctx, prompt, resOptions)
// if err != nil {
// return nil, err
// }
// output = o
// default:
// return nil, perr.InternalWithMessage(fmt.Sprintf("Unsupported integration type %s", integrationType))
// }
// }

// return output, nil
}

func parseEmailInputTemplate(i *InputIntegrationEmail, prompt string, responseOptions []InputIntegrationResponseOption) (string, error) {
Expand Down

0 comments on commit 90d08ef

Please sign in to comment.