feat/sync-setting:
+ moved infra/sync-cfg to infra/sync-consumer-cfg + adjut anything related to old infra/sync + infra/sync is now have new setting for the sync
This commit is contained in:
@@ -69,9 +69,11 @@ bpjsCfg:
|
||||
baseUrl:
|
||||
|
||||
syncUrlCfg:
|
||||
enable: false
|
||||
host:
|
||||
prefix: new-to-old
|
||||
enable: false
|
||||
targetHost:
|
||||
prefix: new-to-old
|
||||
source: new-app
|
||||
secretKey: new-world-order!!
|
||||
|
||||
docsCfg:
|
||||
path: ../../assets/docs/
|
||||
@@ -34,4 +34,12 @@ langCfg:
|
||||
|
||||
corsCfg:
|
||||
allowedOrigin:
|
||||
allowedMethod: GET, POST, PUT, PATCH, DELETE, OPTIONS
|
||||
allowedMethod: GET, POST, PUT, PATCH, DELETE, OPTIONS
|
||||
|
||||
syncPartnerCfg:
|
||||
oldSource
|
||||
oldSecretKey
|
||||
oldHost
|
||||
newSource
|
||||
newSecretKey
|
||||
newHost
|
||||
@@ -0,0 +1,9 @@
|
||||
package authentication
|
||||
|
||||
type SyncKey struct{}
|
||||
|
||||
type CredentialDto struct {
|
||||
Source string `json:"X-Sync-Source"`
|
||||
SecretKey string `json:"X-Sync-SecretKey"`
|
||||
UserName string `json:"X-Sync-UserName"`
|
||||
}
|
||||
@@ -8,8 +8,8 @@ import (
|
||||
func SetConfig() {
|
||||
a.ParseSingleCfg(&O)
|
||||
|
||||
if O.Host == "" || O.Prefix == "" {
|
||||
panic("config sync host and prefix empty")
|
||||
if O.NewSecretKey == "" || O.NewHost == "" || O.OldSecretKey == "" || O.OldHost == "" {
|
||||
panic("secret key and host of the sync partner config can not be empty")
|
||||
}
|
||||
lo.I.Println("sync url config loaded, status: DONE!!")
|
||||
lo.I.Println("sync partner config loaded, status: DONE!!")
|
||||
}
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
package synccfg
|
||||
|
||||
var O SyncUrlCfg = SyncUrlCfg{}
|
||||
var O PartnerCfg = PartnerCfg{} // old
|
||||
|
||||
type SyncUrlCfg struct {
|
||||
Prefix string `yaml:"prefix"`
|
||||
Host string `yaml:"host"`
|
||||
Enable bool `yaml:"enable"`
|
||||
// Used by sync itself, so any partner should be stated here
|
||||
type PartnerCfg struct {
|
||||
OldSource string `yaml:"oldSource"`
|
||||
OldSecretKey string `yaml:"oldSecretKey"`
|
||||
OldHost string `yaml:"oldHost"`
|
||||
NewSource string `yaml:"newSource"`
|
||||
NewSecretKey string `yaml:"newSecretKey"`
|
||||
NewHost string `yaml:"newHost"`
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
package synccfg
|
||||
|
||||
import (
|
||||
a "github.com/karincake/apem"
|
||||
lo "github.com/karincake/apem/loggero"
|
||||
)
|
||||
|
||||
func SetConfig() {
|
||||
a.ParseSingleCfg(&O)
|
||||
|
||||
if O.TargetHost == "" || O.Prefix == "" {
|
||||
panic("config sync host and prefix empty")
|
||||
}
|
||||
lo.I.Println("sync url config loaded, status: DONE!!")
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package synccfg
|
||||
|
||||
var O SyncUrlCfg = SyncUrlCfg{} // old
|
||||
|
||||
type SyncUrlCfg struct {
|
||||
Prefix string `yaml:"prefix"`
|
||||
TargetHost string `yaml:"targetHost"`
|
||||
Enable bool `yaml:"enable"`
|
||||
Source string `yaml:"source"`
|
||||
SecretKey string `yaml:"secretKey"`
|
||||
}
|
||||
@@ -13,6 +13,8 @@ import (
|
||||
mf "simrs-vx/internal/domain/main-entities/user-fes"
|
||||
pa "simrs-vx/internal/lib/auth"
|
||||
s "simrs-vx/internal/use-case/main-use-case/authentication"
|
||||
|
||||
esga "simrs-vx/internal/domain/sync-entities/authentication"
|
||||
)
|
||||
|
||||
func Login(w http.ResponseWriter, r *http.Request) {
|
||||
@@ -67,6 +69,23 @@ func Logout(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
func GuardMW(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
// Check if it's from sync
|
||||
credential := esga.CredentialDto{}
|
||||
credential.Source = r.Header.Get("X-Sync-Source")
|
||||
credential.SecretKey = r.Header.Get("X-Sync-SecretKey")
|
||||
credential.UserName = r.Header.Get("X-Sync-UserName")
|
||||
if credential.Source != "" || credential.SecretKey != "" || credential.UserName != "" {
|
||||
ctx := context.WithValue(r.Context(), esga.SyncKey{}, credential)
|
||||
next.ServeHTTP(w, r.WithContext(ctx))
|
||||
// TO DO:
|
||||
// 1 Get user info manually (not by using token), based on credential.UserName
|
||||
// 2 To cover the point 1, Adjust /use-case/main-use-case/authentication to have the function
|
||||
// 3 Any DTO that is used in the sync, add flag Sync (tru/false), set it true if it is from sync
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// Normal flow goes here
|
||||
accessDetail, err := s.ExtractToken(r, s.AccessToken)
|
||||
if err != nil {
|
||||
rw.WriteJSON(w, http.StatusUnauthorized, err.(d.FieldError), nil)
|
||||
|
||||
@@ -63,7 +63,7 @@ import (
|
||||
gs "simrs-vx/internal/infra/gorm-setting"
|
||||
minio "simrs-vx/internal/infra/minio"
|
||||
ssdb "simrs-vx/internal/infra/ss-db"
|
||||
simgossync "simrs-vx/internal/infra/sync-cfg"
|
||||
sync "simrs-vx/internal/infra/sync-consumer-cfg"
|
||||
|
||||
/******************** pkg ********************/
|
||||
cmw "simrs-vx/pkg/cors-manager-mw"
|
||||
@@ -135,7 +135,7 @@ func SetRoutes() http.Handler {
|
||||
a.RegisterExtCall(mh.I.SetClient)
|
||||
a.RegisterExtCall(ibpjs.SetConfig)
|
||||
a.RegisterExtCall(validation.RegisterValidation)
|
||||
a.RegisterExtCall(simgossync.SetConfig)
|
||||
a.RegisterExtCall(sync.SetConfig)
|
||||
a.RegisterExtCall(docscfg.ParseCfg)
|
||||
|
||||
r := http.NewServeMux()
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
package authentication
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
|
||||
d "github.com/karincake/dodol"
|
||||
rw "github.com/karincake/risoles"
|
||||
|
||||
sc "simrs-vx/internal/lib/sync-credential"
|
||||
|
||||
e "simrs-vx/internal/domain/sync-entities/authentication"
|
||||
is "simrs-vx/internal/infra/sync-cfg"
|
||||
)
|
||||
|
||||
func NewGuardMW(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
// check the data format
|
||||
input := e.CredentialDto{}
|
||||
if success := sc.CheckCredentialData(&input, r, w); !success {
|
||||
return
|
||||
}
|
||||
|
||||
// check the validity
|
||||
if input.Source != is.O.NewSource || input.SecretKey != is.O.NewSecretKey {
|
||||
rw.WriteJSON(w, http.StatusUnauthorized, d.IS{"message": "invalid consumer credential"}, nil)
|
||||
return
|
||||
}
|
||||
|
||||
ctx := context.WithValue(r.Context(), e.SyncKey{}, input)
|
||||
next.ServeHTTP(w, r.WithContext(ctx))
|
||||
})
|
||||
}
|
||||
|
||||
func OldGuardMW(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
// check the data format
|
||||
input := e.CredentialDto{}
|
||||
if success := sc.CheckCredentialData(&input, r, w); !success {
|
||||
return
|
||||
}
|
||||
|
||||
// check the validity
|
||||
if input.Source != is.O.OldSource || input.SecretKey != is.O.OldSecretKey {
|
||||
rw.WriteJSON(w, http.StatusUnauthorized, d.IS{"message": "invalid consumer credential"}, nil)
|
||||
return
|
||||
}
|
||||
|
||||
ctx := context.WithValue(r.Context(), e.SyncKey{}, input)
|
||||
next.ServeHTTP(w, r.WithContext(ctx))
|
||||
})
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
/******************** infra ********************/
|
||||
gs "simrs-vx/internal/infra/gorm-setting"
|
||||
simgosdb "simrs-vx/internal/infra/simgos-db"
|
||||
sync "simrs-vx/internal/infra/sync-consumer-cfg"
|
||||
|
||||
/******************** pkg ********************/
|
||||
cmw "simrs-vx/pkg/cors-manager-mw"
|
||||
@@ -27,6 +28,8 @@ import (
|
||||
"simrs-vx/internal/interface/simgos-sync-handler/new/specialist"
|
||||
"simrs-vx/internal/interface/simgos-sync-handler/new/subspecialist"
|
||||
"simrs-vx/internal/interface/simgos-sync-handler/new/unit"
|
||||
|
||||
oauth "simrs-vx/internal/interface/simgos-sync-handler/old/authentication" // just a reminder, an openauth
|
||||
)
|
||||
|
||||
func SetRoutes() http.Handler {
|
||||
@@ -34,6 +37,7 @@ func SetRoutes() http.Handler {
|
||||
a.RegisterExtCall(gs.Adjust)
|
||||
a.RegisterExtCall(zlc.Adjust)
|
||||
a.RegisterExtCall(lh.Populate)
|
||||
a.RegisterExtCall(sync.SetConfig)
|
||||
a.RegisterExtCall(simgosdb.SetInstance)
|
||||
|
||||
r := http.NewServeMux()
|
||||
@@ -66,7 +70,8 @@ func SetRoutes() http.Handler {
|
||||
})
|
||||
|
||||
/******************** SvcToNew ******************/
|
||||
//prefixold := "/old-to-new"
|
||||
prefixold := "/old-to-new"
|
||||
hk.GroupRoutes(prefixold+"/v1/patient", r, oauth.OldGuardMW, hk.MapHandlerFunc{}) // FINISH THIS
|
||||
|
||||
return cmw.SetCors(handlerlogger.SetLog(r))
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
package authentication
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
d "github.com/karincake/dodol"
|
||||
rw "github.com/karincake/risoles"
|
||||
sr "github.com/karincake/serabi"
|
||||
|
||||
e "simrs-vx/internal/domain/sync-entities/authentication"
|
||||
)
|
||||
|
||||
func CheckCredentialData(input *e.CredentialDto, r *http.Request, w http.ResponseWriter) bool {
|
||||
input.Source = r.Header.Get("X-Sync-Source")
|
||||
input.SecretKey = r.Header.Get("X-Sync-SecretKey")
|
||||
input.UserName = r.Header.Get("X-Sync-UserName")
|
||||
if err := sr.Validate(input); err != nil {
|
||||
rw.WriteJSON(w, http.StatusUnauthorized, d.II{"errors": err}, nil)
|
||||
return false
|
||||
}
|
||||
return true
|
||||
|
||||
}
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
|
||||
"gorm.io/gorm"
|
||||
|
||||
sync "simrs-vx/internal/infra/sync-cfg"
|
||||
sync "simrs-vx/internal/infra/sync-consumer-cfg"
|
||||
|
||||
e "simrs-vx/internal/domain/main-entities/division"
|
||||
esync "simrs-vx/internal/domain/sync-entities/log"
|
||||
|
||||
@@ -834,7 +834,7 @@ func RequestSwitchUnit(input e.SwitchUnitDto) (*d.Data, error) {
|
||||
event.Status = "failed"
|
||||
event.ErrInfo = pl.ErrorInfo{
|
||||
Code: "missing-soapi",
|
||||
Detail: fmt.Sprintf("Missing soapi from latest responsible doctor"),
|
||||
Detail: "Missing soapi from latest responsible doctor",
|
||||
}
|
||||
return pl.SetLogError(&event, input)
|
||||
}
|
||||
@@ -919,7 +919,7 @@ func ApproveSwitchUnit(input e.ApproveUnitDto) (*d.Data, error) {
|
||||
event.Status = "failed"
|
||||
event.ErrInfo = pl.ErrorInfo{
|
||||
Code: "missing-soapi",
|
||||
Detail: fmt.Sprintf("Missing soapi from latest responsible doctor"),
|
||||
Detail: "Missing soapi from latest responsible doctor",
|
||||
}
|
||||
return pl.SetLogError(&event, input)
|
||||
}
|
||||
|
||||
@@ -601,7 +601,7 @@ func getSoapiEncounterAdm(enc e.Encounter, event *pl.Event) (dataSoapi []es.Crea
|
||||
event.Status = "failed"
|
||||
event.ErrInfo = pl.ErrorInfo{
|
||||
Code: "missing-soapi",
|
||||
Detail: fmt.Sprintf("Missing required Soapi types"),
|
||||
Detail: "Missing required Soapi types",
|
||||
}
|
||||
return nil, pl.SetLogError(event, enc)
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
|
||||
"gorm.io/gorm"
|
||||
|
||||
sync "simrs-vx/internal/infra/sync-cfg"
|
||||
sync "simrs-vx/internal/infra/sync-consumer-cfg"
|
||||
|
||||
e "simrs-vx/internal/domain/main-entities/encounter"
|
||||
esync "simrs-vx/internal/domain/sync-entities/log"
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
|
||||
"gorm.io/gorm"
|
||||
|
||||
sync "simrs-vx/internal/infra/sync-cfg"
|
||||
sync "simrs-vx/internal/infra/sync-consumer-cfg"
|
||||
|
||||
e "simrs-vx/internal/domain/main-entities/installation"
|
||||
esync "simrs-vx/internal/domain/sync-entities/log"
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
|
||||
"gorm.io/gorm"
|
||||
|
||||
sync "simrs-vx/internal/infra/sync-cfg"
|
||||
sync "simrs-vx/internal/infra/sync-consumer-cfg"
|
||||
|
||||
e "simrs-vx/internal/domain/main-entities/patient"
|
||||
esync "simrs-vx/internal/domain/sync-entities/log"
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
|
||||
"gorm.io/gorm"
|
||||
|
||||
sync "simrs-vx/internal/infra/sync-cfg"
|
||||
sync "simrs-vx/internal/infra/sync-consumer-cfg"
|
||||
|
||||
e "simrs-vx/internal/domain/main-entities/specialist"
|
||||
esync "simrs-vx/internal/domain/sync-entities/log"
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
|
||||
"gorm.io/gorm"
|
||||
|
||||
sync "simrs-vx/internal/infra/sync-cfg"
|
||||
sync "simrs-vx/internal/infra/sync-consumer-cfg"
|
||||
|
||||
e "simrs-vx/internal/domain/main-entities/subspecialist"
|
||||
esync "simrs-vx/internal/domain/sync-entities/log"
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
|
||||
"gorm.io/gorm"
|
||||
|
||||
sync "simrs-vx/internal/infra/sync-cfg"
|
||||
sync "simrs-vx/internal/infra/sync-consumer-cfg"
|
||||
|
||||
e "simrs-vx/internal/domain/main-entities/unit"
|
||||
esync "simrs-vx/internal/domain/sync-entities/log"
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
"io"
|
||||
"net/http"
|
||||
|
||||
sync "simrs-vx/internal/infra/sync-cfg"
|
||||
sync "simrs-vx/internal/infra/sync-consumer-cfg"
|
||||
|
||||
e "simrs-vx/internal/domain/main-entities/division"
|
||||
elog "simrs-vx/internal/domain/sync-entities/log"
|
||||
@@ -163,5 +163,5 @@ func Delete(input *e.DeleteDto) error {
|
||||
}
|
||||
|
||||
func getPrefixEndpoint() string {
|
||||
return fmt.Sprintf("%s%s/v1/division", sync.O.Host, sync.O.Prefix)
|
||||
return fmt.Sprintf("%s%s/v1/division", sync.O.TargetHost, sync.O.Prefix)
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ package encounter
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
sync "simrs-vx/internal/infra/sync-cfg"
|
||||
sync "simrs-vx/internal/infra/sync-consumer-cfg"
|
||||
helper "simrs-vx/internal/use-case/simgos-sync-plugin/new"
|
||||
|
||||
e "simrs-vx/internal/domain/main-entities/encounter"
|
||||
@@ -50,5 +50,5 @@ func Cancel(input *e.Encounter) error {
|
||||
}
|
||||
|
||||
func getPrefixEndpoint() string {
|
||||
return fmt.Sprintf("%s%s/v1/encounter", sync.O.Host, sync.O.Prefix)
|
||||
return fmt.Sprintf("%s%s/v1/encounter", sync.O.TargetHost, sync.O.Prefix)
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
"io"
|
||||
"net/http"
|
||||
|
||||
sync "simrs-vx/internal/infra/sync-cfg"
|
||||
sync "simrs-vx/internal/infra/sync-consumer-cfg"
|
||||
|
||||
e "simrs-vx/internal/domain/main-entities/installation"
|
||||
elog "simrs-vx/internal/domain/sync-entities/log"
|
||||
@@ -163,5 +163,5 @@ func Delete(input *e.DeleteDto) error {
|
||||
}
|
||||
|
||||
func getPrefixEndpoint() string {
|
||||
return fmt.Sprintf("%s%s/v1/installation", sync.O.Host, sync.O.Prefix)
|
||||
return fmt.Sprintf("%s%s/v1/installation", sync.O.TargetHost, sync.O.Prefix)
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
|
||||
d "github.com/karincake/dodol"
|
||||
|
||||
sync "simrs-vx/internal/infra/sync-cfg"
|
||||
sync "simrs-vx/internal/infra/sync-consumer-cfg"
|
||||
|
||||
e "simrs-vx/internal/domain/main-entities/patient"
|
||||
elog "simrs-vx/internal/domain/sync-entities/log"
|
||||
@@ -203,5 +203,5 @@ func GenerateNomrPatient() (*string, error) {
|
||||
}
|
||||
|
||||
func getPrefixEndpoint() string {
|
||||
return fmt.Sprintf("%s%s/v1/patient", sync.O.Host, sync.O.Prefix)
|
||||
return fmt.Sprintf("%s%s/v1/patient", sync.O.TargetHost, sync.O.Prefix)
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
"io"
|
||||
"net/http"
|
||||
|
||||
sync "simrs-vx/internal/infra/sync-cfg"
|
||||
sync "simrs-vx/internal/infra/sync-consumer-cfg"
|
||||
|
||||
e "simrs-vx/internal/domain/main-entities/specialist"
|
||||
elog "simrs-vx/internal/domain/sync-entities/log"
|
||||
@@ -163,5 +163,5 @@ func Delete(input *e.DeleteDto) error {
|
||||
}
|
||||
|
||||
func getPrefixEndpoint() string {
|
||||
return fmt.Sprintf("%s%s/v1/specialist", sync.O.Host, sync.O.Prefix)
|
||||
return fmt.Sprintf("%s%s/v1/specialist", sync.O.TargetHost, sync.O.Prefix)
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
"io"
|
||||
"net/http"
|
||||
|
||||
sync "simrs-vx/internal/infra/sync-cfg"
|
||||
sync "simrs-vx/internal/infra/sync-consumer-cfg"
|
||||
|
||||
e "simrs-vx/internal/domain/main-entities/subspecialist"
|
||||
elog "simrs-vx/internal/domain/sync-entities/log"
|
||||
@@ -163,5 +163,5 @@ func Delete(input *e.DeleteDto) error {
|
||||
}
|
||||
|
||||
func getPrefixEndpoint() string {
|
||||
return fmt.Sprintf("%s%s/v1/subspecialist", sync.O.Host, sync.O.Prefix)
|
||||
return fmt.Sprintf("%s%s/v1/subspecialist", sync.O.TargetHost, sync.O.Prefix)
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
"io"
|
||||
"net/http"
|
||||
|
||||
sync "simrs-vx/internal/infra/sync-cfg"
|
||||
sync "simrs-vx/internal/infra/sync-consumer-cfg"
|
||||
|
||||
e "simrs-vx/internal/domain/main-entities/unit"
|
||||
elog "simrs-vx/internal/domain/sync-entities/log"
|
||||
@@ -163,5 +163,5 @@ func Delete(input *e.DeleteDto) error {
|
||||
}
|
||||
|
||||
func getPrefixEndpoint() string {
|
||||
return fmt.Sprintf("%s%s/v1/unit", sync.O.Host, sync.O.Prefix)
|
||||
return fmt.Sprintf("%s%s/v1/unit", sync.O.TargetHost, sync.O.Prefix)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user