Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/weos 1518 #175

Merged
merged 20 commits into from
Jul 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
5c5cc46
feature: WEOS-1504 Add logs to container
akeemphilbert Jun 14, 2022
1d9bd48
feature: WEOS-1504 Add http client to container
akeemphilbert Jun 15, 2022
78631ad
docs: Added spec for authorization configuration
akeemphilbert Jun 19, 2022
9d20b66
Merge branch 'feature/WEOS-1504' into feature/WEOS-1518
akeemphilbert Jun 19, 2022
017c7d2
feature: WEOS-1518 WEOS-1519 WEOS-1344 Create Security Middleware for…
akeemphilbert Jun 19, 2022
426ce0c
feature: WEOS-1344 Create Security Middleware for managing security c…
akeemphilbert Jun 20, 2022
5d71d71
feature: WEOS-1518 Map JWT parts to user id, role, WEOS-1344 Added su…
akeemphilbert Jun 20, 2022
cdb6053
feature: WEOS-1519 Setup permission configuration
akeemphilbert Jun 21, 2022
6555162
feature: WEOS-1519 Setup permission configuration
akeemphilbert Jun 21, 2022
cf5e1cd
feature: FHIR api fixes
akeemphilbert Jun 23, 2022
233eee0
feature: FHIR api fixes
akeemphilbert Jun 24, 2022
d041004
bugfix: Remove use of old schema code
akeemphilbert Jun 24, 2022
b017f05
bugfix: Changed depth restriction
akeemphilbert Jun 24, 2022
20b8078
bugfix: Fix for date time not being unmarshalled into content entity …
akeemphilbert Jun 26, 2022
affb372
bugfix: Fix for date time not being unmarshalled into content entity …
akeemphilbert Jun 26, 2022
aeb7a0a
feature: added basic template functions
akeemphilbert Jul 1, 2022
c99a58d
fix: Get preload associations working
akeemphilbert Jul 4, 2022
fa31f8a
feature: Closed #177
akeemphilbert Jul 13, 2022
acfb0d0
feature: Fixed content entity check test
akeemphilbert Jul 13, 2022
6374da4
Merge pull request #176 from wepala/fhir-fixes
akeemphilbert Jul 13, 2022
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
1 change: 1 addition & 0 deletions context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const HeaderXLogLevel = "X-LOG-LEVEL"
const ACCOUNT_ID ContextKey = "ACCOUNT_ID"
const OPERATION_ID = "OPERATION_ID"
const USER_ID ContextKey = "USER_ID"
const ROLE ContextKey = "ROLE"
const LOG_LEVEL ContextKey = "LOG_LEVEL"
const REQUEST_ID ContextKey = "REQUEST_ID"
const WEOS_ID ContextKey = "WEOS_ID"
Expand Down
69 changes: 68 additions & 1 deletion controllers/rest/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"database/sql"
"errors"
"fmt"
"github.com/casbin/casbin/v2"
"net/http"
"os"
"reflect"
Expand Down Expand Up @@ -38,6 +39,7 @@ type RESTAPI struct {
Client *http.Client
projection *projections.GORMDB
Config *APIConfig
securityConfiguration *SecurityConfiguration
e *echo.Echo
PathConfigs map[string]*PathConfig
Schemas map[string]ds.Builder
Expand All @@ -47,6 +49,8 @@ type RESTAPI struct {
eventStores map[string]model.EventRepository
commandDispatchers map[string]model.CommandDispatcher
projections map[string]projections.Projection
logs map[string]model.Log
httpClients map[string]*http.Client
globalInitializers []GlobalInitializer
operationInitializers []OperationInitializer
registeredInitializers map[reflect.Value]int
Expand All @@ -57,6 +61,7 @@ type RESTAPI struct {
entityFactories map[string]model.EntityFactory
dbConnections map[string]*sql.DB
gormConnections map[string]*gorm.DB
enforcers map[string]*casbin.Enforcer
}

type schema struct {
Expand Down Expand Up @@ -219,6 +224,20 @@ func (p *RESTAPI) RegisterGORMDB(name string, connection *gorm.DB) {
p.gormConnections[name] = connection
}

func (p *RESTAPI) RegisterPermissionEnforcer(name string, enforcer *casbin.Enforcer) {
if p.enforcers == nil {
p.enforcers = make(map[string]*casbin.Enforcer)
}
p.enforcers[name] = enforcer
}

func (p *RESTAPI) GetPermissionEnforcer(name string) (*casbin.Enforcer, error) {
if tenforcer, ok := p.enforcers[name]; ok {
return tenforcer, nil
}
return nil, fmt.Errorf("permission enforcer '%s' not found", name)
}

//GetMiddleware get middleware by name
func (p *RESTAPI) GetMiddleware(name string) (Middleware, error) {
if tmiddleware, ok := p.middlewares[name]; ok {
Expand Down Expand Up @@ -341,6 +360,43 @@ func (p *RESTAPI) GetWeOSConfig() *APIConfig {
return p.Config
}

//RegisterLog setup a log
func (p *RESTAPI) RegisterLog(name string, logger model.Log) {
if p.logs == nil {
p.logs = make(map[string]model.Log)
}
p.logs[name] = logger
}

func (p *RESTAPI) GetLog(name string) (model.Log, error) {
if tlog, ok := p.logs[name]; ok {
return tlog, nil
}
return nil, fmt.Errorf("log '%s' not found", name)
}

func (p *RESTAPI) RegisterHTTPClient(name string, client *http.Client) {
if p.httpClients == nil {
p.httpClients = make(map[string]*http.Client)
}
p.httpClients[name] = client
}

func (p *RESTAPI) GetHTTPClient(name string) (*http.Client, error) {
if client, ok := p.httpClients[name]; ok {
return client, nil
}
return nil, fmt.Errorf("http client '%s' not found", name)
}

func (p *RESTAPI) RegisterSecurityConfiguration(configuration *SecurityConfiguration) {
p.securityConfiguration = configuration
}

func (p *RESTAPI) GetSecurityConfiguration() *SecurityConfiguration {
return p.securityConfiguration
}

const SWAGGERUIENDPOINT = "/_discover/"
const SWAGGERJSONENDPOINT = "/_discover_json"

Expand Down Expand Up @@ -368,6 +424,17 @@ func (p *RESTAPI) RegisterDefaultSwaggerJSON(pathMiddleware []echo.MiddlewareFun

//Initialize and setup configurations for RESTAPI
func (p *RESTAPI) Initialize(ctxt context.Context) error {
//register logger
p.RegisterLog("Default", p.e.Logger)
//register httpClient
t := http.DefaultTransport.(*http.Transport).Clone()
t.MaxIdleConns = 100
t.MaxConnsPerHost = 100
t.MaxIdleConnsPerHost = 100
p.RegisterHTTPClient("Default", &http.Client{
Transport: t,
Timeout: time.Second * 10,
})
//register standard controllers
p.RegisterController("CreateController", CreateController)
p.RegisterController("UpdateController", UpdateController)
Expand All @@ -381,7 +448,6 @@ func (p *RESTAPI) Initialize(ctxt context.Context) error {

//register standard middleware
p.RegisterMiddleware("Context", Context)
p.RegisterMiddleware("OpenIDMiddleware", OpenIDMiddleware)
p.RegisterMiddleware("CreateMiddleware", CreateMiddleware)
p.RegisterMiddleware("CreateBatchMiddleware", CreateBatchMiddleware)
p.RegisterMiddleware("UpdateMiddleware", UpdateMiddleware)
Expand All @@ -403,6 +469,7 @@ func (p *RESTAPI) Initialize(ctxt context.Context) error {
p.RegisterOperationInitializer(ContentTypeResponseInitializer)
p.RegisterOperationInitializer(EntityFactoryInitializer)
p.RegisterOperationInitializer(UserDefinedInitializer)
p.RegisterOperationInitializer(AuthorizationInitializer)
p.RegisterOperationInitializer(StandardInitializer)
p.RegisterOperationInitializer(RouteInitializer)
//register standard post path initializers
Expand Down
7 changes: 6 additions & 1 deletion controllers/rest/controller_standard.go
Original file line number Diff line number Diff line change
Expand Up @@ -861,7 +861,12 @@ func DefaultResponseMiddleware(tapi Container, projection projections.Projection
ctxt.File(fileName)
} else if len(templates) != 0 {
contextValues := ReturnContextValues(ctx)
t := template.New(path1.Base(templates[0]))
funcMap := template.FuncMap{
"Title": strings.Title,
"ToUpper": strings.ToUpper,
"ToLower": strings.ToLower,
}
t := template.New(path1.Base(templates[0])).Funcs(funcMap)
t, err := t.ParseFiles(templates...)
if err != nil {
api.e.Logger.Debugf("unexpected error %s ", err)
Expand Down
Loading