feat (url-logger) Implement logic for a selection classifier (#4411)

* forcing the urls finder to relaxed

* adding a classifier map

* passing the stepName to the kaniko command executor bundle

* pass stepName to maven utils for mavenBuild

* improve enabling of Maven access log generation

* Revert "improve enabling of Maven access log generation"

This reverts commit 80b77223cd.

* Revert "pass stepName to maven utils for mavenBuild"

This reverts commit a4f99ae160.

* use reflection to update command stepName for mavenBuild

* Revert "use reflection to update command stepName for mavenBuild"

This reverts commit ef85c78669.

---------

Co-authored-by: I557621 <jordi.van.liempt@sap.com>
Co-authored-by: Jordi van Liempt <35920075+jliempt@users.noreply.github.com>
This commit is contained in:
Anil Keshav
2023-06-26 08:47:11 +02:00
committed by GitHub
co-authored by I557621 Jordi van Liempt
parent ae4550d0dd
commit a9bab48557
2 changed files with 23 additions and 4 deletions
+1
View File
@@ -25,6 +25,7 @@ func kanikoExecute(config kanikoExecuteOptions, telemetryData *telemetry.CustomD
"unsupported status code 401",
},
},
StepName: "kanikoExecute",
}
// reroute command output to logging framework
+22 -4
View File
@@ -5,9 +5,10 @@ import (
"encoding/json"
"fmt"
"io/ioutil"
"mvdan.cc/xurls/v2"
"os"
"sync"
"mvdan.cc/xurls/v2"
)
type (
@@ -89,9 +90,26 @@ func (cl *URLLogger) WriteURLsLogToJSON() error {
func (cl *URLLogger) Parse(buf bytes.Buffer) {
cl.buf.Lock()
defer cl.buf.Unlock()
cl.buf.data = append(cl.buf.data, parseURLs(buf.Bytes())...)
classifier := returnURLStrictClassifier(cl.stepName)
cl.buf.data = append(cl.buf.data, parseURLs(buf.Bytes(), classifier)...)
}
func parseURLs(src []byte) [][]byte {
return xurls.Strict().FindAll(src, -1)
func parseURLs(src []byte, classifier string) [][]byte {
if classifier == "Strict" {
return xurls.Strict().FindAll(src, -1)
} else {
return xurls.Relaxed().FindAll(src, -1)
}
}
func returnURLStrictClassifier(stepName string) string {
switch stepName {
// golang cli output urls without the http protocol hence making the search less strict
//ToDo: other cases where the url is without protocol
case "golangBuild":
return "Relaxed"
default:
return "Strict"
}
}