diff --git a/src/frontend/handlers.go b/src/frontend/handlers.go index c396aa9..e3ba902 100644 --- a/src/frontend/handlers.go +++ b/src/frontend/handlers.go @@ -24,12 +24,11 @@ import ( "strconv" "time" + pb "github.com/GoogleCloudPlatform/microservices-demo/src/frontend/genproto" + "github.com/GoogleCloudPlatform/microservices-demo/src/frontend/money" "github.com/gorilla/mux" "github.com/pkg/errors" "github.com/sirupsen/logrus" - - pb "github.com/GoogleCloudPlatform/microservices-demo/src/frontend/genproto" - "github.com/GoogleCloudPlatform/microservices-demo/src/frontend/money" ) var ( @@ -353,6 +352,8 @@ func (fe *frontendServer) setCurrencyHandler(w http.ResponseWriter, r *http.Requ // TODO(phriscage) update for multiple config values func (fe *frontendServer) viewConfigHandler(w http.ResponseWriter, r *http.Request) { log := r.Context().Value(ctxKeyLog{}).(logrus.FieldLogger) + log.Debug("Viewing the configuration") + currencies, err := fe.getCurrencies(r.Context()) if err != nil { renderHTTPError(log, r, w, errors.Wrap(err, "could not retrieve currencies"), http.StatusInternalServerError) diff --git a/src/frontend/main.go b/src/frontend/main.go index d72788e..17229d5 100644 --- a/src/frontend/main.go +++ b/src/frontend/main.go @@ -138,6 +138,7 @@ func main() { var handler http.Handler = r handler = &logHandler{log: log, next: handler} // add logging handler = ensureSessionID(handler) // add session ID + handler = ensureApigeeClientID(handler) // add apigee client ID handler = &ochttp.Handler{ // add opencensus instrumentation Handler: handler, Propagation: &b3.HTTPFormat{}} diff --git a/src/frontend/middleware.go b/src/frontend/middleware.go index 4d4221a..7ed0cee 100644 --- a/src/frontend/middleware.go +++ b/src/frontend/middleware.go @@ -21,6 +21,7 @@ import ( "github.com/google/uuid" "github.com/sirupsen/logrus" + "google.golang.org/grpc/metadata" ) type ctxKeyLog struct{} @@ -103,3 +104,14 @@ func ensureSessionID(next http.Handler) http.HandlerFunc { next.ServeHTTP(w, r) } } + +// update context metadata with appropriate Apigee Authorization header +func ensureApigeeClientID(next http.Handler) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + var apigeeClientID string + apigeeClientID = currentApigeeClientID(r) + ctx := metadata.AppendToOutgoingContext(r.Context(), apigeeClientIDHeaderName, apigeeClientID) + r = r.WithContext(ctx) + next.ServeHTTP(w, r) + } +}