-
Notifications
You must be signed in to change notification settings - Fork 52
/
config.go
80 lines (68 loc) · 2.42 KB
/
config.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
package main
import (
"log/slog"
"os"
"github.com/ossf/package-analysis/internal/resultstore"
"github.com/ossf/package-analysis/internal/worker"
)
// resultBucketPaths holds bucket paths for the different types of results.
type resultBucketPaths struct {
analyzedPkg string
dynamicAnalysis string
executionLog string
fileWrites string
staticAnalysis string
}
type sandboxImageSpec struct {
tag string
noPull bool
}
type config struct {
imageSpec sandboxImageSpec
resultStores *worker.ResultStores
subURL string
packagesBucket string
notificationTopicURL string
userAgentExtra string
}
func (c *config) LogValue() slog.Value {
return slog.GroupValue(
slog.String("subscription", c.subURL),
slog.String("package_bucket", c.packagesBucket),
slog.String("dynamic_results_store", c.resultStores.DynamicAnalysis.String()),
slog.String("static_results_store", c.resultStores.StaticAnalysis.String()),
slog.String("file_write_results_store", c.resultStores.FileWrites.String()),
slog.String("analyzed_packages_store", c.resultStores.AnalyzedPackage.String()),
slog.String("execution_log_store", c.resultStores.ExecutionLog.String()),
slog.String("image_tag", c.imageSpec.tag),
slog.Bool("image_nopull", c.imageSpec.noPull),
slog.String("topic_notification", c.notificationTopicURL),
slog.String("user_agent_extra", c.userAgentExtra),
)
}
func resultStoreForEnv(key string) *resultstore.ResultStore {
val := os.Getenv(key)
if val == "" {
return nil
}
return resultstore.New(val, resultstore.ConstructPath())
}
func configFromEnv() *config {
return &config{
imageSpec: sandboxImageSpec{
tag: os.Getenv("OSSF_SANDBOX_IMAGE_TAG"),
noPull: os.Getenv("OSSF_SANDBOX_NOPULL") != "",
},
resultStores: &worker.ResultStores{
AnalyzedPackage: resultStoreForEnv("OSSF_MALWARE_ANALYZED_PACKAGES"),
DynamicAnalysis: resultStoreForEnv("OSSF_MALWARE_ANALYSIS_RESULTS"),
ExecutionLog: resultStoreForEnv("OSSF_MALWARE_ANALYSIS_EXECUTION_LOGS"),
FileWrites: resultStoreForEnv("OSSF_MALWARE_ANALYSIS_FILE_WRITE_RESULTS"),
StaticAnalysis: resultStoreForEnv("OSSF_MALWARE_STATIC_ANALYSIS_RESULTS"),
},
subURL: os.Getenv("OSSMALWARE_WORKER_SUBSCRIPTION"),
packagesBucket: os.Getenv("OSSF_MALWARE_ANALYSIS_PACKAGES"),
notificationTopicURL: os.Getenv("OSSF_MALWARE_NOTIFICATION_TOPIC"),
userAgentExtra: os.Getenv("OSSF_MALWARE_USER_AGENT_EXTRA"),
}
}