Compare commits

...

5 Commits

Author SHA1 Message Date
Cedric Verstraeten
3af1df5b19 set realtime processing to false 2024-10-23 16:08:29 +02:00
Cedric Verstraeten
acf06e6e63 fix database client #2 2024-10-21 20:44:31 +02:00
Cedric Verstraeten
3f43e15cc2 fix database client 2024-10-21 20:41:31 +02:00
Cedric Verstraeten
c14683ec0d update database client 2024-10-18 15:48:04 +02:00
Cédric Verstraeten
213aaa5c15 update agent to 3.2.3 2024-09-14 19:34:19 +02:00
4 changed files with 50 additions and 25 deletions

View File

@@ -16,7 +16,7 @@ spec:
spec:
containers:
- name: agent
image: kerberos/agent:latest
image: kerberos/agent:3.2.3
ports:
- containerPort: 80
protocol: TCP
@@ -50,4 +50,4 @@ spec:
- port: 80
targetPort: 80
selector:
app: agent
app: agent

View File

@@ -115,6 +115,6 @@
"hub_site": "",
"condition_uri": "",
"encryption": {},
"realtimeprocessing": "true",
"realtimeprocessing": "false",
"realtimeprocessing_topic": ""
}

View File

@@ -59,7 +59,7 @@ func OpenConfig(configDirectory string, configuration *models.Configuration) {
// Write to mongodb
client := database.New()
db := client.Database(database.DatabaseName)
db := client.Client.Database(database.DatabaseName)
collection := db.Collection("configuration")
var globalConfig models.Config
@@ -525,7 +525,7 @@ func StoreConfig(configDirectory string, config models.Config) error {
// Write to mongodb
client := database.New()
db := client.Database(database.DatabaseName)
db := client.Client.Database(database.DatabaseName)
collection := db.Collection("configuration")
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)

View File

@@ -15,12 +15,19 @@ type DB struct {
Client *mongo.Client
}
var TIMEOUT = 10 * time.Second
var _init_ctx sync.Once
var _instance *DB
var DatabaseName = "KerberosFactory"
func New() *mongo.Client {
var DatabaseName = os.Getenv("MONGODB_DATABASE_FACTORY")
func New() *DB {
if DatabaseName == "" {
DatabaseName = "KerberosFactory"
}
mongodbURI := os.Getenv("MONGODB_URI")
host := os.Getenv("MONGODB_HOST")
databaseCredentials := os.Getenv("MONGODB_DATABASE_CREDENTIALS")
replicaset := os.Getenv("MONGODB_REPLICASET")
@@ -28,28 +35,46 @@ func New() *mongo.Client {
password := os.Getenv("MONGODB_PASSWORD")
authentication := "SCRAM-SHA-256"
ctx, cancel := context.WithTimeout(context.Background(), TIMEOUT)
defer cancel()
_init_ctx.Do(func() {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
_instance = new(DB)
mongodbURI := fmt.Sprintf("mongodb://%s:%s@%s", username, password, host)
if replicaset != "" {
mongodbURI = fmt.Sprintf("%s/?replicaSet=%s", mongodbURI, replicaset)
}
client, err := mongo.Connect(ctx, options.Client().ApplyURI(mongodbURI).SetAuth(options.Credential{
AuthMechanism: authentication,
AuthSource: databaseCredentials,
Username: username,
Password: password,
}))
if err != nil {
fmt.Printf("Error setting up mongodb connection: %+v\n", err)
os.Exit(1)
// We can also apply the complete URI
// e.g. "mongodb+srv://<username>:<password>@kerberos-hub.shhng.mongodb.net/?retryWrites=true&w=majority&appName=kerberos-hub"
if mongodbURI != "" {
serverAPI := options.ServerAPI(options.ServerAPIVersion1)
opts := options.Client().ApplyURI(mongodbURI).SetServerAPIOptions(serverAPI)
// Create a new client and connect to the server
client, err := mongo.Connect(ctx, opts)
if err != nil {
fmt.Printf("Error setting up mongodb connection: %+v\n", err)
os.Exit(1)
}
_instance.Client = client
} else {
// New MongoDB driver
mongodbURI := fmt.Sprintf("mongodb://%s:%s@%s", username, password, host)
if replicaset != "" {
mongodbURI = fmt.Sprintf("%s/?replicaSet=%s", mongodbURI, replicaset)
}
client, err := mongo.Connect(ctx, options.Client().ApplyURI(mongodbURI).SetAuth(options.Credential{
AuthMechanism: authentication,
AuthSource: databaseCredentials,
Username: username,
Password: password,
}))
if err != nil {
fmt.Printf("Error setting up mongodb connection: %+v\n", err)
os.Exit(1)
}
_instance.Client = client
}
_instance.Client = client
})
return _instance.Client
return _instance
}