mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-27 00:33:10 -06:00
- Use the ConnectionString in the YAML to include the Tenant - Revert all other non implemented tables back to use SQLLite3
51 lines
1.5 KiB
Go
51 lines
1.5 KiB
Go
package cosmosdbutil
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"github.com/matrix-org/dendrite/internal/cosmosdbapi"
|
|
"github.com/matrix-org/dendrite/setup/config"
|
|
)
|
|
|
|
const accountEndpointName = "AccountEndpoint"
|
|
const accountKeyName = "AccountKey"
|
|
const databaseName = "DatabaseName"
|
|
const containerName = "ContainerName"
|
|
|
|
func getConnectionString(d *config.DataSource) config.DataSource {
|
|
var connString string
|
|
connString = string(*d)
|
|
return config.DataSource(strings.Replace(connString, "cosmosdb:", "", 1))
|
|
}
|
|
|
|
func getConnectionProperties(connectionString string) map[string]string {
|
|
connectionItemsRaw := strings.Split(connectionString, ";")
|
|
connectionItems := map[string]string{}
|
|
for _, item := range connectionItemsRaw {
|
|
if len(item) > 0 {
|
|
itemSplit := strings.SplitN(item, "=", 2)
|
|
connectionItems[itemSplit[0]] = itemSplit[1]
|
|
}
|
|
}
|
|
return connectionItems
|
|
}
|
|
|
|
func GetCosmosConnection(d *config.DataSource) cosmosdbapi.CosmosConnection {
|
|
connString := getConnectionString(d)
|
|
connMap := getConnectionProperties(string(connString))
|
|
accountEndpoint := connMap[accountEndpointName]
|
|
accountKey := connMap[accountKeyName]
|
|
return cosmosdbapi.GetCosmosConnection(accountEndpoint, accountKey)
|
|
}
|
|
|
|
func GetCosmosConfig(d *config.DataSource) cosmosdbapi.CosmosConfig {
|
|
connString := getConnectionString(d)
|
|
connMap := getConnectionProperties(string(connString))
|
|
database := connMap[databaseName]
|
|
container := connMap[containerName]
|
|
return cosmosdbapi.CosmosConfig{
|
|
DatabaseName: database,
|
|
ContainerName: container,
|
|
}
|
|
}
|