Skip to content

Commit

Permalink
golang: Fix deserialization of verdictResponse (all optional fields c…
Browse files Browse the repository at this point in the history
…ould be from the previous request)
  • Loading branch information
Philip Stadermann committed Aug 7, 2024
1 parent 76e12fe commit 838b191
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 10 deletions.
16 changes: 12 additions & 4 deletions golang/vaas/examples/vaasctl/vaas.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,22 @@ func main() {
if !exists {
log.Fatal("no Client Secret set")
}
tokenEndpoint, exists := os.LookupEnv("TOKEN_URL")
if !exists {
tokenEndpoint = "https://account.gdata.de/realms/vaas-production/protocol/openid-connect/token"
}
vaasURL, exists := os.LookupEnv("VAAS_URL")
if !exists {
vaasURL = "wss://gateway.production.vaas.gdatasecurity.de"
}

auth := authenticator.NewWithDefaultTokenEndpoint(clientID, clientSecret)
auth := authenticator.New(clientID, clientSecret, tokenEndpoint)

vaasClient := vaas.NewWithDefaultEndpoint(options.VaasOptions{
vaasClient := vaas.New(options.VaasOptions{
UseHashLookup: true,
UseCache: false,
EnableLogs: false,
})
}, vaasURL)
ctx, webSocketCancel := context.WithCancel(context.Background())

termChan, err := vaasClient.Connect(ctx, auth)
Expand Down Expand Up @@ -98,7 +106,7 @@ func checkFile(ctx context.Context, fileList []string, vaasClient vaas.Vaas) err
}

for _, result := range results {
fmt.Println(result.Sha256, result.Verdict)
fmt.Println(result.Sha256, result.Verdict, result.Detection)
}
}
return nil
Expand Down
3 changes: 2 additions & 1 deletion golang/vaas/pkg/vaas/vaas.go
Original file line number Diff line number Diff line change
Expand Up @@ -653,8 +653,9 @@ func (v *vaas) listenWebSocket(ctx context.Context) chan error {
}

func (v *vaas) readWebSocket(termChan chan<- error) {
var verdictResponse msg.VerdictResponse
for {
var verdictResponse msg.VerdictResponse

err := v.websocketConnection.ReadJSON(&verdictResponse)
if err == nil {
v.openRequestsMutex.Lock()
Expand Down
16 changes: 12 additions & 4 deletions golang/vaas/v2/examples/vaasctl/vaas.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,22 @@ func main() {
if !exists {
log.Fatal("no Client Secret set")
}
tokenEndpoint, exists := os.LookupEnv("TOKEN_URL")
if !exists {
tokenEndpoint = "https://account.gdata.de/realms/vaas-production/protocol/openid-connect/token"
}
vaasURL, exists := os.LookupEnv("VAAS_URL")
if !exists {
vaasURL = "wss://gateway.production.vaas.gdatasecurity.de"
}

auth := authenticator.NewWithDefaultTokenEndpoint(clientID, clientSecret)
auth := authenticator.New(clientID, clientSecret, tokenEndpoint)

vaasClient := vaas.NewWithDefaultEndpoint(options.VaasOptions{
vaasClient := vaas.New(options.VaasOptions{
UseHashLookup: true,
UseCache: false,
EnableLogs: false,
})
}, vaasURL)
connectCtx, webSocketCancel := context.WithTimeout(context.Background(), 5*time.Second)
defer webSocketCancel()

Expand Down Expand Up @@ -100,7 +108,7 @@ func checkFile(ctx context.Context, fileList []string, vaasClient vaas.Vaas) err
}

for _, result := range results {
fmt.Println(result.Sha256, result.Verdict)
fmt.Println(result.Sha256, result.Verdict, result.Detection)
}
}
return nil
Expand Down
3 changes: 2 additions & 1 deletion golang/vaas/v2/pkg/vaas/vaas.go
Original file line number Diff line number Diff line change
Expand Up @@ -651,8 +651,9 @@ func (v *vaas) listenWebSocket() <-chan error {
defer close(errorChan)
defer close(v.termChan)

var verdictResponse msg.VerdictResponse
for {
var verdictResponse msg.VerdictResponse

err := v.websocketConnection.ReadJSON(&verdictResponse)
if err == nil {
v.openRequestsMutex.Lock()
Expand Down

0 comments on commit 838b191

Please sign in to comment.