Skip to content

Commit b4c84f1

Browse files
authored
Merge pull request #31 from ConductorOne/BB958Main
baton-sql-server: set up BATON_CONFIG_PATH in windows service
2 parents b9de97d + a5b0c42 commit b4c84f1

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

cmd/baton-sql-server/main.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import (
55
"fmt"
66
"os"
77

8+
"path/filepath"
9+
810
config "github.com/conductorone/baton-sdk/pkg/config"
911
"github.com/conductorone/baton-sdk/pkg/connectorbuilder"
1012
"github.com/conductorone/baton-sdk/pkg/types"
@@ -16,10 +18,25 @@ import (
1618

1719
var version = "dev"
1820

21+
func getConfigDir(name string) string {
22+
return filepath.Join(os.Getenv("PROGRAMDATA"), "ConductorOne", name)
23+
}
24+
1925
func main() {
2026
ctx := context.Background()
2127

22-
_, cmd, err := config.DefineConfiguration(ctx, "baton-sql-server", getConnector, cfg)
28+
connectorName := "baton-sql-server"
29+
configPath := os.Getenv("BATON_CONFIG_PATH")
30+
if configPath == "" && os.Getenv("PROGRAMDATA") != "" {
31+
// Set BATON_CONFIG_PATH so that if we're running as a windows service, we use the correct config file
32+
err := os.Setenv("BATON_CONFIG_PATH", filepath.Join(getConfigDir(connectorName), "config.yaml"))
33+
if err != nil {
34+
fmt.Fprintln(os.Stderr, err.Error())
35+
os.Exit(1)
36+
}
37+
}
38+
39+
_, cmd, err := config.DefineConfiguration(ctx, connectorName, getConnector, cfg)
2340
if err != nil {
2441
fmt.Fprintln(os.Stderr, err.Error())
2542
os.Exit(1)

0 commit comments

Comments
 (0)