Loading go-apps/meep-metrics-engine/go.mod +2 −0 Original line number Diff line number Diff line Loading @@ -12,6 +12,7 @@ require ( github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-model v0.0.0 github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-mq v0.0.0 github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-redis v0.0.0 github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-sessions v0.0.0 github.com/fortytw2/leaktest v1.3.0 // indirect github.com/google/go-cmp v0.3.1 // indirect github.com/gorilla/handlers v1.4.0 Loading @@ -31,4 +32,5 @@ replace ( github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-model => ../../go-packages/meep-model github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-mq => ../../go-packages/meep-mq github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-redis => ../../go-packages/meep-redis github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-sessions => ../../go-packages/meep-sessions ) go-apps/meep-metrics-engine/go.sum +6 −0 Original line number Diff line number Diff line Loading @@ -20,6 +20,10 @@ github.com/gorilla/handlers v1.4.0 h1:XulKRWSQK5uChr4pEgSE4Tc/OcmnU9GJuSwdog/tZs github.com/gorilla/handlers v1.4.0/go.mod h1:Qkdc/uu4tH4g6mTK6auzZ766c4CA0Ng8+o/OAirnOIQ= github.com/gorilla/mux v1.7.1 h1:Dw4jY2nghMMRsh1ol8dv1axHkDwMQK2DHerMNJsIpJU= github.com/gorilla/mux v1.7.1/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs= github.com/gorilla/securecookie v1.1.1 h1:miw7JPhV+b/lAHSXz4qd/nN9jRiAFV5FwjeKyCS8BvQ= github.com/gorilla/securecookie v1.1.1/go.mod h1:ra0sb63/xPlUeL+yeDciTfxMRAA+MP+HVt/4epWDjd4= github.com/gorilla/sessions v1.2.0 h1:S7P+1Hm5V/AT9cjEcUD5uDaQSX0OE577aCXgoaKpYbQ= github.com/gorilla/sessions v1.2.0/go.mod h1:dk2InVEVJ0sfLlnXv9EAgkf6ecYs/i80K/zI+bUmuGM= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= github.com/influxdata/influxdb1-client v0.0.0-20190809212627-fc22c7df067e h1:txQltCyjXAqVVSZDArPEhUTg35hKwVIuXwtQo7eAMNQ= github.com/influxdata/influxdb1-client v0.0.0-20190809212627-fc22c7df067e/go.mod h1:qj24IKcXYK6Iy9ceXlo3Tc+vtHo9lIhSX5JddghvEPo= Loading @@ -33,6 +37,8 @@ github.com/onsi/ginkgo v1.10.1/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+ github.com/onsi/gomega v1.7.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/rs/xid v1.2.1 h1:mhH9Nq+C1fY2l1XIpgxIiUOfNpRBYH1kKcr+qfKgjRc= github.com/rs/xid v1.2.1/go.mod h1:+uKXf+4Djp6Md1KODXJxgGQPKngRmWyn10oCKFzNHOQ= github.com/sirupsen/logrus v1.4.1 h1:GL2rEmy6nsikmW0r8opw9JIRScdMF5hA8cOYLH7In1k= github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q= github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= Loading go-apps/meep-metrics-engine/main.go +17 −3 Original line number Diff line number Diff line Loading @@ -23,9 +23,9 @@ import ( "syscall" "time" log "github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-logger" server "github.com/InterDigitalInc/AdvantEDGE/go-apps/meep-metrics-engine/server" log "github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-logger" ss "github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-sessions" "github.com/gorilla/handlers" ) Loading Loading @@ -69,7 +69,21 @@ func main() { } // Start Metric Engine Service REST API Server router := server.NewRouter() accessMap := map[string]string{ "IndexV2": ss.AccessBlock, "PostEventQuery": ss.AccessVerify, "PostHttpQuery": ss.AccessVerify, "PostNetworkQuery": ss.AccessVerify, "CreateEventSubscription": ss.AccessVerify, "CreateNetworkSubscription": ss.AccessVerify, "DeleteEventSubscriptionById": ss.AccessVerify, "DeleteNetworkSubscriptionById": ss.AccessVerify, "GetEventSubscription": ss.AccessVerify, "GetEventSubscriptionById": ss.AccessVerify, "GetNetworkSubscription": ss.AccessVerify, "GetNetworkSubscriptionById": ss.AccessVerify, } router := server.NewRouter(accessMap) methods := handlers.AllowedMethods([]string{"OPTIONS", "DELETE", "GET", "HEAD", "POST", "PUT"}) header := handlers.AllowedHeaders([]string{"content-type"}) log.Fatal(http.ListenAndServe(":80", handlers.CORS(methods, header)(router))) Loading go-apps/meep-metrics-engine/server/routers.go +28 −3 Original line number Diff line number Diff line Loading @@ -29,11 +29,11 @@ import ( "net/http" "strings" httpLog "github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-http-logger" "github.com/gorilla/mux" v2 "github.com/InterDigitalInc/AdvantEDGE/go-apps/meep-metrics-engine/server/v2" httpLog "github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-http-logger" ss "github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-sessions" ) type Route struct { Loading @@ -41,17 +41,30 @@ type Route struct { Method string Pattern string HandlerFunc http.HandlerFunc AccessType string } type Routes []Route func NewRouter() *mux.Router { func NewRouter(accessMap map[string]string) *mux.Router { router := mux.NewRouter().StrictSlash(true) for _, route := range routes { var handler http.Handler = route.HandlerFunc handler = Logger(handler, route.Name) handler = httpLog.LogRx(handler, "") // Authorization accessType, found := accessMap[route.Name] if !found { accessType = route.AccessType } if accessType == ss.AccessBlock { handler = v2.SessionStore.AccessBlocker(handler) } else if accessType == ss.AccessVerify { handler = v2.SessionStore.AccessVerifier(handler) } router. Methods(route.Method). Path(route.Pattern). Loading Loading @@ -88,6 +101,7 @@ var routes = Routes{ "GET", "/metrics/v2/", IndexV2, ss.AccessGrant, }, Route{ Loading @@ -95,6 +109,7 @@ var routes = Routes{ strings.ToUpper("Post"), "/metrics/v2/metrics/query/event", v2.PostEventQuery, ss.AccessGrant, }, Route{ Loading @@ -102,6 +117,7 @@ var routes = Routes{ strings.ToUpper("Post"), "/metrics/v2/metrics/query/http", v2.PostHttpQuery, ss.AccessGrant, }, Route{ Loading @@ -109,6 +125,7 @@ var routes = Routes{ strings.ToUpper("Post"), "/metrics/v2/metrics/query/network", v2.PostNetworkQuery, ss.AccessGrant, }, Route{ Loading @@ -116,6 +133,7 @@ var routes = Routes{ strings.ToUpper("Post"), "/metrics/v2/metrics/subscriptions/event", v2.CreateEventSubscription, ss.AccessGrant, }, Route{ Loading @@ -123,6 +141,7 @@ var routes = Routes{ strings.ToUpper("Post"), "/metrics/v2/metrics/subscriptions/network", v2.CreateNetworkSubscription, ss.AccessGrant, }, Route{ Loading @@ -130,6 +149,7 @@ var routes = Routes{ strings.ToUpper("Delete"), "/metrics/v2/metrics/subscriptions/event/{subscriptionId}", v2.DeleteEventSubscriptionById, ss.AccessGrant, }, Route{ Loading @@ -137,6 +157,7 @@ var routes = Routes{ strings.ToUpper("Delete"), "/metrics/v2/metrics/subscriptions/network/{subscriptionId}", v2.DeleteNetworkSubscriptionById, ss.AccessGrant, }, Route{ Loading @@ -144,6 +165,7 @@ var routes = Routes{ strings.ToUpper("Get"), "/metrics/v2/metrics/subscriptions/event", v2.GetEventSubscription, ss.AccessGrant, }, Route{ Loading @@ -151,6 +173,7 @@ var routes = Routes{ strings.ToUpper("Get"), "/metrics/v2/metrics/subscriptions/event/{subscriptionId}", v2.GetEventSubscriptionById, ss.AccessGrant, }, Route{ Loading @@ -158,6 +181,7 @@ var routes = Routes{ strings.ToUpper("Get"), "/metrics/v2/metrics/subscriptions/network", v2.GetNetworkSubscription, ss.AccessGrant, }, Route{ Loading @@ -165,5 +189,6 @@ var routes = Routes{ strings.ToUpper("Get"), "/metrics/v2/metrics/subscriptions/network/{subscriptionId}", v2.GetNetworkSubscriptionById, ss.AccessGrant, }, } go-apps/meep-metrics-engine/server/v2/metrics-engine.go +10 −0 Original line number Diff line number Diff line Loading @@ -37,6 +37,7 @@ import ( mod "github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-model" mq "github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-mq" redis "github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-redis" ss "github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-sessions" "github.com/gorilla/mux" ) Loading Loading @@ -73,6 +74,7 @@ var hostUrl *url.URL var basePath string var baseKey string var SessionStore *ss.SessionStore var rc *redis.Connector type EventRegistration struct { Loading Loading @@ -148,6 +150,14 @@ func Init() (err error) { } log.Info("Connected to Redis DB") // Connect to Session Store SessionStore, err = ss.NewSessionStore(redisAddr) if err != nil { log.Error("Failed connection to Session Store: ", err.Error()) return err } log.Info("Connected to Session Store") nextNetworkSubscriptionIdAvailable = 1 nextEventSubscriptionIdAvailable = 1 Loading Loading
go-apps/meep-metrics-engine/go.mod +2 −0 Original line number Diff line number Diff line Loading @@ -12,6 +12,7 @@ require ( github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-model v0.0.0 github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-mq v0.0.0 github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-redis v0.0.0 github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-sessions v0.0.0 github.com/fortytw2/leaktest v1.3.0 // indirect github.com/google/go-cmp v0.3.1 // indirect github.com/gorilla/handlers v1.4.0 Loading @@ -31,4 +32,5 @@ replace ( github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-model => ../../go-packages/meep-model github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-mq => ../../go-packages/meep-mq github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-redis => ../../go-packages/meep-redis github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-sessions => ../../go-packages/meep-sessions )
go-apps/meep-metrics-engine/go.sum +6 −0 Original line number Diff line number Diff line Loading @@ -20,6 +20,10 @@ github.com/gorilla/handlers v1.4.0 h1:XulKRWSQK5uChr4pEgSE4Tc/OcmnU9GJuSwdog/tZs github.com/gorilla/handlers v1.4.0/go.mod h1:Qkdc/uu4tH4g6mTK6auzZ766c4CA0Ng8+o/OAirnOIQ= github.com/gorilla/mux v1.7.1 h1:Dw4jY2nghMMRsh1ol8dv1axHkDwMQK2DHerMNJsIpJU= github.com/gorilla/mux v1.7.1/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs= github.com/gorilla/securecookie v1.1.1 h1:miw7JPhV+b/lAHSXz4qd/nN9jRiAFV5FwjeKyCS8BvQ= github.com/gorilla/securecookie v1.1.1/go.mod h1:ra0sb63/xPlUeL+yeDciTfxMRAA+MP+HVt/4epWDjd4= github.com/gorilla/sessions v1.2.0 h1:S7P+1Hm5V/AT9cjEcUD5uDaQSX0OE577aCXgoaKpYbQ= github.com/gorilla/sessions v1.2.0/go.mod h1:dk2InVEVJ0sfLlnXv9EAgkf6ecYs/i80K/zI+bUmuGM= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= github.com/influxdata/influxdb1-client v0.0.0-20190809212627-fc22c7df067e h1:txQltCyjXAqVVSZDArPEhUTg35hKwVIuXwtQo7eAMNQ= github.com/influxdata/influxdb1-client v0.0.0-20190809212627-fc22c7df067e/go.mod h1:qj24IKcXYK6Iy9ceXlo3Tc+vtHo9lIhSX5JddghvEPo= Loading @@ -33,6 +37,8 @@ github.com/onsi/ginkgo v1.10.1/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+ github.com/onsi/gomega v1.7.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/rs/xid v1.2.1 h1:mhH9Nq+C1fY2l1XIpgxIiUOfNpRBYH1kKcr+qfKgjRc= github.com/rs/xid v1.2.1/go.mod h1:+uKXf+4Djp6Md1KODXJxgGQPKngRmWyn10oCKFzNHOQ= github.com/sirupsen/logrus v1.4.1 h1:GL2rEmy6nsikmW0r8opw9JIRScdMF5hA8cOYLH7In1k= github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q= github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= Loading
go-apps/meep-metrics-engine/main.go +17 −3 Original line number Diff line number Diff line Loading @@ -23,9 +23,9 @@ import ( "syscall" "time" log "github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-logger" server "github.com/InterDigitalInc/AdvantEDGE/go-apps/meep-metrics-engine/server" log "github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-logger" ss "github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-sessions" "github.com/gorilla/handlers" ) Loading Loading @@ -69,7 +69,21 @@ func main() { } // Start Metric Engine Service REST API Server router := server.NewRouter() accessMap := map[string]string{ "IndexV2": ss.AccessBlock, "PostEventQuery": ss.AccessVerify, "PostHttpQuery": ss.AccessVerify, "PostNetworkQuery": ss.AccessVerify, "CreateEventSubscription": ss.AccessVerify, "CreateNetworkSubscription": ss.AccessVerify, "DeleteEventSubscriptionById": ss.AccessVerify, "DeleteNetworkSubscriptionById": ss.AccessVerify, "GetEventSubscription": ss.AccessVerify, "GetEventSubscriptionById": ss.AccessVerify, "GetNetworkSubscription": ss.AccessVerify, "GetNetworkSubscriptionById": ss.AccessVerify, } router := server.NewRouter(accessMap) methods := handlers.AllowedMethods([]string{"OPTIONS", "DELETE", "GET", "HEAD", "POST", "PUT"}) header := handlers.AllowedHeaders([]string{"content-type"}) log.Fatal(http.ListenAndServe(":80", handlers.CORS(methods, header)(router))) Loading
go-apps/meep-metrics-engine/server/routers.go +28 −3 Original line number Diff line number Diff line Loading @@ -29,11 +29,11 @@ import ( "net/http" "strings" httpLog "github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-http-logger" "github.com/gorilla/mux" v2 "github.com/InterDigitalInc/AdvantEDGE/go-apps/meep-metrics-engine/server/v2" httpLog "github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-http-logger" ss "github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-sessions" ) type Route struct { Loading @@ -41,17 +41,30 @@ type Route struct { Method string Pattern string HandlerFunc http.HandlerFunc AccessType string } type Routes []Route func NewRouter() *mux.Router { func NewRouter(accessMap map[string]string) *mux.Router { router := mux.NewRouter().StrictSlash(true) for _, route := range routes { var handler http.Handler = route.HandlerFunc handler = Logger(handler, route.Name) handler = httpLog.LogRx(handler, "") // Authorization accessType, found := accessMap[route.Name] if !found { accessType = route.AccessType } if accessType == ss.AccessBlock { handler = v2.SessionStore.AccessBlocker(handler) } else if accessType == ss.AccessVerify { handler = v2.SessionStore.AccessVerifier(handler) } router. Methods(route.Method). Path(route.Pattern). Loading Loading @@ -88,6 +101,7 @@ var routes = Routes{ "GET", "/metrics/v2/", IndexV2, ss.AccessGrant, }, Route{ Loading @@ -95,6 +109,7 @@ var routes = Routes{ strings.ToUpper("Post"), "/metrics/v2/metrics/query/event", v2.PostEventQuery, ss.AccessGrant, }, Route{ Loading @@ -102,6 +117,7 @@ var routes = Routes{ strings.ToUpper("Post"), "/metrics/v2/metrics/query/http", v2.PostHttpQuery, ss.AccessGrant, }, Route{ Loading @@ -109,6 +125,7 @@ var routes = Routes{ strings.ToUpper("Post"), "/metrics/v2/metrics/query/network", v2.PostNetworkQuery, ss.AccessGrant, }, Route{ Loading @@ -116,6 +133,7 @@ var routes = Routes{ strings.ToUpper("Post"), "/metrics/v2/metrics/subscriptions/event", v2.CreateEventSubscription, ss.AccessGrant, }, Route{ Loading @@ -123,6 +141,7 @@ var routes = Routes{ strings.ToUpper("Post"), "/metrics/v2/metrics/subscriptions/network", v2.CreateNetworkSubscription, ss.AccessGrant, }, Route{ Loading @@ -130,6 +149,7 @@ var routes = Routes{ strings.ToUpper("Delete"), "/metrics/v2/metrics/subscriptions/event/{subscriptionId}", v2.DeleteEventSubscriptionById, ss.AccessGrant, }, Route{ Loading @@ -137,6 +157,7 @@ var routes = Routes{ strings.ToUpper("Delete"), "/metrics/v2/metrics/subscriptions/network/{subscriptionId}", v2.DeleteNetworkSubscriptionById, ss.AccessGrant, }, Route{ Loading @@ -144,6 +165,7 @@ var routes = Routes{ strings.ToUpper("Get"), "/metrics/v2/metrics/subscriptions/event", v2.GetEventSubscription, ss.AccessGrant, }, Route{ Loading @@ -151,6 +173,7 @@ var routes = Routes{ strings.ToUpper("Get"), "/metrics/v2/metrics/subscriptions/event/{subscriptionId}", v2.GetEventSubscriptionById, ss.AccessGrant, }, Route{ Loading @@ -158,6 +181,7 @@ var routes = Routes{ strings.ToUpper("Get"), "/metrics/v2/metrics/subscriptions/network", v2.GetNetworkSubscription, ss.AccessGrant, }, Route{ Loading @@ -165,5 +189,6 @@ var routes = Routes{ strings.ToUpper("Get"), "/metrics/v2/metrics/subscriptions/network/{subscriptionId}", v2.GetNetworkSubscriptionById, ss.AccessGrant, }, }
go-apps/meep-metrics-engine/server/v2/metrics-engine.go +10 −0 Original line number Diff line number Diff line Loading @@ -37,6 +37,7 @@ import ( mod "github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-model" mq "github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-mq" redis "github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-redis" ss "github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-sessions" "github.com/gorilla/mux" ) Loading Loading @@ -73,6 +74,7 @@ var hostUrl *url.URL var basePath string var baseKey string var SessionStore *ss.SessionStore var rc *redis.Connector type EventRegistration struct { Loading Loading @@ -148,6 +150,14 @@ func Init() (err error) { } log.Info("Connected to Redis DB") // Connect to Session Store SessionStore, err = ss.NewSessionStore(redisAddr) if err != nil { log.Error("Failed connection to Session Store: ", err.Error()) return err } log.Info("Connected to Session Store") nextNetworkSubscriptionIdAvailable = 1 nextEventSubscriptionIdAvailable = 1 Loading