Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
lc = $(subst A,a,$(subst B,b,$(subst C,c,$(subst D,d,$(subst E,e,$(subst F,f,$(subst G,g,$(subst H,h,$(subst I,i,$(subst J,j,$(subst K,k,$(subst L,l,$(subst M,m,$(subst N,n,$(subst O,o,$(subst P,p,$(subst Q,q,$(subst R,r,$(subst S,s,$(subst T,t,$(subst U,u,$(subst V,v,$(subst W,w,$(subst X,x,$(subst Y,y,$(subst Z,z,$1))))))))))))))))))))))))))
BASIC_SERVICES = traefik postgres cloudSymmetric pgweb localMinio cloudMinio localNats natsStreamingExporter localPrometheusPushGateway localPrometheus cloudPrometheus cloudAuth localAuth localStorage cloudStorage localNats storageSync waitlist localStatusReporter cloudDiscovery localDiscovery localSymmetric
BASIC_SERVICES = traefik postgres cloudSymmetric pgweb localMinio cloudMinio localNats natsStreamingExporter localPrometheusPushGateway localPrometheus cloudPrometheus cloudAuth localAuth localStorage cloudStorage localNats storageSync waitlist localStatusReporter cloudStatusReporter cloudDiscovery localDiscovery localSymmetric
BIN_CMD ?=
DOCKER_TAG ?= $(shell git rev-parse --short HEAD)
DOCKER_REGISTRY ?= localhost:5000/
Expand Down
7 changes: 7 additions & 0 deletions cmd/cloudAuth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
metricsServer "github.com/iryonetwork/wwm/metrics/server"
"github.com/iryonetwork/wwm/service/authDataManager"
"github.com/iryonetwork/wwm/service/authenticator"
"github.com/iryonetwork/wwm/service/tracing"
statusServer "github.com/iryonetwork/wwm/status/server"
"github.com/iryonetwork/wwm/storage/auth"
"github.com/iryonetwork/wwm/utils"
Expand All @@ -46,6 +47,9 @@ func main() {
logger.Fatal().Err(err).Msg("failed to get config")
}

traceCloser := tracing.New("cloudAuth", cfg.TracerAddr)
defer traceCloser.Close()

swaggerSpec, err := loads.Analyzed(restapi.SwaggerJSON, "")
if err != nil {
logger.Fatal().Err(err).Msg("Failed to load swagger spec")
Expand Down Expand Up @@ -209,6 +213,9 @@ func main() {
}).Handler(api.Serve(nil))
handler = logMW.APILogMiddleware(handler, logger)
handler = apiMetrics.Middleware(handler)
// add tracer middleware
handler = tracing.Middleware(handler)

server.SetHandler(handler)

// Start servers
Expand Down
6 changes: 6 additions & 0 deletions cmd/cloudDiscovery/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
metricsServer "github.com/iryonetwork/wwm/metrics/server"
"github.com/iryonetwork/wwm/service/authorizer"
discoveryService "github.com/iryonetwork/wwm/service/discovery"
"github.com/iryonetwork/wwm/service/tracing"
statusServer "github.com/iryonetwork/wwm/status/server"
discoveryStorage "github.com/iryonetwork/wwm/storage/discovery"
"github.com/iryonetwork/wwm/utils"
Expand All @@ -44,6 +45,9 @@ func main() {
logger.Fatal().Err(err).Msg("failed to get config")
}

traceCloser := tracing.New("cloudDiscovery", cfg.TracerAddr)
defer traceCloser.Close()

swaggerSpec, err := loads.Analyzed(restapi.SwaggerJSON, "")
if err != nil {
logger.Fatal().Err(err).Msg("Failed to load swagger spec")
Expand Down Expand Up @@ -115,6 +119,8 @@ func main() {
AllowedHeaders: []string{"Authorization", "Content-Type"},
}).Handler(api.Serve(nil))
handler = m.Middleware(handler)
// add tracer middleware
handler = tracing.Middleware(handler)

server.SetHandler(handler)

Expand Down
7 changes: 7 additions & 0 deletions cmd/cloudStatusReporter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
metricsServer "github.com/iryonetwork/wwm/metrics/server"
"github.com/iryonetwork/wwm/service/statusReporter"
"github.com/iryonetwork/wwm/service/statusReporter/polling"
"github.com/iryonetwork/wwm/service/tracing"
)

func main() {
Expand All @@ -36,6 +37,9 @@ func main() {
}
logger.Print(cfg)

traceCloser := tracing.New("cloudStatusReporter", cfg.TracerAddr)
defer traceCloser.Close()

// initialize status reporter
r := statusReporter.New(logger)

Expand Down Expand Up @@ -85,6 +89,9 @@ func main() {
AllowedHeaders: []string{"Authorization", "Content-Type"},
}).Handler(m.Middleware(log.APILogMiddleware(r.Handler("status"), logger)))

// add tracer middleware
handler = tracing.Middleware(handler)

