Skip to content

Commit

Permalink
Change Zipkin CORS origins and headers to comma separated list (#1556)
Browse files Browse the repository at this point in the history
Signed-off-by: Jonas Verhofsté <25819942+JonasVerhofste@users.noreply.github.com>
  • Loading branch information
JonasVerhofste authored and yurishkuro committed Aug 15, 2019
1 parent 75b670f commit 581f9be
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
4 changes: 2 additions & 2 deletions cmd/collector/app/builder/builder_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ func AddFlags(flags *flag.FlagSet) {
flags.String(collectorGRPCCert, "", "Path to TLS certificate for the gRPC collector TLS service")
flags.String(collectorGRPCKey, "", "Path to TLS key for the gRPC collector TLS cert")
flags.String(collectorGRPCClientCA, "", "Path to a TLS CA to verify certificates presented by clients (if unset, all clients are permitted)")
flags.String(collectorZipkinAllowedOrigins, "*", "Allowed origins for the Zipkin collector service, default accepts all")
flags.String(collectorZipkinAllowedHeaders, "content-type", "Allowed headers for the Zipkin collector service, default content-type")
flags.String(collectorZipkinAllowedOrigins, "*", "Comma separated list of allowed origins for the Zipkin collector service, default accepts all")
flags.String(collectorZipkinAllowedHeaders, "content-type", "Comma separated list of allowed headers for the Zipkin collector service, default content-type")
}

// InitFromViper initializes CollectorOptions with properties from viper
Expand Down
8 changes: 6 additions & 2 deletions cmd/collector/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"net/http"
"os"
"strconv"
"strings"

"github.com/gorilla/mux"
"github.com/rs/cors"
Expand Down Expand Up @@ -227,10 +228,13 @@ func startZipkinHTTPAPI(
r := mux.NewRouter()
zHandler.RegisterRoutes(r)

origins := strings.Split(strings.Replace(allowedOrigins, " ", "", -1), ",")
headers := strings.Split(strings.Replace(allowedHeaders, " ", "", -1), ",")

c := cors.New(cors.Options{
AllowedOrigins: []string{allowedOrigins},
AllowedOrigins: origins,
AllowedMethods: []string{"POST"}, // Allowing only POST, because that's the only handled one
AllowedHeaders: []string{allowedHeaders},
AllowedHeaders: headers,
})

httpPortStr := ":" + strconv.Itoa(zipkinPort)
Expand Down

0 comments on commit 581f9be

Please sign in to comment.