-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathconfig.go
More file actions
79 lines (68 loc) · 3.09 KB
/
config.go
File metadata and controls
79 lines (68 loc) · 3.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package config
import (
"encoding/json"
"os"
"github.com/rs/zerolog/log"
tclient "go.temporal.io/sdk/client"
tworker "go.temporal.io/sdk/worker"
)
type GitConfig struct {
Username string `json:"Username"` // Username
Password string `json:"Password"` // Password or token
Insecure bool `json:"Insecure"` // Allow insecure server connections when using SSL
}
type Module struct {
GitUrl string `json:"GitUrl"` // Git repository path
SubStorage string `json:"SubStorage"` // Sub storage to store the module
ModuleLocation string `json:"ModuleLocation"` // Path to the module in the git repository
GitConfig GitConfig `json:"GitConfig"`
}
// TDWS configuration
type Config struct {
AlwaysDownloadModules bool `json:"AlwaysDownloadModules"` // Always download the modules even if they are already downloaded (if not it will only download if the module doesnt exist)
TemporalWorkerName string `json:"TemporalWorkerName"` // Name of the temporal worker, this will replace tworker.Options.Identity (TemporalWorkerOptions.Identity)
TemporalTaskQueue string `json:"TemporalTaskQueue"` // Name of the temporal task queue
TemporalClientOptions tclient.Options `json:"TemporalClientOptions"` // Temporal client options (see https://pkg.go.dev/go.temporal.io/[email protected]/internal#ClientOptions)
TemporalWorkerOptions tworker.Options `json:"TemporalWorkerOptions"` // Temporal worker options (see https://pkg.go.dev/go.temporal.io/[email protected]/internal#WorkerOptions)
Storage string `json:"Storage"` // Where to git clone the repositories (modules)
GitConfig GitConfig `json:"GitConfig"` // Git configuration, will be used to clone the repositories if not provided in the module
Modules []Module `json:"Modules"` // Modules to be cloned
}
// LoadConfig loads the configuration from the configuration file
func LoadConfig() Config {
// Load the configuration file tdws.json or TDWS_CONFIG_FILE environment variable
tdwsFileName := os.Getenv("TDWS_CONFIG_FILE")
if tdwsFileName == "" {
tdwsFileName = "tdws.json"
}
// Open the configuration file
jsonFile, err := os.Open(tdwsFileName)
if err != nil {
log.Fatal().Err(err).Msg("Failed to read the configuration file")
}
// Base configuration
config := Config{
TemporalWorkerName: "tdws-worker",
TemporalTaskQueue: "tdws-task-queue",
TemporalClientOptions: tclient.Options{
HostPort: "temporal:7233",
},
Storage: "tdws-storage",
GitConfig: GitConfig{
Insecure: false,
},
}
// Load the configuration from the json and update the base configuration
err = json.NewDecoder(jsonFile).Decode(&config)
if err != nil {
// log config struct
log.Fatal().Err(err).Msg("Failed to decode the configuration file")
}
// Create storage if it doesn't exist
if _, err := os.Stat(config.Storage); os.IsNotExist(err) {
os.Mkdir(config.Storage, 0755)
}
// Log the configuration loaded
log.Info().Interface("config", json.NewDecoder(jsonFile)).Msg("Configuration loaded")
return config
}