httpServer := &http.Server{
Addr: fmt.Sprintf("%s:%d", cfg.ServerHost, cfg.ServerPortHTTP),
Handler: handler,
Expand Down
6 changes: 6 additions & 0 deletions cmd/cloudStorage/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
metricsServer "github.com/iryonetwork/wwm/metrics/server"
"github.com/iryonetwork/wwm/service/authorizer"
storage "github.com/iryonetwork/wwm/service/storage"
"github.com/iryonetwork/wwm/service/tracing"
statusServer "github.com/iryonetwork/wwm/status/server"
"github.com/iryonetwork/wwm/storage/s3"
"github.com/iryonetwork/wwm/sync/storage/publisher"
Expand All @@ -48,6 +49,9 @@ func main() {
logger.Fatal().Err(err).Msg("failed to get config")
}

traceCloser := tracing.New("cloudStorage", cfg.TracerAddr)
defer traceCloser.Close()

swaggerSpec, err := loads.Analyzed(restapi.SwaggerJSON, "")
if err != nil {
logger.Fatal().Err(err).Msg("Failed to load swagger spec")
Expand Down Expand Up @@ -124,6 +128,8 @@ func main() {
}).Handler(api.Serve(nil))
handler = logMW.APILogMiddleware(handler, logger)
handler = m.Middleware(handler)
// add tracer middleware
handler = tracing.Middleware(handler)

server.SetHandler(handler)

Expand Down
7 changes: 7 additions & 0 deletions cmd/localAuth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/iryonetwork/wwm/service/authDataManager"
"github.com/iryonetwork/wwm/service/authSync"
"github.com/iryonetwork/wwm/service/authenticator"
"github.com/iryonetwork/wwm/service/tracing"
statusServer "github.com/iryonetwork/wwm/status/server"
"github.com/iryonetwork/wwm/storage/auth"
"github.com/iryonetwork/wwm/utils"
Expand All @@ -47,6 +48,9 @@ func main() {
logger.Fatal().Err(err).Msg("failed to get config")
}

traceCloser := tracing.New("localAuth", cfg.TracerAddr)
defer traceCloser.Close()

swaggerSpec, err := loads.Analyzed(restapi.SwaggerJSON, "")
if err != nil {
logger.Fatal().Err(err).Msg("Failed to load swagger spec")
Expand Down Expand Up @@ -192,6 +196,9 @@ func main() {
}).Handler(api.Serve(nil))
handler = logMW.APILogMiddleware(handler, logger)
handler = apiMetrics.Middleware(handler)
// add tracer middleware
handler = tracing.Middleware(handler)

server.SetHandler(handler)

gocron.Every(5).Minutes().Do(authSync.Sync)
Expand Down
6 changes: 6 additions & 0 deletions cmd/localDiscovery/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
metricsServer "github.com/iryonetwork/wwm/metrics/server"
"github.com/iryonetwork/wwm/service/authorizer"
discoveryService "github.com/iryonetwork/wwm/service/discovery"
"github.com/iryonetwork/wwm/service/tracing"
statusServer "github.com/iryonetwork/wwm/status/server"
discoveryStorage "github.com/iryonetwork/wwm/storage/discovery"
"github.com/iryonetwork/wwm/utils"
Expand All @@ -45,6 +46,9 @@ func main() {
logger.Fatal().Err(err).Msg("failed to get config")
}

traceCloser := tracing.New("localDiscovery", cfg.TracerAddr)
defer traceCloser.Close()

swaggerSpec, err := loads.Analyzed(restapi.SwaggerJSON, "")
if err != nil {
logger.Fatal().Err(err).Msg("Failed to load swagger spec")
Expand Down Expand Up @@ -121,6 +125,8 @@ func main() {
AllowedHeaders: []string{"Authorization", "Content-Type"},
}).Handler(api.Serve(nil))
handler = m.Middleware(handler)
// add tracer middleware
handler = tracing.Middleware(handler)

server.SetHandler(handler)

Expand Down
7 changes: 7 additions & 0 deletions cmd/localStatusReporter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
metricsServer "github.com/iryonetwork/wwm/metrics/server"
"github.com/iryonetwork/wwm/service/statusReporter"
"github.com/iryonetwork/wwm/service/statusReporter/polling"
"github.com/iryonetwork/wwm/service/tracing"
)

func main() {
Expand All @@ -36,6 +37,9 @@ func main() {
}
logger.Print(cfg)

traceCloser := tracing.New("localStatusReporter", cfg.TracerAddr)
defer traceCloser.Close()

// initialize status reporter
r := statusReporter.New(logger)

Expand Down Expand Up @@ -99,6 +103,9 @@ func main() {
AllowedHeaders: []string{"Authorization", "Content-Type"},
}).Handler(m.Middleware(log.APILogMiddleware(r.Handler("status"), logger)))

// add tracer middleware
handler = tracing.Middleware(handler)

