aboutsummaryrefslogtreecommitdiffstats
path: root/skate
diff options
context:
space:
mode:
authorMartin Czygan <martin.czygan@gmail.com>2021-06-01 17:38:11 +0200
committerMartin Czygan <martin.czygan@gmail.com>2021-06-01 17:38:11 +0200
commit5c2597133c64ab0ffe2a54d1f23834249278db4a (patch)
tree94ca0ac4ef269fc91cf3d5f3a0c0005076a855e1 /skate
parent25a4517383c03540bd3d7695e14f60c1bb20da2d (diff)
downloadrefcat-5c2597133c64ab0ffe2a54d1f23834249278db4a.tar.gz
refcat-5c2597133c64ab0ffe2a54d1f23834249278db4a.zip
add mapper: MapperReleaseResolvedContainerName
Diffstat (limited to 'skate')
-rw-r--r--skate/cmd/skate-map/main.go3
-rw-r--r--skate/map.go17
2 files changed, 19 insertions, 1 deletions
diff --git a/skate/cmd/skate-map/main.go b/skate/cmd/skate-map/main.go
index 060e324..3d5630b 100644
--- a/skate/cmd/skate-map/main.go
+++ b/skate/cmd/skate-map/main.go
@@ -66,7 +66,7 @@ func main() {
flag.Parse()
availableMappers := map[string]skate.Mapper{
// Add new mapper functions here. TODO: add more docs, and improve
- // composability, e.g. like middleware.
+ // composability, e.g. like middleware. Also improve naming.
"id": skate.Identity,
"ff": skate.CreateFixedMapper(*extraValue),
"ti": skate.MapperTitle,
@@ -77,6 +77,7 @@ func main() {
"cni": skate.MapperContainerName,
"cns": skate.MapperContainerNameSandcrawler,
"rcns": skate.MapperReleaseContainerName,
+ "vcns": skate.MapperReleaseResolvedContainerName,
}
if *logFile != "" {
f, err := os.OpenFile(*logFile, os.O_CREATE|os.O_APPEND, 0644)
diff --git a/skate/map.go b/skate/map.go
index a06b5ae..1d21818 100644
--- a/skate/map.go
+++ b/skate/map.go
@@ -257,6 +257,23 @@ func MapperReleaseContainerName(p []byte) (fields [][]byte, err error) {
return [][]byte{key, p}, nil
}
+// MapperReleaseResolvedContainerName extracts slug container name from
+// resolved container names.
+func MapperReleaseResolvedContainerName(p []byte) (fields [][]byte, err error) {
+ var (
+ doc Release
+ key []byte
+ )
+ if err := json.Unmarshal(p, &doc); err != nil {
+ return nil, err
+ }
+ if doc.Extra.Skate.ResolvedContainerName == "" {
+ return nil, nil
+ }
+ key = []byte(sandcrawlerSlugify(wsReplacer.Replace(strings.TrimSpace(doc.Extra.Skate.ResolvedContainerName))))
+ return [][]byte{key, p}, nil
+}
+
// MapperPartial works on partial documents.
func MapperPartial(p []byte) (fields [][]byte, err error) {
return nil, nil