@@ -26,7 +26,11 @@ import (
26
26
)
27
27
28
28
// Writer writes results to SaaS
29
- type Writer struct {}
29
+ type Writer struct {
30
+ Cnf config.SaasConf
31
+ Proxy string
32
+ TimeoutSec int
33
+ }
30
34
31
35
// TempCredential : TempCredential
32
36
type TempCredential struct {
@@ -57,8 +61,8 @@ func (w Writer) Write(rs ...models.ScanResult) error {
57
61
hostname , _ := os .Hostname ()
58
62
59
63
payload := payload {
60
- GroupID : config . Conf . Saas .GroupID ,
61
- Token : config . Conf . Saas .Token ,
64
+ GroupID : w . Cnf .GroupID ,
65
+ Token : w . Cnf .Token ,
62
66
ScannedBy : hostname ,
63
67
ScannedIPv4s : strings .Join (ipv4s , ", " ),
64
68
ScannedIPv6s : strings .Join (ipv6s , ", " ),
@@ -68,16 +72,15 @@ func (w Writer) Write(rs ...models.ScanResult) error {
68
72
return xerrors .Errorf ("Failed to Marshal to JSON: %w" , err )
69
73
}
70
74
71
- ctx , cancel := context .WithTimeout (context .Background (), 10 * time .Second )
72
- req , err := http .NewRequestWithContext (ctx , http .MethodPost , config . Conf . Saas .URL , bytes .NewBuffer (body ))
75
+ ctx , cancel := context .WithTimeout (context .Background (), time . Duration ( w . TimeoutSec ) * time .Second )
76
+ req , err := http .NewRequestWithContext (ctx , http .MethodPost , w . Cnf .URL , bytes .NewBuffer (body ))
73
77
defer cancel ()
74
78
if err != nil {
75
79
return err
76
80
}
77
81
req .Header .Set ("Content-Type" , "application/json" )
78
82
req .Header .Set ("Accept" , "application/json" )
79
- // TODO Don't use global variable
80
- client , err := util .GetHTTPClient (config .Conf .HTTPProxy )
83
+ client , err := util .GetHTTPClient (w .Proxy )
81
84
if err != nil {
82
85
return err
83
86
}
@@ -107,7 +110,7 @@ func (w Writer) Write(rs ...models.ScanResult) error {
107
110
return xerrors .Errorf ("Failed to load config. err: %w" , err )
108
111
}
109
112
// For S3 upload of aws sdk
110
- if err := os .Setenv ("HTTPS_PROXY" , config . Conf . HTTPProxy ); err != nil {
113
+ if err := os .Setenv ("HTTPS_PROXY" , w . Proxy ); err != nil {
111
114
return xerrors .Errorf ("Failed to set HTTP proxy: %s" , err )
112
115
}
113
116
0 commit comments