httpServer := &http.Server{
Addr: fmt.Sprintf("%s:%d", cfg.ServerHost, cfg.ServerPortHTTP),
Handler: handler,
Expand Down
6 changes: 6 additions & 0 deletions cmd/localStorage/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
metricsServer "github.com/iryonetwork/wwm/metrics/server"
"github.com/iryonetwork/wwm/service/authorizer"
storage "github.com/iryonetwork/wwm/service/storage"
"github.com/iryonetwork/wwm/service/tracing"
statusServer "github.com/iryonetwork/wwm/status/server"
"github.com/iryonetwork/wwm/storage/s3"
storageSync "github.com/iryonetwork/wwm/sync/storage"
Expand All @@ -54,6 +55,9 @@ func main() {
logger.Fatal().Err(err).Msg("failed to get config")
}

traceCloser := tracing.New("localStorage", cfg.TracerAddr)
defer traceCloser.Close()

swaggerSpec, err := loads.Analyzed(restapi.SwaggerJSON, "")
if err != nil {
logger.Fatal().Err(err).Msg("Failed to load swagger spec")
Expand Down Expand Up @@ -179,6 +183,8 @@ func main() {
}).Handler(api.Serve(nil))
handler = logMW.APILogMiddleware(handler, logger)
handler = m.Middleware(handler)
// add tracer middleware
handler = tracing.Middleware(handler)

server.SetHandler(handler)

Expand Down
1 change: 1 addition & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type Config struct {
StoragePath string `env:"STORAGE_PATH" envDefault:"storage"`
AuthHost string `env:"AUTH_HOST" envDefault:"localAuth"`
AuthPath string `env:"AUTH_PATH" envDefault:"auth"`
TracerAddr string `env:"TRACER_ADDR" envDefault:"jaeger:5775"`
}

// New returns new instance of Config
Expand Down
7 changes: 7 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -383,3 +383,10 @@ services:
- DB_USERNAME=reportgenerator
- DB_PASSWORD=reportgenerator
- REPORT_SPECS_FILEPATHS=/patientsReportSpec.json,/encountersReportSpec.json

jaeger:
image: jaegertracing/all-in-one:1.3.0
ports:
- 127.0.0.1:5775:5775/udp # accept zipkin.thrift over compact thrift protocol
- 127.0.0.1:16686:16686 # serve frontend

70 changes: 37 additions & 33 deletions service/authenticator/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (
"net/http"
"strings"

"github.com/iryonetwork/wwm/service/tracing"

jwt "github.com/dgrijalva/jwt-go"
"github.com/go-openapi/runtime"
"github.com/go-openapi/swag"
Expand Down Expand Up @@ -158,45 +160,47 @@ func (a *service) GetPrincipalFromToken(tokenString string) (*string, error) {

func (a *service) Authorizer() runtime.Authorizer {
return runtime.AuthorizerFunc(func(request *http.Request, principal interface{}) error {
userID, ok := principal.(*string)
if !ok {
return fmt.Errorf("Principal type was '%T', expected '*string'", principal)
}
return tracing.TraceFunctionSpan("Authorizer", request.Context(), func() error {
userID, ok := principal.(*string)
if !ok {
return fmt.Errorf("Principal type was '%T', expected '*string'", principal)
}

// allow access for service operations without checking ACL
if strings.HasPrefix(*userID, servicePrincipal) {
keyID := (*userID)[len(servicePrincipal):]
s, ok := a.syncServices[keyID]
if ok && (request.URL.EscapedPath() == "/auth/validate" || s.glob.Match("/api"+request.URL.EscapedPath())) {
return nil
// allow access for service operations without checking ACL
if strings.HasPrefix(*userID, servicePrincipal) {
keyID := (*userID)[len(servicePrincipal):]
s, ok := a.syncServices[keyID]
if ok && (request.URL.EscapedPath() == "/auth/validate" || s.glob.Match("/api"+request.URL.EscapedPath())) {
return nil
}
return utils.NewError(utils.ErrForbidden, "You do not have permissions for this resource")
}
return utils.NewError(utils.ErrForbidden, "You do not have permissions for this resource")
}

var action int64
switch request.Method {
case http.MethodPost:
action = auth.Write
case http.MethodPut:
action = auth.Update
case http.MethodDelete:
action = auth.Delete
default:
action = auth.Read
}
var action int64
switch request.Method {
case http.MethodPost:
action = auth.Write
case http.MethodPut:
action = auth.Update
case http.MethodDelete:
action = auth.Delete
default:
action = auth.Read
}

result := a.storage.FindACL(*userID, []*models.ValidationPair{{
DomainType: &a.domainType,
DomainID: &a.domainID,
Actions: &action,
Resource: swag.String("/api" + request.URL.EscapedPath()),
}})
result := a.storage.FindACL(*userID, []*models.ValidationPair{{
DomainType: &a.domainType,
DomainID: &a.domainID,
Actions: &action,
Resource: swag.String("/api" + request.URL.EscapedPath()),
}})

if !*result[0].Result {
return utils.NewError(utils.ErrForbidden, "You do not have permissions for this resource")
}
if !*result[0].Result {
return utils.NewError(utils.ErrForbidden, "You do not have permissions for this resource")
}

return nil
return nil
})
})
}

Expand Down
Loading