Skip to content

Commit

Permalink
Store authentication keys in a separate database
Browse files Browse the repository at this point in the history
Signed-off-by: gatici <[email protected]>
  • Loading branch information
gatici committed Feb 15, 2024
1 parent 05ee1ff commit 4ea0bf0
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 12 deletions.
5 changes: 3 additions & 2 deletions factory/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,9 @@ type Tls struct {
}

type Mongodb struct {
Name string `yaml:"name"`
Url string `yaml:"url"`
Name string `yaml:"name"`
Url string `yaml:"url"`
AuthKeysDbName string `yaml:"authKeysDbName"`
}

var ConfigPodTrigger chan bool
Expand Down
8 changes: 4 additions & 4 deletions producer/data_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ func HandleModifyAuthentication(request *httpwrapper.Request) *httpwrapper.Respo

func ModifyAuthenticationProcedure(collName string, ueId string, patchItem []models.PatchItem) *models.ProblemDetails {
filter := bson.M{"ueId": ueId}
origValue, errGetOne := CommonDBClient.RestfulAPIGetOne(collName, filter)
origValue, errGetOne := AuthDBClient.RestfulAPIGetOne(collName, filter)
if errGetOne != nil {
logger.DataRepoLog.Warnln(errGetOne)
}
Expand All @@ -386,10 +386,10 @@ func ModifyAuthenticationProcedure(collName string, ueId string, patchItem []mod
if err != nil {
logger.DataRepoLog.Error(err)
}
failure := CommonDBClient.RestfulAPIJSONPatch(collName, filter, patchJSON)
failure := AuthDBClient.RestfulAPIJSONPatch(collName, filter, patchJSON)

if failure == nil {
newValue, errGetOneNew := CommonDBClient.RestfulAPIGetOne(collName, filter)
newValue, errGetOneNew := AuthDBClient.RestfulAPIGetOne(collName, filter)
if errGetOneNew != nil {
logger.DataRepoLog.Warnln(errGetOneNew)
}
Expand Down Expand Up @@ -421,7 +421,7 @@ func HandleQueryAuthSubsData(request *httpwrapper.Request) *httpwrapper.Response
func QueryAuthSubsDataProcedure(collName string, ueId string) (map[string]interface{}, *models.ProblemDetails) {
filter := bson.M{"ueId": ueId}

authenticationSubscription, errGetOne := CommonDBClient.RestfulAPIGetOne(collName, filter)
authenticationSubscription, errGetOne := AuthDBClient.RestfulAPIGetOne(collName, filter)
if errGetOne != nil {
logger.DataRepoLog.Warnln(errGetOne)
}
Expand Down
16 changes: 11 additions & 5 deletions producer/db_adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,28 +30,34 @@ type DBInterface interface {
}

var CommonDBClient DBInterface
var AuthDBClient DBInterface

type MongoDBClient struct {
mongoapi.MongoClient
}

func getMongoClient(url string, dbname string) error {
func getMongoClient(url string, dbname string, dbclient DBInterface) error {

Check failure on line 39 in producer/db_adapter.go

View workflow job for this annotation

GitHub Actions / lint

SA4009: argument dbclient is overwritten before first use (staticcheck)
var mClient, errConnect = mongoapi.NewMongoClient(url, dbname)
if mClient.Client != nil {
CommonDBClient = mClient
CommonDBClient.(*mongoapi.MongoClient).Client.Database(dbname)
dbclient = mClient

Check failure on line 42 in producer/db_adapter.go

View workflow job for this annotation

GitHub Actions / lint

SA4009(related information): assignment to dbclient (staticcheck)
dbclient.(*mongoapi.MongoClient).Client.Database(dbname)
}
return errConnect
}

func ConnectMongo(url string, dbname string) {
func ConnectMongo(url string, dbname string, authkeysdbname string) {
// Connect to MongoDB
ticker := time.NewTicker(2 * time.Second)
defer func() { ticker.Stop() }()
timer := time.After(180 * time.Second)
ConnectMongo:
for {
if err := getMongoClient(url, dbname); err == nil {
if err := getMongoClient(url, dbname, CommonDBClient); err == nil {
logger.DataRepoLog.Warnf("Could not connect to database %+v: %+v", dbname, err)
break ConnectMongo
}
if err := getMongoClient(url, authkeysdbname, AuthDBClient); err == nil {
logger.DataRepoLog.Warnf("Could not connect to database %+v: %+v", authkeysdbname, err)
break ConnectMongo
}
select {
Expand Down
2 changes: 1 addition & 1 deletion service/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func (udr *UDR) Start() {
initLog.Infof("UDR Config Info: Version[%s] Description[%s]", config.Info.Version, config.Info.Description)

// Connect to MongoDB
producer.ConnectMongo(mongodb.Url, mongodb.Name)
producer.ConnectMongo(mongodb.Url, mongodb.Name, mongodb.AuthKeysDbName)
initLog.Infoln("Server started")

router := logger_util.NewGinWithLogrus(logger.GinLog)
Expand Down

0 comments on commit 4ea0bf0

Please sign in to comment.