-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathpaths.go
77 lines (65 loc) · 1.67 KB
/
paths.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
package utils
import (
"os"
"path/filepath"
"github.com/jfrog/jfrog-cli-core/v2/utils/coreutils"
"github.com/jfrog/jfrog-cli-security/utils/techutils"
)
const (
JfrogCurationDirName = "curation"
CurationsDir = "JFROG_CLI_CURATION_DIR"
// #nosec G101 -- Not credentials.
CurationSupportFlag = "JFROG_CLI_CURATION"
)
func getJfrogCurationFolder() (string, error) {
dependenciesDir := os.Getenv(CurationsDir)
if dependenciesDir != "" {
return dependenciesDir, nil
}
jfrogHome, err := coreutils.GetJfrogHomeDir()
if err != nil {
return "", err
}
return filepath.Join(jfrogHome, JfrogCurationDirName), nil
}
func GetCurationCacheFolder() (string, error) {
curationFolder, err := getJfrogCurationFolder()
if err != nil {
return "", err
}
return filepath.Join(curationFolder, "cache"), nil
}
func GetCurationCacheFolderByTech(tech techutils.Technology) (projectDir string, err error) {
pathHash, errFromHash := getProjectPathHash()
if errFromHash != nil {
err = errFromHash
return
}
curationFolder, err := GetCurationCacheFolder()
if err != nil {
return "", err
}
projectDir = filepath.Join(curationFolder, tech.String(), pathHash)
return
}
func getProjectPathHash() (string, error) {
workingDir, err := os.Getwd()
if err != nil {
return "", err
}
return Sha1Hash(workingDir)
}
func GetCurationPipCacheFolder() (string, error) {
curationFolder, err := GetCurationCacheFolder()
if err != nil {
return "", err
}
return filepath.Join(curationFolder, "pip"), nil
}
func GetCurationNugetCacheFolder() (string, error) {
curationFolder, err := GetCurationCacheFolder()
if err != nil {
return "", err
}
return filepath.Join(curationFolder, "nuget"), nil
}