mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-11 08:53:11 -06:00
Resolve relative paths against the current working directory
This commit is contained in:
parent
72717e1016
commit
a3ca843d39
|
|
@ -33,6 +33,7 @@ import (
|
||||||
const Version = "v0"
|
const Version = "v0"
|
||||||
|
|
||||||
// Dendrite contains all the config used by a dendrite process.
|
// Dendrite contains all the config used by a dendrite process.
|
||||||
|
// Relative paths are resolved relative to the current working directory
|
||||||
type Dendrite struct {
|
type Dendrite struct {
|
||||||
// The version of the configuration file.
|
// The version of the configuration file.
|
||||||
Version string `yaml:"version"`
|
Version string `yaml:"version"`
|
||||||
|
|
@ -42,16 +43,12 @@ type Dendrite struct {
|
||||||
// The name of the server. This is usually the domain name, e.g 'matrix.org', 'localhost'.
|
// The name of the server. This is usually the domain name, e.g 'matrix.org', 'localhost'.
|
||||||
ServerName gomatrixserverlib.ServerName `yaml:"server_name"`
|
ServerName gomatrixserverlib.ServerName `yaml:"server_name"`
|
||||||
// Path to the private key which will be used to sign requests and events.
|
// Path to the private key which will be used to sign requests and events.
|
||||||
// The path may be relative or absolute.
|
|
||||||
// Relative paths are resolved relative to the directory containing the config file.
|
|
||||||
PrivateKeyPath Path `yaml:"private_key"`
|
PrivateKeyPath Path `yaml:"private_key"`
|
||||||
// List of paths to X509 certificates used by the external federation listeners.
|
// List of paths to X509 certificates used by the external federation listeners.
|
||||||
// These are used to calculate the TLS fingerprints to publish for this server.
|
// These are used to calculate the TLS fingerprints to publish for this server.
|
||||||
// Other matrix servers talking to this server will expect the x509 certificate
|
// Other matrix servers talking to this server will expect the x509 certificate
|
||||||
// to match one of these certificates.
|
// to match one of these certificates.
|
||||||
// The certificates should be in PEM format.
|
// The certificates should be in PEM format.
|
||||||
// The path may be relative or absolute.
|
|
||||||
// Relative paths are resolved relative to the directory containing the config file.
|
|
||||||
FederationCertificatePaths []Path `yaml:"federation_certificates"`
|
FederationCertificatePaths []Path `yaml:"federation_certificates"`
|
||||||
// The private key which will be used to sign requests and events.
|
// The private key which will be used to sign requests and events.
|
||||||
PrivateKey ed25519.PrivateKey `yaml:"-"`
|
PrivateKey ed25519.PrivateKey `yaml:"-"`
|
||||||
|
|
@ -71,7 +68,6 @@ type Dendrite struct {
|
||||||
// The configuration specific to the media repostitory.
|
// The configuration specific to the media repostitory.
|
||||||
Media struct {
|
Media struct {
|
||||||
// The base path to where the media files will be stored. May be relative or absolute.
|
// The base path to where the media files will be stored. May be relative or absolute.
|
||||||
// Relative paths are resolved relative to the directory containing the config file.
|
|
||||||
BasePath Path `yaml:"base_path"`
|
BasePath Path `yaml:"base_path"`
|
||||||
// The absolute base path to where media files will be stored.
|
// The absolute base path to where media files will be stored.
|
||||||
AbsBasePath Path `yaml:"-"`
|
AbsBasePath Path `yaml:"-"`
|
||||||
|
|
@ -154,7 +150,7 @@ func Load(configPath string) (*Dendrite, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
configDirPath, err := filepath.Abs(filepath.Dir(configPath))
|
configDirPath, err := filepath.Abs(".")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
@ -168,7 +164,7 @@ type Error struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func loadConfig(
|
func loadConfig(
|
||||||
configDirPath string,
|
basePath string,
|
||||||
configData []byte,
|
configData []byte,
|
||||||
readFile func(string) ([]byte, error),
|
readFile func(string) ([]byte, error),
|
||||||
) (*Dendrite, error) {
|
) (*Dendrite, error) {
|
||||||
|
|
@ -184,7 +180,7 @@ func loadConfig(
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
privateKeyPath := absPath(configDirPath, config.Matrix.PrivateKeyPath)
|
privateKeyPath := absPath(basePath, config.Matrix.PrivateKeyPath)
|
||||||
privateKeyData, err := readFile(privateKeyPath)
|
privateKeyData, err := readFile(privateKeyPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
@ -195,7 +191,7 @@ func loadConfig(
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, certPath := range config.Matrix.FederationCertificatePaths {
|
for _, certPath := range config.Matrix.FederationCertificatePaths {
|
||||||
absCertPath := absPath(configDirPath, certPath)
|
absCertPath := absPath(basePath, certPath)
|
||||||
pemData, err := readFile(absCertPath)
|
pemData, err := readFile(absCertPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
@ -207,7 +203,7 @@ func loadConfig(
|
||||||
config.Matrix.TLSFingerPrints = append(config.Matrix.TLSFingerPrints, *fingerprint)
|
config.Matrix.TLSFingerPrints = append(config.Matrix.TLSFingerPrints, *fingerprint)
|
||||||
}
|
}
|
||||||
|
|
||||||
config.Media.AbsBasePath = Path(absPath(configDirPath, config.Media.BasePath))
|
config.Media.AbsBasePath = Path(absPath(basePath, config.Media.BasePath))
|
||||||
|
|
||||||
return &config, nil
|
return &config, nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue