-
Notifications
You must be signed in to change notification settings - Fork 262
/
steampipe.go
170 lines (136 loc) · 5.43 KB
/
steampipe.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
158
159
160
161
162
163
164
165
166
167
168
169
170
package filepaths
import (
"fmt"
"os"
"path/filepath"
filehelpers "github.com/turbot/go-kit/files"
"github.com/turbot/steampipe/pkg/constants"
"github.com/turbot/steampipe/pkg/error_helpers"
)
// Constants for Config
const (
DefaultInstallDir = "~/.steampipe"
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"
)
var SteampipeDir string
func ensureSteampipeSubDir(dirName string) string {
subDir := steampipeSubDir(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 steampipeSubDir(dirName string) string {
if SteampipeDir == "" {
panic(fmt.Errorf("cannot call any Steampipe directory functions before SteampipeDir is set"))
}
return filepath.Join(SteampipeDir, dirName)
}
// EnsureTemplateDir returns the path to the templates directory (creates if missing)
func EnsureTemplateDir() string {
return ensureSteampipeSubDir(filepath.Join("check", "templates"))
}
// EnsurePluginDir returns the path to the plugins directory (creates if missing)
func EnsurePluginDir() string {
return ensureSteampipeSubDir("plugins")
}
// EnsureConfigDir returns the path to the config directory (creates if missing)
func EnsureConfigDir() string {
return ensureSteampipeSubDir("config")
}
// EnsureInternalDir returns the path to the internal directory (creates if missing)
func EnsureInternalDir() string {
return ensureSteampipeSubDir("internal")
}
// EnsureBackupsDir returns the path to the backups directory (creates if missing)
func EnsureBackupsDir() string {
return ensureSteampipeSubDir("backups")
}
// BackupsDir returns the path to the backups directory
func BackupsDir() string {
return steampipeSubDir("backups")
}
// WorkspaceProfileDir returns the path to the workspace profiles directory
// if STEAMPIPE_WORKSPACE_PROFILES_LOCATION is set use that
// otherwise look in the config folder
// NOTE: unlike other path functions this accepts the install-dir as arg
// this is because of the slightly complex bootstrapping process required because the
// install-dir may be set in the workspace profile
func WorkspaceProfileDir(installDir string) (string, error) {
if workspaceProfileLocation, ok := os.LookupEnv(constants.EnvWorkspaceProfileLocation); ok {
return filehelpers.Tildefy(workspaceProfileLocation)
}
return filepath.Join(installDir, "config"), nil
}
// EnsureDatabaseDir returns the path to the db directory (creates if missing)
func EnsureDatabaseDir() string {
return ensureSteampipeSubDir("db")
}
// EnsureLogDir returns the path to the db log directory (creates if missing)
func EnsureLogDir() string {
return ensureSteampipeSubDir("logs")
}
func EnsureDashboardAssetsDir() string {
return ensureSteampipeSubDir(filepath.Join("dashboard", "assets"))
}
// LegacyDashboardAssetsDir returns the path to the legacy report assets folder
func LegacyDashboardAssetsDir() string {
return steampipeSubDir("report")
}
// LegacyStateFilePath returns the path of the legacy update-check.json state file
func LegacyStateFilePath() string {
return filepath.Join(EnsureInternalDir(), legacyStateFileName)
}
// 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
}