mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-29 01:33:10 -06:00
- Add DisableCertificateValidation to the config (#21)
- Use the value in the HTTP Connection to not validate the cert Co-authored-by: alexf@example.com <alexf@example.com>
This commit is contained in:
parent
1a5d7f2bb2
commit
2e168ee5ea
|
|
@ -2,7 +2,9 @@ package cosmosdbapi
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"crypto/tls"
|
||||||
"errors"
|
"errors"
|
||||||
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
|
@ -12,19 +14,28 @@ import (
|
||||||
type CosmosConnection struct {
|
type CosmosConnection struct {
|
||||||
Url string
|
Url string
|
||||||
Key string
|
Key string
|
||||||
|
DisableCertificateValidation bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetCosmosConnection(accountEndpoint string, accountKey string) CosmosConnection {
|
func GetCosmosConnection(accountEndpoint string, accountKey string, disableCertificateValidation bool) CosmosConnection {
|
||||||
return CosmosConnection{
|
return CosmosConnection{
|
||||||
Url: accountEndpoint,
|
Url: accountEndpoint,
|
||||||
Key: accountKey,
|
Key: accountKey,
|
||||||
|
DisableCertificateValidation: disableCertificateValidation,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func disableCertificateValidation() {
|
||||||
|
http.DefaultTransport.(*http.Transport).TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
|
||||||
|
}
|
||||||
|
|
||||||
func GetClient(conn CosmosConnection) *cosmosapi.Client {
|
func GetClient(conn CosmosConnection) *cosmosapi.Client {
|
||||||
cfg := cosmosapi.Config{
|
cfg := cosmosapi.Config{
|
||||||
MasterKey: conn.Key,
|
MasterKey: conn.Key,
|
||||||
}
|
}
|
||||||
|
if conn.DisableCertificateValidation {
|
||||||
|
disableCertificateValidation()
|
||||||
|
}
|
||||||
return cosmosapi.New(conn.Url, cfg, nil, nil)
|
return cosmosapi.New(conn.Url, cfg, nil, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
package cosmosdbutil
|
package cosmosdbutil
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/matrix-org/dendrite/internal/cosmosdbapi"
|
"github.com/matrix-org/dendrite/internal/cosmosdbapi"
|
||||||
|
|
@ -12,10 +13,10 @@ const accountKeyName = "AccountKey"
|
||||||
const databaseName = "DatabaseName"
|
const databaseName = "DatabaseName"
|
||||||
const containerName = "ContainerName"
|
const containerName = "ContainerName"
|
||||||
const tenantName = "TenantName"
|
const tenantName = "TenantName"
|
||||||
|
const disableCertificateValidationName = "DisableCertificateValidation"
|
||||||
|
|
||||||
func getConnectionString(d *config.DataSource) config.DataSource {
|
func getConnectionString(d *config.DataSource) config.DataSource {
|
||||||
var connString string
|
connString := string(*d)
|
||||||
connString = string(*d)
|
|
||||||
return config.DataSource(strings.Replace(connString, "cosmosdb:", "", 1))
|
return config.DataSource(strings.Replace(connString, "cosmosdb:", "", 1))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -36,7 +37,15 @@ func GetCosmosConnection(d *config.DataSource) cosmosdbapi.CosmosConnection {
|
||||||
connMap := getConnectionProperties(string(connString))
|
connMap := getConnectionProperties(string(connString))
|
||||||
accountEndpoint := connMap[accountEndpointName]
|
accountEndpoint := connMap[accountEndpointName]
|
||||||
accountKey := connMap[accountKeyName]
|
accountKey := connMap[accountKeyName]
|
||||||
return cosmosdbapi.GetCosmosConnection(accountEndpoint, accountKey)
|
value, ok := connMap[disableCertificateValidationName]
|
||||||
|
disableCertificateValidation := false
|
||||||
|
if ok {
|
||||||
|
valueBool, err := strconv.ParseBool(value)
|
||||||
|
if err == nil {
|
||||||
|
disableCertificateValidation = valueBool
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return cosmosdbapi.GetCosmosConnection(accountEndpoint, accountKey, disableCertificateValidation)
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetCosmosConfig(d *config.DataSource) cosmosdbapi.CosmosConfig {
|
func GetCosmosConfig(d *config.DataSource) cosmosdbapi.CosmosConfig {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue