-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathinstall_dir.go
157 lines (125 loc) · 4.83 KB
/
install_dir.go
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
package filepaths
import (
"fmt"
"os"
"path/filepath"
"github.com/turbot/pipe-fittings/v2/app_specific"
"github.com/turbot/pipe-fittings/v2/error_helpers"
)
// Constants for Config
const (
connectionsStateFileName = "connection.json"
versionFileName = "versions.json"
databaseRunningInfoFileName = "steampipe.json"
pluginManagerStateFileName = "plugin_manager.json"
dashboardServerStateFileName = "dashboard_service.json"
stateFileName = "update_check.json"
legacyStateFileName = "update-check.json"
availableVersionsFileName = "available_versions.json"
legacyNotificationsFileName = "notifications.json"
)
func ensureInstallSubDir(dirName string) string {
subDir := installSubDir(dirName)
if _, err := os.Stat(subDir); os.IsNotExist(err) {
err = os.MkdirAll(subDir, 0755)
error_helpers.FailOnErrorWithMessage(err, fmt.Sprintf("could not create %s directory", dirName))
}
return subDir
}
func installSubDir(dirName string) string {
if app_specific.InstallDir == "" {
panic(fmt.Errorf("cannot call any %s directory functions before InstallDir is set", app_specific.AppName))
}
return filepath.Join(app_specific.InstallDir, dirName)
}
// EnsureControlTemplateDir returns the path to the templates directory (creates if missing)
func EnsureControlTemplateDir() string {
return ensureInstallSubDir(filepath.Join("check", "templates"))
}
// EnsureDetectionTemplateDir returns the path to the detection templates directory (creates if missing)
func EnsureDetectionTemplateDir() string {
return ensureInstallSubDir(filepath.Join("check", "detection_templates"))
}
// EnsureConfigDir returns the path to the config directory (creates if missing)
func EnsureConfigDir() string {
return ensureInstallSubDir("config")
}
// GetInternalDir returns the path to the internal directory
func GetInternalDir() string {
return installSubDir("internal")
}
// EnsureInternalDir returns the path to the internal directory (creates if missing)
func EnsureInternalDir() string {
return ensureInstallSubDir("internal")
}
// EnsureBackupsDir returns the path to the backups directory (creates if missing)
func EnsureBackupsDir() string {
return ensureInstallSubDir("backups")
}
// BackupsDir returns the path to the backups directory
func BackupsDir() string {
return installSubDir("backups")
}
// EnsureDatabaseDir returns the path to the db directory (creates if missing)
func EnsureDatabaseDir() string {
return ensureInstallSubDir("db")
}
// EnsureLogDir returns the path to the db log directory (creates if missing)
func EnsureLogDir() string {
return ensureInstallSubDir("logs")
}
func EnsureDashboardAssetsDir() string {
return ensureInstallSubDir(filepath.Join("dashboard", "assets"))
}
// StateFilePath returns the path of the update_check.json state file
func StateFilePath() string {
return filepath.Join(EnsureInternalDir(), stateFileName)
}
// AvailableVersionsFilePath returns the path of the json file used to store cache available versions of installed plugins and the CLI
func AvailableVersionsFilePath() string {
return filepath.Join(EnsureInternalDir(), availableVersionsFileName)
}
// LegacyNotificationsFilePath returns the path of the (legacy) notifications.json file used to store update notifications
func LegacyNotificationsFilePath() string {
return filepath.Join(EnsureInternalDir(), legacyNotificationsFileName)
}
// ConnectionStatePath returns the path of the connections state file
func ConnectionStatePath() string {
return filepath.Join(EnsureInternalDir(), connectionsStateFileName)
}
// LegacyVersionFilePath returns the legacy version file path
func LegacyVersionFilePath() string {
return filepath.Join(EnsureInternalDir(), versionFileName)
}
// PluginVersionFilePath returns the plugin version file path
func PluginVersionFilePath() string {
return filepath.Join(EnsurePluginDir(), versionFileName)
}
// DatabaseVersionFilePath returns the plugin version file path
func DatabaseVersionFilePath() string {
return filepath.Join(EnsureDatabaseDir(), versionFileName)
}
// ReportAssetsVersionFilePath returns the report assets version file path
func ReportAssetsVersionFilePath() string {
return filepath.Join(EnsureDashboardAssetsDir(), versionFileName)
}
func RunningInfoFilePath() string {
return filepath.Join(EnsureInternalDir(), databaseRunningInfoFileName)
}
func PluginManagerStateFilePath() string {
return filepath.Join(EnsureInternalDir(), pluginManagerStateFileName)
}
func DashboardServiceStateFilePath() string {
return filepath.Join(EnsureInternalDir(), dashboardServerStateFileName)
}
func StateFileName() string {
return stateFileName
}
// GetDataDir returns the path to the data directory
func GetDataDir() string {
return installSubDir("data")
}
// EnsureDataDir returns the path to the data directory (creates if missing)
func EnsureDataDir() string {
return ensureInstallSubDir("data")
}