Skip to content

Commit

Permalink
feat: default integration/notifier files
Browse files Browse the repository at this point in the history
  • Loading branch information
graza-io committed Feb 7, 2024
1 parent 0c56e95 commit c7646e9
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
28 changes: 28 additions & 0 deletions internal/cmdconfig/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,15 @@ package cmdconfig
import (
"maps"
"os"
"path/filepath"
"time"

"github.com/spf13/cobra"
"github.com/spf13/viper"
con "github.com/turbot/flowpipe/internal/constants"
"github.com/turbot/flowpipe/internal/log"
"github.com/turbot/go-kit/files"
"github.com/turbot/pipe-fittings/app_specific"
"github.com/turbot/pipe-fittings/cmdconfig"
"github.com/turbot/pipe-fittings/constants"
"github.com/turbot/pipe-fittings/error_helpers"
Expand All @@ -16,6 +21,9 @@ import (
)

func initGlobalConfig() *flowpipeconfig.FlowpipeConfig {
// check defaults prior to loading into workspace
defaultIntegrationNotifierFiles()

// load workspace profile from the configured install dir
loader, err := cmdconfig.GetWorkspaceProfileLoader[*modconfig.FlowpipeWorkspaceProfile]()
error_helpers.FailOnError(err)
Expand Down Expand Up @@ -77,3 +85,23 @@ func getConfigDefaults(cmd *cobra.Command) map[string]any {
}
return res
}

func defaultIntegrationNotifierFiles() {
installPath := app_specific.DefaultInstallDir
// configPath := strings.Split(app_specific.DefaultConfigPath, ":")[len(strings.Split(app_specific.DefaultConfigPath, ":"))-1]
configPath := filepath.Join(installPath, "config")
internalStateFile := filepath.Join(installPath, "internal", ".webform_initialized")
integrationFile := filepath.Join(configPath, "integrations.fpc")
notifierFile := filepath.Join(configPath, "notifiers.fpc")
if !files.FileExists(internalStateFile) {
if !files.FileExists(integrationFile) {
_ = os.WriteFile(integrationFile, []byte(con.DefaultFlowpipeIntegrationContent), 0755)
}
if !files.FileExists(notifierFile) {
_ = os.WriteFile(notifierFile, []byte(con.DefaultFlowpipeNotifierContent), 0755)
}

ts := time.Now().Format(time.RFC3339)
_ = os.WriteFile(internalStateFile, []byte(ts), 0755)
}
}
12 changes: 12 additions & 0 deletions internal/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,15 @@ const (

MaxScanSize = bufio.MaxScanTokenSize * 40
)

const DefaultFlowpipeIntegrationContent = `
integration "webform" "default" {}
`

const DefaultFlowpipeNotifierContent = `
notifier "default" {
integration "default" {
base = integration.webform.default
}
}
`

0 comments on commit c7646e9

Please sign in to comment.