From 3fa1fa43b532f336f31afcd6854095966031cb1e Mon Sep 17 00:00:00 2001 From: Blaize M Kaye Date: Mon, 18 Sep 2023 07:28:05 +1200 Subject: [PATCH 1/2] Makes defaults loadable from yaml --- .gitignore | 3 +- default_filter_transformers.json | 95 ------------------- default_filter_transformers.yaml | 49 ++++++++++ go.mod | 12 +-- go.sum | 13 +-- internal/handler/imageInspectParserFilter.go | 2 +- internal/handler/registerFilters.go | 19 +++- internal/handler/registerFilters_test.go | 64 +++++++++++++ .../testLoadTransformsFromDisk/test1.json | 7 ++ .../testLoadTransformsFromDisk/test2.yaml | 3 + .../testLoadTransformsFromDisk/test3.yml | 3 + .../testLoadTransformsFromDisk/test4.unsp | 3 + main.go | 4 +- 13 files changed, 157 insertions(+), 120 deletions(-) delete mode 100644 default_filter_transformers.json create mode 100644 default_filter_transformers.yaml create mode 100644 internal/handler/registerFilters_test.go create mode 100644 internal/handler/testassets/testLoadTransformsFromDisk/test1.json create mode 100644 internal/handler/testassets/testLoadTransformsFromDisk/test2.yaml create mode 100644 internal/handler/testassets/testLoadTransformsFromDisk/test3.yml create mode 100644 internal/handler/testassets/testLoadTransformsFromDisk/test4.unsp diff --git a/.gitignore b/.gitignore index 3bf780b..776aecc 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .idea -.env \ No newline at end of file +.env +internal/handler/testassets/bin/* \ No newline at end of file diff --git a/default_filter_transformers.json b/default_filter_transformers.json deleted file mode 100644 index c1ce467..0000000 --- a/default_filter_transformers.json +++ /dev/null @@ -1,95 +0,0 @@ -{ - "transforms": [ - { - "type": "handler.EnvironmentVariable", - "lookupvalue": [ - { - "name": "Key", - "value": "PHP_VERSION", - "exactMatch": true - } - ], - "transformations": [ - { - "name": "Name", - "value": "PHP" - }, - { - "name": "Category", - "value": "Language" - }, - { - "name": "Description", - "value": "The currently installed PHP version" - } - ], - "keyfact": true - }, - { - "type": "cyclonedx.Component", - "lookupvalue": [ - { - "name": "Name", - "value": "drupal/core", - "exactMatch": true - } - ], - "transformations": [ - { - "name": "Name", - "value": "Drupal" - }, - { - "name": "Category", - "value": "Application" - } - ], - "keyfact": true - }, - { - "type": "cyclonedx.Component", - "lookupvalue": [ - { - "name": "Name", - "value": "alpine", - "exactMatch": true - } - ], - "transformations": [ - { - "name": "Name", - "value": "Alpine Linux" - }, - { - "name": "Category", - "value": "OS" - }, - { - "name": "Description", - "value": "Base image Alpine Linux version" - } - ], - "keyfact": true - }, - { - "type": "cyclonedx.Component", - "lookupvalue": [ - { - "name": "Name", - "value": "drush/drush" - } - ], - "transformations": [ - { - "name": "Name", - "value": "Drush" - }, - { - "name": "Category", - "value": "Helper" - } - ], - "keyfact": true - } - ] -} \ No newline at end of file diff --git a/default_filter_transformers.yaml b/default_filter_transformers.yaml new file mode 100644 index 0000000..360add3 --- /dev/null +++ b/default_filter_transformers.yaml @@ -0,0 +1,49 @@ +--- +transforms: + - type: handler.EnvironmentVariable + lookupvalue: + - name: Key + value: PHP_VERSION + exactMatch: true + transformations: + - name: Name + value: PHP + - name: Category + value: Language + - name: Description + value: The currently installed PHP version + keyfact: true + - type: cyclonedx.Component + lookupvalue: + - name: Name + value: drupal/core + exactMatch: true + transformations: + - name: Name + value: Drupal + - name: Category + value: Application + keyfact: true + - type: cyclonedx.Component + lookupvalue: + - name: Name + value: alpine + exactMatch: true + transformations: + - name: Name + value: Alpine Linux + - name: Category + value: OS + - name: Description + value: Base image Alpine Linux version + keyfact: true + - type: cyclonedx.Component + lookupvalue: + - name: Name + value: drush/drush + transformations: + - name: Name + value: Drush + - name: Category + value: Helper + keyfact: true \ No newline at end of file diff --git a/go.mod b/go.mod index 09ae4d6..3830f3d 100644 --- a/go.mod +++ b/go.mod @@ -6,19 +6,18 @@ require ( github.com/Khan/genqlient v0.3.0 github.com/cheshir/go-mq v1.0.2 github.com/dgrijalva/jwt-go v3.2.0+incompatible + github.com/joho/godotenv v1.5.1 github.com/matryer/try v0.0.0-20161228173917-9ac251b645a2 + github.com/stretchr/testify v1.8.4 + gopkg.in/yaml.v1 v1.0.0-20140924161607-9f9df34309c0 ) require ( github.com/NeowayLabs/wabbit v0.0.0-20200409220312-12e68ab5b0c6 // indirect - github.com/agnivade/levenshtein v1.0.3 // indirect - github.com/alexflint/go-arg v1.4.2 // indirect - github.com/alexflint/go-scalar v1.0.0 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/dustin/go-humanize v1.0.0 // indirect github.com/google/uuid v1.1.2 // indirect github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 // indirect - github.com/joho/godotenv v1.5.1 // indirect github.com/json-iterator/go v1.1.12 // indirect github.com/jtolds/gls v4.20.0+incompatible // indirect github.com/klauspost/compress v1.13.5 // indirect @@ -35,16 +34,11 @@ require ( github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d // indirect github.com/streadway/amqp v0.0.0-20200108173154-1c71cc93ed71 // indirect github.com/stretchr/objx v0.5.0 // indirect - github.com/stretchr/testify v1.8.4 // indirect github.com/vektah/gqlparser/v2 v2.1.0 // indirect golang.org/x/crypto v0.0.0-20201216223049-8b5274cf687f // indirect - golang.org/x/mod v0.4.2 // indirect golang.org/x/sys v0.0.0-20211019181941-9d821ace8654 // indirect golang.org/x/text v0.3.7 // indirect - golang.org/x/tools v0.1.5 // indirect - golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect gopkg.in/ini.v1 v1.57.0 // indirect - gopkg.in/yaml.v2 v2.4.0 // indirect ) require ( diff --git a/go.sum b/go.sum index 5c845e1..4866c6c 100644 --- a/go.sum +++ b/go.sum @@ -14,11 +14,8 @@ github.com/Microsoft/go-winio v0.5.0/go.mod h1:JPGBdM1cNvN/6ISo+n8V5iA4v8pBzdOpz github.com/Microsoft/hcsshim v0.8.14 h1:lbPVK25c1cu5xTLITwpUcxoA9vKrKErASPYygvouJns= github.com/Microsoft/hcsshim v0.8.14/go.mod h1:NtVKoYxQuTLx6gEq0L96c9Ju4JbRJ4nY2ow3VK6a9Lg= github.com/agnivade/levenshtein v1.0.1/go.mod h1:CURSv5d9Uaml+FovSIICkLbAUZ9S4RqaHDIsdSBg7lM= -github.com/agnivade/levenshtein v1.0.3 h1:M5ZnqLOoZR8ygVq0FfkXsNOKzMCk0xRiow0R5+5VkQ0= github.com/agnivade/levenshtein v1.0.3/go.mod h1:4SFRZbbXWLF4MU1T9Qg0pGgH3Pjs+t6ie5efyrwRJXs= -github.com/alexflint/go-arg v1.4.2 h1:lDWZAXxpAnZUq4qwb86p/3rIJJ2Li81EoMbTMujhVa0= github.com/alexflint/go-arg v1.4.2/go.mod h1:9iRbDxne7LcR/GSvEr7ma++GLpdIU1zrghf2y2768kM= -github.com/alexflint/go-scalar v1.0.0 h1:NGupf1XV/Xb04wXskDFzS0KWOLH632W/EO4fAFi+A70= github.com/alexflint/go-scalar v1.0.0/go.mod h1:GpHzbCOZXEKMEcygYQ5n/aa4Aq84zbxjy3MxYW0gjYw= github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883 h1:bvNMNQO63//z+xNgfBlViaCIJKLlCJ6/fmUseuG0wVQ= github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883/go.mod h1:rCTlJbsFo29Kk6CurOXKm700vrz8f0KW0JNfpkRJY/8= @@ -107,8 +104,10 @@ github.com/klauspost/cpuid v1.3.1 h1:5JNjFYYQrZeKRJ0734q51WCEEn2huer72Dc7K+R/b6s github.com/klauspost/cpuid v1.3.1/go.mod h1:bYW4mA6ZgKPob1/Dlai2LviZJO7KGI3uoWLd42rAQw4= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= +github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/logrusorgru/aurora v0.0.0-20200102142835-e9ef32dff381/go.mod h1:7rIyQOR62GCctdiQpZ/zOJlFyk6y+94wXzv6RNZgaR4= github.com/matryer/moq v0.0.0-20200106131100-75d0ddfc0007/go.mod h1:9ELz6aaclSIGnZBoaSLZ3NAl1VTufbOrXBPvtcy6WiQ= @@ -194,7 +193,6 @@ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXf github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= @@ -224,7 +222,6 @@ golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHl golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/mod v0.4.2 h1:Gz96sIWK3OalVv/I/qNygP42zyoKp3xptRVCWRFEBvo= golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -293,12 +290,10 @@ golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtn golang.org/x/tools v0.0.0-20200114235610-7ae403b6b589/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= -golang.org/x/tools v0.1.5 h1:ouewzE6p+/VEB31YYnTbEJdi8pFqKp4P4n85vwo3DHA= golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= @@ -310,6 +305,7 @@ google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiq google.golang.org/grpc v1.23.1/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/ini.v1 v1.57.0 h1:9unxIsFcTt4I55uWluz+UmL95q4kdJ0buvQ1ZIqVQww= gopkg.in/ini.v1 v1.57.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= @@ -318,11 +314,8 @@ gopkg.in/yaml.v1 v1.0.0-20140924161607-9f9df34309c0/go.mod h1:WDnlLJ4WF5VGsH/HVa gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo= -gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw= diff --git a/internal/handler/imageInspectParserFilter.go b/internal/handler/imageInspectParserFilter.go index ab30b2e..057ca39 100644 --- a/internal/handler/imageInspectParserFilter.go +++ b/internal/handler/imageInspectParserFilter.go @@ -49,7 +49,7 @@ func processImageInspectInsightsData(h *Messaging, insights InsightsData, v stri if err != nil { return nil, "", err } - log.Printf("Successfully decoded image-inspect, for '$s:$s', from '%s'", resource.Project, resource.Environment, source) + log.Printf("Successfully decoded image-inspect, for '%s:%s', from '%s'", resource.Project, resource.Environment, source) facts, err = KeyFactsFilter(facts) if err != nil { diff --git a/internal/handler/registerFilters.go b/internal/handler/registerFilters.go index 3a56c2d..2cc9e98 100644 --- a/internal/handler/registerFilters.go +++ b/internal/handler/registerFilters.go @@ -2,7 +2,11 @@ package handler import ( "encoding/json" + "fmt" + "gopkg.in/yaml.v1" "io/ioutil" + "path/filepath" + "strings" ) var KeyFactFilters []func(filter parserFilter) parserFilter @@ -59,11 +63,22 @@ func LoadTransformsFromDisk(filename string) ([]FactTransform, error) { if err != nil { return ret.Transforms, err } - err = json.Unmarshal(file, &ret) + + ext := strings.ToLower(filepath.Ext(filename)) + + switch ext { + case ".json": + err = json.Unmarshal(file, &ret) + case ".yaml", ".yml": + err = yaml.Unmarshal(file, &ret) + default: + err = fmt.Errorf("Unsupported file type for default transforms: %v", ext) + } if err != nil { return ret.Transforms, err } + return ret.Transforms, nil } @@ -103,7 +118,7 @@ func GenerateFilterFromTransform(transform FactTransform) (func(filter parserFil } -func RegisterFiltersFromJson(filename string) error { +func RegisterFiltersFromDisk(filename string) error { transforms, err := LoadTransformsFromDisk(filename) if err != nil { diff --git a/internal/handler/registerFilters_test.go b/internal/handler/registerFilters_test.go new file mode 100644 index 0000000..2be7704 --- /dev/null +++ b/internal/handler/registerFilters_test.go @@ -0,0 +1,64 @@ +package handler + +import ( + "reflect" + "testing" +) + +func TestLoadTransformsFromDisk(t *testing.T) { + type args struct { + filename string + } + tests := []struct { + name string + args args + want []FactTransform + wantErr bool + }{ + { + name: "test1 - json", + args: args{filename: "testassets/testLoadTransformsFromDisk/test1.json"}, + want: []FactTransform{ + { + Type: "test1", + }, + }, + }, + { + name: "test2 - yaml", + args: args{filename: "testassets/testLoadTransformsFromDisk/test2.yaml"}, + want: []FactTransform{ + { + Type: "test2", + }, + }, + }, + { + name: "test3 - json", + args: args{filename: "testassets/testLoadTransformsFromDisk/test3.yml"}, + want: []FactTransform{ + { + Type: "test3", + }, + }, + }, + { + name: "test4 - unsupported file type", + args: args{filename: "testassets/testLoadTransformsFromDisk/test4.unsp"}, + want: []FactTransform{}, + wantErr: true, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := LoadTransformsFromDisk(tt.args.filename) + if (err != nil) != tt.wantErr { + t.Errorf("LoadTransformsFromDisk() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) && tt.wantErr == false { + t.Errorf("LoadTransformsFromDisk() got = %v, want %v", got, tt.want) + } + }) + } +} diff --git a/internal/handler/testassets/testLoadTransformsFromDisk/test1.json b/internal/handler/testassets/testLoadTransformsFromDisk/test1.json new file mode 100644 index 0000000..f34bd9e --- /dev/null +++ b/internal/handler/testassets/testLoadTransformsFromDisk/test1.json @@ -0,0 +1,7 @@ +{ + "transforms": [ + { + "type": "test1" + } + ] +} \ No newline at end of file diff --git a/internal/handler/testassets/testLoadTransformsFromDisk/test2.yaml b/internal/handler/testassets/testLoadTransformsFromDisk/test2.yaml new file mode 100644 index 0000000..ebf747e --- /dev/null +++ b/internal/handler/testassets/testLoadTransformsFromDisk/test2.yaml @@ -0,0 +1,3 @@ +--- +transforms: + - type: test2 \ No newline at end of file diff --git a/internal/handler/testassets/testLoadTransformsFromDisk/test3.yml b/internal/handler/testassets/testLoadTransformsFromDisk/test3.yml new file mode 100644 index 0000000..7deda89 --- /dev/null +++ b/internal/handler/testassets/testLoadTransformsFromDisk/test3.yml @@ -0,0 +1,3 @@ +--- +transforms: + - type: test3 \ No newline at end of file diff --git a/internal/handler/testassets/testLoadTransformsFromDisk/test4.unsp b/internal/handler/testassets/testLoadTransformsFromDisk/test4.unsp new file mode 100644 index 0000000..d8f1150 --- /dev/null +++ b/internal/handler/testassets/testLoadTransformsFromDisk/test4.unsp @@ -0,0 +1,3 @@ +--- +transforms: + - type: test4 \ No newline at end of file diff --git a/main.go b/main.go index 40de93d..f533f68 100644 --- a/main.go +++ b/main.go @@ -65,7 +65,7 @@ func main() { flag.StringVar(&s3Bucket, "s3-bucket", "lagoon-insights", "The s3 bucket name.") flag.StringVar(&s3Region, "s3-region", "", "The s3 region.") flag.BoolVar(&s3useSSL, "s3-usessl", true, "Use SSL with S3") - flag.StringVar(&filterTransformerFile, "filter-transformer-file", "./default_filter_transformers.json", "The filter/transformers to load.") + flag.StringVar(&filterTransformerFile, "filter-transformer-file", "./default_filter_transformers.yaml", "The filter/transformers to load.") flag.BoolVar(&disableS3Upload, "disable-s3-upload", false, "Disable uploading insights data to an s3 s3Bucket") flag.BoolVar(&disableAPIIntegration, "disable-api-integration", false, "Disable insights data integration for the Lagoon API") flag.BoolVar(&enableDebug, "debug", false, "Enable debugging output") @@ -122,7 +122,7 @@ func main() { } log.Println("Registering Fact Filters/Transformer") - err := handler.RegisterFiltersFromJson(filterTransformerFile) + err := handler.RegisterFiltersFromDisk(filterTransformerFile) if err != nil { log.Println(err) } From a3337f8335c4c345da30a7b4eaaa40d956cc3112 Mon Sep 17 00:00:00 2001 From: Blaize M Kaye Date: Mon, 18 Sep 2023 08:53:28 +1200 Subject: [PATCH 2/2] Updates dockerfile to use yaml --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 3df5c88..90035d9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -23,7 +23,7 @@ FROM alpine:3.15 WORKDIR / COPY --from=builder /go/src/github.com/uselagoon/lagoon/services/insights-handler/insights-handler . -COPY default_filter_transformers.json /default_filter_transformers.json +COPY default_filter_transformers.yaml /default_filter_transformers.yaml USER 65532:65532 ENTRYPOINT ["/insights-handler"] \ No newline at end of file