-
-
Notifications
You must be signed in to change notification settings - Fork 66
Expand file tree
/
Copy pathexecutor.go
More file actions
62 lines (50 loc) · 1.59 KB
/
executor.go
File metadata and controls
62 lines (50 loc) · 1.59 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
package watcher
import (
"fmt"
"os"
"github.com/microcks/microcks-cli/pkg/config"
"github.com/microcks/microcks-cli/pkg/connectors"
)
func TriggerImport(entry config.WatchEntry) {
// Retrieve config to get client options.
cfgPath, err := config.DefaultLocalConfigPath()
if err != nil {
fmt.Printf("Error while loading config: %s\n", err.Error())
}
fmt.Println("[INFO] Re-importing changed file: " + entry.FilePath)
for _, context := range entry.Context {
// Prepare Microcks client.
var mc connectors.MicrocksClient
// If config path exist, instantiate client with it.
if _, err := os.Stat(cfgPath); err == nil {
globalClientOpts := &connectors.ClientOptions{
ConfigPath: cfgPath,
Context: context,
}
mc, err = connectors.NewClient(*globalClientOpts)
if err != nil {
fmt.Printf("[ERROR] Cannot connect to Microcks client: %v in context '%s'\n", err, context)
}
} else {
// We have no config file, so just create a client with context as server URL.
mc = connectors.NewMicrocksClient(context)
}
_, err = mc.UploadArtifact(entry.FilePath, entry.MainArtifact)
if err != nil {
fmt.Printf("[WARN] Error re-importing %s: %v\n", entry.FilePath, err)
} else {
fmt.Printf("[INFO] Successfully re-imported %s in context '%s'\n", entry.FilePath, context)
}
}
}
func LoadRegistry(watchFilePath string) (*config.WatchConfig, error) {
var watchCfg *config.WatchConfig
watchCfg, err := config.ReadLocalWatchConfig(watchFilePath)
if err != nil {
return nil, err
}
if watchCfg == nil {
watchCfg = &config.WatchConfig{}
}
return watchCfg, nil
}