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:
@@ -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))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user