From b05419be9d734b2388a2460ca5e7d9c9176f6481 Mon Sep 17 00:00:00 2001 From: Femi Novia Lina <77434812+FemiNoviaLina@users.noreply.github.com> Date: Tue, 4 Jun 2024 15:48:19 +0700 Subject: [PATCH] feat: make public api prefix configurable (#63) * feat: make public api prefix configurable * fix: default public api prefix --- internal/server/config.go | 2 ++ internal/server/server.go | 2 +- test/e2e_test/testbench/testbench.go | 1 + test/e2e_test/testbench/testdata/configs/rules/rule.yaml | 2 +- 4 files changed, 5 insertions(+), 2 deletions(-) diff --git a/internal/server/config.go b/internal/server/config.go index 710f4928f..98b573072 100644 --- a/internal/server/config.go +++ b/internal/server/config.go @@ -65,4 +65,6 @@ type Config struct { DefaultSystemEmail string `yaml:"default_system_email" mapstructure:"default_system_email" default:"shield-service@gotocompany.com"` ServiceData ServiceDataConfig `yaml:"service_data" mapstructure:"service_data"` + + PublicAPIPrefix string `yaml:"public_api_prefix" mapstructure:"public_api_prefix" default:"/api"` } diff --git a/internal/server/server.go b/internal/server/server.go index 4efb5f0b2..417fbe836 100644 --- a/internal/server/server.go +++ b/internal/server/server.go @@ -71,7 +71,7 @@ func Serve( runtime.WithIncomingHeaderMatcher(customHeaderMatcherFunc(map[string]bool{cfg.IdentityProxyHeader: true})), ) - httpMux.Handle("/shield/", http.StripPrefix("/shield", grpcServiceDataGateway)) + httpMux.Handle(fmt.Sprintf("%s/", cfg.PublicAPIPrefix), http.StripPrefix(cfg.PublicAPIPrefix, grpcServiceDataGateway)) if err := shieldv1beta1.RegisterServiceDataServiceHandler(ctx, grpcServiceDataGateway, grpcConn); err != nil { return err diff --git a/test/e2e_test/testbench/testbench.go b/test/e2e_test/testbench/testbench.go index 14e26ec40..91f8fe5f9 100644 --- a/test/e2e_test/testbench/testbench.go +++ b/test/e2e_test/testbench/testbench.go @@ -207,6 +207,7 @@ func SetupTests(t *testing.T) (shieldv1beta1.ShieldServiceClient, shieldv1beta1. BootstrapEnabled: true, MaxNumUpsertData: 1, }, + PublicAPIPrefix: "/api", }, Proxy: proxy.ServicesConfig{ Services: []proxy.Config{ diff --git a/test/e2e_test/testbench/testdata/configs/rules/rule.yaml b/test/e2e_test/testbench/testdata/configs/rules/rule.yaml index 68141f421..1b52463db 100644 --- a/test/e2e_test/testbench/testdata/configs/rules/rule.yaml +++ b/test/e2e_test/testbench/testdata/configs/rules/rule.yaml @@ -1,7 +1,7 @@ rules: - backends: - name: entropy - target: "http://localhost:52118" + target: "http://localhost:51463" frontends: - name: ping path: "/api/ping"