diff --git a/go.mod b/go.mod index 91ab0603..9df0749a 100644 --- a/go.mod +++ b/go.mod @@ -2,8 +2,6 @@ module github.com/aserto-dev/topaz go 1.23.3 -replace github.com/aserto-dev/service-host => ./internal/pkg/service/builder - replace github.com/adrg/xdg => ./internal/pkg/xdg require ( @@ -27,16 +25,18 @@ require ( github.com/aserto-dev/openapi-directory v0.31.2 github.com/aserto-dev/runtime v0.69.1 github.com/aserto-dev/self-decision-logger v0.0.8 - github.com/aserto-dev/service-host v0.0.0-00010101000000-000000000000 github.com/cli/browser v1.3.0 github.com/docker/docker v27.1.1+incompatible github.com/docker/go-connections v0.5.0 github.com/fatih/color v1.18.0 github.com/fullstorydev/grpcurl v1.9.1 github.com/gdamore/tcell/v2 v2.7.4 + github.com/go-http-utils/headers v0.0.0-20181008091004-fed159eddc2a github.com/google/uuid v1.6.0 github.com/google/wire v0.6.0 github.com/grpc-ecosystem/go-grpc-middleware v1.4.0 + github.com/grpc-ecosystem/go-grpc-middleware/providers/prometheus v1.0.1 + github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 github.com/grpc-ecosystem/grpc-gateway/v2 v2.23.0 github.com/itchyny/gojq v0.12.16 github.com/lestrrat-go/jwx/v2 v2.1.2 @@ -50,9 +50,12 @@ require ( github.com/open-policy-agent/opa v0.69.0 github.com/opencontainers/image-spec v1.1.0 github.com/pkg/errors v0.9.1 + github.com/prometheus/client_golang v1.20.5 github.com/rivo/tview v0.0.0-20241103174730-c76f7879f592 + github.com/rs/cors v1.11.1 github.com/rs/zerolog v1.33.0 github.com/samber/lo v1.47.0 + github.com/slok/go-http-metrics v0.13.0 github.com/spf13/cobra v1.8.1 github.com/spf13/viper v1.19.0 github.com/stretchr/testify v1.9.0 @@ -98,7 +101,6 @@ require ( github.com/felixge/httpsnoop v1.0.4 // indirect github.com/fsnotify/fsnotify v1.7.0 // indirect github.com/gdamore/encoding v1.0.1 // indirect - github.com/go-http-utils/headers v0.0.0-20181008091004-fed159eddc2a // indirect github.com/go-ini/ini v1.67.0 // indirect github.com/go-logr/logr v1.4.2 // indirect github.com/go-logr/stdr v1.2.2 // indirect @@ -110,9 +112,7 @@ require ( github.com/google/cel-go v0.21.0 // indirect github.com/google/subcommands v1.2.0 // indirect github.com/gorilla/mux v1.8.1 // indirect - github.com/grpc-ecosystem/go-grpc-middleware/providers/prometheus v1.0.1 // indirect github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.1.0 // indirect - github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 // indirect github.com/hashicorp/errwrap v1.1.0 // indirect github.com/hashicorp/go-multierror v1.1.1 // indirect github.com/hashicorp/hcl v1.0.0 // indirect @@ -153,20 +153,17 @@ require ( github.com/planetscale/vtprotobuf v0.6.1-0.20240319094008-0393e58bdf10 // indirect github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect - github.com/prometheus/client_golang v1.20.5 // indirect github.com/prometheus/client_model v0.6.1 // indirect github.com/prometheus/common v0.60.1 // indirect github.com/prometheus/procfs v0.15.1 // indirect github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect github.com/rivo/uniseg v0.4.7 // indirect - github.com/rs/cors v1.11.1 // indirect github.com/sagikazarmark/locafero v0.4.0 // indirect github.com/sagikazarmark/slog-shim v0.1.0 // indirect github.com/segmentio/asm v1.2.0 // indirect github.com/shirou/gopsutil/v3 v3.23.12 // indirect github.com/shoenig/go-m1cpu v0.1.6 // indirect github.com/sirupsen/logrus v1.9.3 // indirect - github.com/slok/go-http-metrics v0.13.0 // indirect github.com/sourcegraph/conc v0.3.0 // indirect github.com/spf13/afero v1.11.0 // indirect github.com/spf13/cast v1.6.0 // indirect diff --git a/go.work b/go.work index 40b3e113..54aa0bcf 100644 --- a/go.work +++ b/go.work @@ -2,6 +2,5 @@ go 1.23.3 use ( . - ./internal/pkg/service/builder ./internal/pkg/xdg ) diff --git a/internal/pkg/service/builder/go.mod b/internal/pkg/service/builder/go.mod deleted file mode 100644 index 68e5e75c..00000000 --- a/internal/pkg/service/builder/go.mod +++ /dev/null @@ -1,46 +0,0 @@ -module github.com/aserto-dev/service-host - -go 1.23 - -toolchain go1.23.2 - -require ( - github.com/aserto-dev/go-aserto v0.33.1 - github.com/go-http-utils/headers v0.0.0-20181008091004-fed159eddc2a - github.com/grpc-ecosystem/go-grpc-middleware/providers/prometheus v1.0.1 - github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 - github.com/grpc-ecosystem/grpc-gateway/v2 v2.23.0 - github.com/pkg/errors v0.9.1 - github.com/prometheus/client_golang v1.20.5 - github.com/rs/cors v1.11.1 - github.com/rs/zerolog v1.33.0 - github.com/slok/go-http-metrics v0.13.0 - golang.org/x/sync v0.9.0 - google.golang.org/grpc v1.67.1 - google.golang.org/protobuf v1.35.1 -) - -require ( - github.com/aserto-dev/header v0.0.8 // indirect - github.com/beorn7/perks v1.0.1 // indirect - github.com/cespare/xxhash/v2 v2.3.0 // indirect - github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect - github.com/google/uuid v1.6.0 // indirect - github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.1.0 // indirect - github.com/hashicorp/errwrap v1.0.0 // indirect - github.com/hashicorp/go-multierror v1.1.1 // indirect - github.com/klauspost/compress v1.17.11 // indirect - github.com/mattn/go-colorable v0.1.13 // indirect - github.com/mattn/go-isatty v0.0.20 // indirect - github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect - github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect - github.com/prometheus/client_model v0.6.1 // indirect - github.com/prometheus/common v0.60.1 // indirect - github.com/prometheus/procfs v0.15.1 // indirect - github.com/samber/lo v1.47.0 // indirect - golang.org/x/net v0.31.0 // indirect - golang.org/x/sys v0.27.0 // indirect - golang.org/x/text v0.20.0 // indirect - google.golang.org/genproto/googleapis/api v0.0.0-20241104194629-dd2ea8efbc28 // indirect - google.golang.org/genproto/googleapis/rpc v0.0.0-20241104194629-dd2ea8efbc28 // indirect -) diff --git a/internal/pkg/service/builder/go.sum b/internal/pkg/service/builder/go.sum deleted file mode 100644 index 6a12b235..00000000 --- a/internal/pkg/service/builder/go.sum +++ /dev/null @@ -1,90 +0,0 @@ -github.com/aserto-dev/go-aserto v0.33.1 h1:oFTlatM7+mq2grD/ut+ff0v7CjCV6YenKd6XWJbonbE= -github.com/aserto-dev/go-aserto v0.33.1/go.mod h1:t2qs6Q7pXlMkKh5MhbssKDbGb62f36Q6Bj3QDXww31s= -github.com/aserto-dev/header v0.0.8 h1:T052WblWFZ/5Mg3MphHylE3sZobdIQpdj5cP3sPMhL8= -github.com/aserto-dev/header v0.0.8/go.mod h1:wmWm+omABTWf6QRRmw9yOdvgTstk/vYDqIA1duR8Pus= -github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= -github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= -github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs= -github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= -github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= -github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM= -github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/go-http-utils/headers v0.0.0-20181008091004-fed159eddc2a h1:v6zMvHuY9yue4+QkG/HQ/W67wvtQmWJ4SDo9aK/GIno= -github.com/go-http-utils/headers v0.0.0-20181008091004-fed159eddc2a/go.mod h1:I79BieaU4fxrw4LMXby6q5OS9XnoR9UIKLOzDFjUmuw= -github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= -github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek= -github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps= -github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= -github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= -github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= -github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/grpc-ecosystem/go-grpc-middleware/providers/prometheus v1.0.1 h1:qnpSQwGEnkcRpTqNOIR6bJbR0gAorgP9CSALpRcKoAA= -github.com/grpc-ecosystem/go-grpc-middleware/providers/prometheus v1.0.1/go.mod h1:lXGCsh6c22WGtjr+qGHj1otzZpV/1kwTMAqkwZsnWRU= -github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.1.0 h1:pRhl55Yx1eC7BZ1N+BBWwnKaMyD8uC+34TLdndZMAKk= -github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.1.0/go.mod h1:XKMd7iuf/RGPSMJ/U4HP0zS2Z9Fh8Ps9a+6X26m/tmI= -github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 h1:Ovs26xHkKqVztRpIrF/92BcuyuQ/YW4NSIpoGtfXNho= -github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk= -github.com/grpc-ecosystem/grpc-gateway/v2 v2.23.0 h1:ad0vkEBuk23VJzZR9nkLVG0YAoN9coASF1GusYX6AlU= -github.com/grpc-ecosystem/grpc-gateway/v2 v2.23.0/go.mod h1:igFoXX2ELCW06bol23DWPB5BEWfZISOzSP5K2sbLea0= -github.com/hashicorp/errwrap v1.0.0 h1:hLrqtEDnRye3+sgx6z4qVLNuviH3MR5aQ0ykNJa/UYA= -github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= -github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo= -github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM= -github.com/klauspost/compress v1.17.11 h1:In6xLpyWOi1+C7tXUUWv2ot1QvBjxevKAaI6IXrJmUc= -github.com/klauspost/compress v1.17.11/go.mod h1:pMDklpSncoRMuLFrf1W9Ss9KT+0rH90U12bZKk7uwG0= -github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc= -github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= -github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= -github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= -github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= -github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= -github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= -github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= -github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA= -github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ= -github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= -github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= -github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U= -github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/prometheus/client_golang v1.20.5 h1:cxppBPuYhUnsO6yo/aoRol4L7q7UFfdm+bR9r+8l63Y= -github.com/prometheus/client_golang v1.20.5/go.mod h1:PIEt8X02hGcP8JWbeHyeZ53Y/jReSnHgO035n//V5WE= -github.com/prometheus/client_model v0.6.1 h1:ZKSh/rekM+n3CeS952MLRAdFwIKqeY8b62p8ais2e9E= -github.com/prometheus/client_model v0.6.1/go.mod h1:OrxVMOVHjw3lKMa8+x6HeMGkHMQyHDk9E3jmP2AmGiY= -github.com/prometheus/common v0.60.1 h1:FUas6GcOw66yB/73KC+BOZoFJmbo/1pojoILArPAaSc= -github.com/prometheus/common v0.60.1/go.mod h1:h0LYf1R1deLSKtD4Vdg8gy4RuOvENW2J/h19V5NADQw= -github.com/prometheus/procfs v0.15.1 h1:YagwOFzUgYfKKHX6Dr+sHT7km/hxC76UB0learggepc= -github.com/prometheus/procfs v0.15.1/go.mod h1:fB45yRUv8NstnjriLhBQLuOUt+WW4BsoGhij/e3PBqk= -github.com/rs/cors v1.11.1 h1:eU3gRzXLRK57F5rKMGMZURNdIG4EoAmX8k94r9wXWHA= -github.com/rs/cors v1.11.1/go.mod h1:XyqrcTp5zjWr1wsJ8PIRZssZ8b/WMcMf71DJnit4EMU= -github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg= -github.com/rs/zerolog v1.33.0 h1:1cU2KZkvPxNyfgEmhHAz/1A9Bz+llsdYzklWFzgp0r8= -github.com/rs/zerolog v1.33.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss= -github.com/samber/lo v1.47.0 h1:z7RynLwP5nbyRscyvcD043DWYoOcYRv3mV8lBeqOCLc= -github.com/samber/lo v1.47.0/go.mod h1:RmDH9Ct32Qy3gduHQuKJ3gW1fMHAnE/fAzQuf6He5cU= -github.com/slok/go-http-metrics v0.13.0 h1:lQDyJJx9wKhmbliyUsZ2l6peGnXRHjsjoqPt5VYzcP8= -github.com/slok/go-http-metrics v0.13.0/go.mod h1:HIr7t/HbN2sJaunvnt9wKP9xoBBVZFo1/KiHU3b0w+4= -github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY= -github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= -github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= -github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= -golang.org/x/net v0.31.0 h1:68CPQngjLL0r2AlUKiSxtQFKvzRVbnzLwMUn5SzcLHo= -golang.org/x/net v0.31.0/go.mod h1:P4fl1q7dY2hnZFxEk4pPSkDHF+QqjitcnDjUQyMM+pM= -golang.org/x/sync v0.9.0 h1:fEo0HyrW1GIgZdpbhCRO0PkJajUS5H9IFUztCgEo2jQ= -golang.org/x/sync v0.9.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= -golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.27.0 h1:wBqf8DvsY9Y/2P8gAfPDEYNuS30J4lPHJxXSb/nJZ+s= -golang.org/x/sys v0.27.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/text v0.20.0 h1:gK/Kv2otX8gz+wn7Rmb3vT96ZwuoxnQlY+HlJVj7Qug= -golang.org/x/text v0.20.0/go.mod h1:D4IsuqiFMhST5bX19pQ9ikHC2GsaKyk/oF+pn3ducp4= -google.golang.org/genproto/googleapis/api v0.0.0-20241104194629-dd2ea8efbc28 h1:M0KvPgPmDZHPlbRbaNU1APr28TvwvvdUPlSv7PUvy8g= -google.golang.org/genproto/googleapis/api v0.0.0-20241104194629-dd2ea8efbc28/go.mod h1:dguCy7UOdZhTvLzDyt15+rOrawrpM4q7DD9dQ1P11P4= -google.golang.org/genproto/googleapis/rpc v0.0.0-20241104194629-dd2ea8efbc28 h1:XVhgTWWV3kGQlwJHR3upFWZeTsei6Oks1apkZSeonIE= -google.golang.org/genproto/googleapis/rpc v0.0.0-20241104194629-dd2ea8efbc28/go.mod h1:GX3210XPVPUjJbTUbvwI8f2IpZDMZuPJWDzDuebbviI= -google.golang.org/grpc v1.67.1 h1:zWnc1Vrcno+lHZCOofnIMvycFcc0QRGIzm9dhnDX68E= -google.golang.org/grpc v1.67.1/go.mod h1:1gLDyUQU7CTLJI90u3nXZ9ekeghjeM7pTDZlqFNg2AA= -google.golang.org/protobuf v1.35.1 h1:m3LfL6/Ca+fqnjnlqQXNpFPABW1UD7mjh8KO2mKFytA= -google.golang.org/protobuf v1.35.1/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE= -gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= -gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/internal/pkg/service/builder/service.go b/internal/pkg/service/builder/service.go index 3beabe80..f749486d 100644 --- a/internal/pkg/service/builder/service.go +++ b/internal/pkg/service/builder/service.go @@ -21,7 +21,7 @@ type GRPCRegistrations func(server *grpc.Server) type HandlerRegistrations func(ctx context.Context, mux *runtime.ServeMux, grpcEndpoint string, opts []grpc.DialOption) error -type Server struct { +type Service struct { Config *API Server *grpc.Server Listener net.Listener diff --git a/internal/pkg/service/builder/service_factory.go b/internal/pkg/service/builder/service_factory.go index 594389e3..e0c44d80 100644 --- a/internal/pkg/service/builder/service_factory.go +++ b/internal/pkg/service/builder/service_factory.go @@ -8,6 +8,7 @@ import ( "strconv" "github.com/aserto-dev/go-aserto" + "github.com/samber/lo" "github.com/grpc-ecosystem/grpc-gateway/v2/runtime" "github.com/pkg/errors" @@ -56,7 +57,7 @@ func (f *ServiceFactory) CreateService( grpcOpts *GRPCOptions, gatewayOpts *GatewayOptions, cleanup ...func(), -) (*Server, error) { +) (*Service, error) { grpcServer, err := prepareGrpcServer(&config.GRPC.Certs, grpcOpts.ServerOptions) if err != nil { return nil, err @@ -77,7 +78,7 @@ func (f *ServiceFactory) CreateService( } } - return &Server{ + return &Service{ Config: config, Server: grpcServer, Listener: listener, @@ -109,7 +110,7 @@ func (f *ServiceFactory) prepareGateway(config *API, gatewayOpts *GatewayOptions runtimeMux := f.gatewayMux(config.Gateway.AllowedHeaders, gatewayOpts.ErrorHandler) opts := []grpc.DialOption{} - if TLS(&config.GRPC.Certs) { + if config.GRPC.Certs.HasCert() { tlsCreds, err := config.GRPC.Certs.ClientCredentials(true) if err != nil { return Gateway{}, errors.Wrapf(err, "failed to get TLS credentials") @@ -141,9 +142,7 @@ func (f *ServiceFactory) prepareGateway(config *API, gatewayOpts *GatewayOptions IdleTimeout: config.Gateway.IdleTimeout, } - if NoTLS(&config.Gateway.Certs) { - config.Gateway.HTTP = true - } + config.Gateway.HTTP = !config.Gateway.Certs.HasCert() if !config.Gateway.HTTP { tlsServerConfig, err := config.Gateway.Certs.ServerConfig() @@ -161,7 +160,7 @@ func (f *ServiceFactory) prepareGateway(config *API, gatewayOpts *GatewayOptions func (f *ServiceFactory) gatewayMux(allowedHeaders []string, errorHandler runtime.ErrorHandlerFunc) *runtime.ServeMux { opts := []runtime.ServeMuxOption{ runtime.WithIncomingHeaderMatcher(func(key string) (string, bool) { - if contains(allowedHeaders, key) { + if lo.Contains(allowedHeaders, key) { return key, true } return runtime.DefaultHeaderMatcher(key) @@ -236,7 +235,7 @@ func httpResponseModifier(ctx context.Context, w http.ResponseWriter, p proto.Me // prepareGrpcServer provides a new grpc server with the provided grpc.ServerOptions using the provided certificates. func prepareGrpcServer(certCfg *aserto.TLSConfig, opts []grpc.ServerOption) (*grpc.Server, error) { // NoTLS path. - if NoTLS(certCfg) { + if !certCfg.HasCert() { opts = append(opts, grpc.Creds(insecure.NewCredentials())) return grpc.NewServer(opts...), nil } @@ -266,15 +265,6 @@ func fieldsMaskHandler(h http.Handler) http.Handler { }) } -func contains[T comparable](slice []T, item T) bool { - for i := range slice { - if slice[i] == item { - return true - } - } - return false -} - type key int var pathPatternKey key diff --git a/internal/pkg/service/builder/service_manager.go b/internal/pkg/service/builder/service_manager.go index 94e58c6a..9bdece1e 100644 --- a/internal/pkg/service/builder/service_manager.go +++ b/internal/pkg/service/builder/service_manager.go @@ -24,7 +24,7 @@ type ServiceManager struct { logger *zerolog.Logger errGroup *errgroup.Group - Servers map[string]*Server + Servers map[string]*Service DependencyMap map[string][]string HealthServer *Health MetricServer *http.Server @@ -42,7 +42,7 @@ func NewServiceManager(logger *zerolog.Logger) *ServiceManager { return &ServiceManager{ Context: ctx, logger: &serviceLogger, - Servers: make(map[string]*Server), + Servers: make(map[string]*Service), DependencyMap: make(map[string][]string), errGroup: errGroup, shutdownTimeout: 30, @@ -54,7 +54,7 @@ func (s *ServiceManager) WithShutdownTimeout(seconds int) *ServiceManager { return s } -func (s *ServiceManager) AddGRPCServer(server *Server) error { +func (s *ServiceManager) AddGRPCServer(server *Service) error { s.Servers[server.Config.GRPC.ListenAddress] = server return nil } @@ -105,7 +105,7 @@ func (s *ServiceManager) SetupMetricsServer(address string, certCfg *aserto.TLSC s.logger.Info().Msgf("Starting %s metric server", address) - if NoTLS(certCfg) { + if !certCfg.HasCert() { s.errGroup.Go(metric.ListenAndServe) } else { s.errGroup.Go(func() error { @@ -163,14 +163,13 @@ func (s *ServiceManager) StartServers(ctx context.Context) error { if httpServer.Server != nil { s.errGroup.Go(func() error { s.logger.Info().Msgf("Starting %s gateway server", httpServer.Server.Addr) - if NoTLS(httpServer.Certs) { - err := httpServer.Server.ListenAndServe() + if httpServer.Certs.HasCert() { + err := httpServer.Server.ListenAndServeTLS(httpServer.Certs.Cert, httpServer.Certs.Key) if err != nil { return err } - } - if TLS(httpServer.Certs) { - err := httpServer.Server.ListenAndServeTLS(httpServer.Certs.Cert, httpServer.Certs.Key) + } else { + err := httpServer.Server.ListenAndServe() if err != nil { return err } @@ -190,7 +189,7 @@ func (s *ServiceManager) logDetails(address string, element interface{}) { ref := reflect.ValueOf(element).Elem() typeOfT := ref.Type() - for i := 0; i < ref.NumField(); i++ { + for i := range ref.NumField() { f := ref.Field(i) s.logger.Debug().Str("address", address).Msgf("%s = %v\n", typeOfT.Field(i).Name, f.Interface()) } diff --git a/internal/pkg/service/builder/tls.go b/internal/pkg/service/builder/tls.go deleted file mode 100644 index bab95780..00000000 --- a/internal/pkg/service/builder/tls.go +++ /dev/null @@ -1,11 +0,0 @@ -package builder - -import "github.com/aserto-dev/go-aserto" - -func NoTLS(cfg *aserto.TLSConfig) bool { - return (cfg == nil || cfg.CA == "" || cfg.Key == "" || cfg.Cert == "") -} - -func TLS(cfg *aserto.TLSConfig) bool { - return !NoTLS(cfg) -} diff --git a/pkg/app/authorizer.go b/pkg/app/authorizer.go index 7c19c4d0..3a38fb7f 100644 --- a/pkg/app/authorizer.go +++ b/pkg/app/authorizer.go @@ -7,7 +7,7 @@ import ( authz "github.com/aserto-dev/go-authorizer/aserto/authorizer/v2" azOpenAPI "github.com/aserto-dev/openapi-authorizer/publish/authorizer" - builder "github.com/aserto-dev/service-host" + builder "github.com/aserto-dev/topaz/internal/pkg/service/builder" "github.com/aserto-dev/topaz/pkg/app/impl" "github.com/aserto-dev/topaz/pkg/cc/config" "github.com/aserto-dev/topaz/pkg/rapidoc" @@ -32,7 +32,7 @@ const ( ) func NewAuthorizer(ctx context.Context, cfg *builder.API, commonConfig *config.Common, authorizerOpts []grpc.ServerOption, logger *zerolog.Logger) (ServiceTypes, error) { - if builder.TLS(&cfg.GRPC.Certs) { + if cfg.GRPC.Certs.HasCert() { tlsCreds, err := cfg.GRPC.Certs.ServerCredentials() if err != nil { return nil, errors.Wrap(err, "failed to calculate tls config") diff --git a/pkg/app/console.go b/pkg/app/console.go index 760d062b..cf46b05c 100644 --- a/pkg/app/console.go +++ b/pkg/app/console.go @@ -6,7 +6,7 @@ import ( "net/http" "strings" - builder "github.com/aserto-dev/service-host" + builder "github.com/aserto-dev/topaz/internal/pkg/service/builder" "github.com/aserto-dev/topaz/pkg/app/handlers" "github.com/aserto-dev/topaz/pkg/cc/config" "github.com/grpc-ecosystem/grpc-gateway/v2/runtime" @@ -111,9 +111,7 @@ func getGatewayAddress(serviceConfig *builder.API) string { } addr := serviceAddress(serviceConfig.Gateway.ListenAddress) - if builder.NoTLS(&serviceConfig.Gateway.Certs) { - serviceConfig.Gateway.HTTP = true - } + serviceConfig.Gateway.HTTP = !serviceConfig.Gateway.Certs.HasCert() if serviceConfig.Gateway.HTTP { return fmt.Sprintf("http://%s", addr) diff --git a/pkg/app/edgedir.go b/pkg/app/edgedir.go index 6aef7c6e..7110862b 100644 --- a/pkg/app/edgedir.go +++ b/pkg/app/edgedir.go @@ -13,7 +13,7 @@ import ( dsm3stream "github.com/aserto-dev/go-directory/pkg/gateway/model/v3" "github.com/aserto-dev/go-edge-ds/pkg/directory" dsOpenAPI "github.com/aserto-dev/openapi-directory/publish/directory" - builder "github.com/aserto-dev/service-host" + builder "github.com/aserto-dev/topaz/internal/pkg/service/builder" "github.com/aserto-dev/topaz/pkg/rapidoc" "github.com/grpc-ecosystem/grpc-gateway/v2/runtime" diff --git a/pkg/app/topaz.go b/pkg/app/topaz.go index 0b7d3a42..cb67c1e8 100644 --- a/pkg/app/topaz.go +++ b/pkg/app/topaz.go @@ -10,10 +10,10 @@ import ( eds "github.com/aserto-dev/go-edge-ds" console "github.com/aserto-dev/go-topaz-ui" "github.com/aserto-dev/self-decision-logger/logger/self" - builder "github.com/aserto-dev/service-host" decisionlog "github.com/aserto-dev/topaz/decision_log" "github.com/aserto-dev/topaz/decision_log/logger/file" "github.com/aserto-dev/topaz/decision_log/logger/nop" + builder "github.com/aserto-dev/topaz/internal/pkg/service/builder" "github.com/aserto-dev/topaz/pkg/app/auth" "github.com/aserto-dev/topaz/pkg/app/handlers" "github.com/aserto-dev/topaz/pkg/app/middlewares" diff --git a/pkg/app/topaz/wire.go b/pkg/app/topaz/wire.go index 9781f60a..4d8aa6c4 100644 --- a/pkg/app/topaz/wire.go +++ b/pkg/app/topaz/wire.go @@ -8,7 +8,7 @@ import ( "google.golang.org/grpc" "github.com/aserto-dev/logger" - builder "github.com/aserto-dev/service-host" + builder "github.com/aserto-dev/topaz/internal/pkg/service/builder" "github.com/aserto-dev/topaz/pkg/app" "github.com/aserto-dev/topaz/pkg/cc" "github.com/aserto-dev/topaz/pkg/cc/config" diff --git a/pkg/app/topaz/wire_gen.go b/pkg/app/topaz/wire_gen.go index 35dc0901..fc4e5b8a 100644 --- a/pkg/app/topaz/wire_gen.go +++ b/pkg/app/topaz/wire_gen.go @@ -8,7 +8,7 @@ package topaz import ( "github.com/aserto-dev/logger" - "github.com/aserto-dev/service-host" + "github.com/aserto-dev/topaz/internal/pkg/service/builder" "github.com/aserto-dev/topaz/pkg/app" "github.com/aserto-dev/topaz/pkg/cc" "github.com/aserto-dev/topaz/pkg/cc/config" diff --git a/pkg/cc/config/config.go b/pkg/cc/config/config.go index 25d0aa11..1e10775e 100644 --- a/pkg/cc/config/config.go +++ b/pkg/cc/config/config.go @@ -10,7 +10,7 @@ import ( "github.com/aserto-dev/go-edge-ds/pkg/directory" "github.com/aserto-dev/logger" "github.com/aserto-dev/runtime" - builder "github.com/aserto-dev/service-host" + builder "github.com/aserto-dev/topaz/internal/pkg/service/builder" "github.com/aserto-dev/topaz/pkg/debug" "github.com/pkg/errors" "github.com/rs/zerolog" @@ -200,7 +200,7 @@ func (c *Config) setupCerts(log *zerolog.Logger, certsGenerator *certs.Generator } if len(existingFiles) == 0 { - if builder.TLS(&config.GRPC.Certs) { + if config.GRPC.Certs.HasCert() && config.GRPC.Certs.HasCA() { err := certsGenerator.MakeDevCert(&certs.CertGenConfig{ CommonName: fmt.Sprintf("%s-grpc", commonName), CertKeyPath: config.GRPC.Certs.Key, @@ -213,7 +213,7 @@ func (c *Config) setupCerts(log *zerolog.Logger, certsGenerator *certs.Generator log.Info().Str("service", serviceName).Msg("gRPC certs configured") } - if builder.TLS(&config.Gateway.Certs) { + if config.Gateway.Certs.HasCert() && config.Gateway.Certs.HasCA() { err := certsGenerator.MakeDevCert(&certs.CertGenConfig{ CommonName: fmt.Sprintf("%s-gateway", commonName), CertKeyPath: config.Gateway.Certs.Key, diff --git a/pkg/cc/config/helper.go b/pkg/cc/config/helper.go index 2a74f62b..6f461242 100644 --- a/pkg/cc/config/helper.go +++ b/pkg/cc/config/helper.go @@ -1,7 +1,7 @@ package config import ( - builder "github.com/aserto-dev/service-host" + builder "github.com/aserto-dev/topaz/internal/pkg/service/builder" "github.com/samber/lo" ) diff --git a/pkg/cc/config/loader.go b/pkg/cc/config/loader.go index 7cf0edc7..5aea3084 100644 --- a/pkg/cc/config/loader.go +++ b/pkg/cc/config/loader.go @@ -9,7 +9,7 @@ import ( "strings" "github.com/aserto-dev/self-decision-logger/logger/self" - builder "github.com/aserto-dev/service-host" + builder "github.com/aserto-dev/topaz/internal/pkg/service/builder" "github.com/aserto-dev/topaz/pkg/cli/cc" "github.com/mitchellh/mapstructure" "github.com/spf13/viper"