mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-12 09:23:09 -06:00
Application Service config file parsing
Signed-off-by: Andrew Morgan (https://amorgan.xyz) <andrew@amorgan.xyz>
This commit is contained in:
parent
00ef2e79eb
commit
0a8d2325d3
|
|
@ -120,3 +120,7 @@ tracing:
|
|||
# for documtation.
|
||||
jaeger:
|
||||
disabled: true
|
||||
|
||||
# A list of application service config files to use
|
||||
applicationservice:
|
||||
app_service_config_files:
|
||||
|
|
|
|||
|
|
@ -0,0 +1,79 @@
|
|||
// Copyright 2017 Andrew Morgan <andrew@amorgan.xyz>
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package config
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"path/filepath"
|
||||
|
||||
"gopkg.in/yaml.v2"
|
||||
)
|
||||
|
||||
// ApplicationServiceNamespace is the namespace that a specific application
|
||||
// service has management over.
|
||||
type ApplicationServiceNamespace struct {
|
||||
// Whether or not the namespace is managed solely by this application service
|
||||
Exclusive bool `yaml:"exclusive"`
|
||||
// A regex pattern that represents the namespace
|
||||
Regex string `yaml:"regex"`
|
||||
}
|
||||
|
||||
// ApplicationService represents a Matrix application service.
|
||||
// https://matrix.org/docs/spec/application_service/unstable.html
|
||||
type ApplicationService struct {
|
||||
// User-defined, unique, persistent ID of the application service
|
||||
ID string `yaml:"id"`
|
||||
// Base URL of the application service
|
||||
URL string `yaml:"url"`
|
||||
// Application service token provided in requests to a homeserver
|
||||
ASToken string `yaml:"as_token"`
|
||||
// Homeserver token provided in requests to an application service
|
||||
HSToken string `yaml:"hs_token"`
|
||||
// Localpart of application service user
|
||||
SenderLocalpart string `yaml:"sender_localpart"`
|
||||
// Information about an application service's namespaces
|
||||
Namespaces map[string][]interface{} `yaml:"namespaces"`
|
||||
}
|
||||
|
||||
func loadAppservices(config *Dendrite) error {
|
||||
// Iterate through and return all the Application Services
|
||||
for _, configPath := range config.ApplicationService.ConfigFiles {
|
||||
// Create a new application service
|
||||
var appservice ApplicationService
|
||||
|
||||
// Create an absolute path from a potentially relative path
|
||||
absPath, err := filepath.Abs(configPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Read the application service's config file
|
||||
configData, err := ioutil.ReadFile(absPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Load the config data into our struct
|
||||
if err = yaml.UnmarshalStrict(configData, &appservice); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Append the parsed application service to the global config
|
||||
config.Derived.ApplicationServices = append(
|
||||
config.Derived.ApplicationServices, appservice)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
@ -206,6 +206,13 @@ type Dendrite struct {
|
|||
Jaeger jaegerconfig.Configuration `yaml:"jaeger"`
|
||||
}
|
||||
|
||||
// Application Services
|
||||
// https://matrix.org/docs/spec/application_service/unstable.html
|
||||
ApplicationService struct {
|
||||
// Configuration files for various application services
|
||||
ConfigFiles []string `yaml:"app_service_config_files"`
|
||||
}
|
||||
|
||||
// Any information derived from the configuration options for later use.
|
||||
Derived struct {
|
||||
Registration struct {
|
||||
|
|
@ -219,6 +226,10 @@ type Dendrite struct {
|
|||
// registration in order to complete registration stages.
|
||||
Params map[string]interface{} `json:"params"`
|
||||
}
|
||||
|
||||
// Application Services parsed from their config files
|
||||
// The paths of which were given above in the main config file
|
||||
ApplicationServices []ApplicationService
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -360,6 +371,14 @@ func (config *Dendrite) derive() {
|
|||
config.Derived.Registration.Flows = append(config.Derived.Registration.Flows,
|
||||
authtypes.Flow{Stages: []authtypes.LoginType{authtypes.LoginTypeDummy}})
|
||||
}
|
||||
|
||||
// Load application service configuration files
|
||||
fmt.Println(config.ApplicationService.ConfigFiles)
|
||||
if len(config.ApplicationService.ConfigFiles) > 0 {
|
||||
if err := loadAppservices(config); err != nil {
|
||||
fmt.Println("Error loading AS config: ", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// setDefaults sets default config values if they are not explicitly set.
|
||||
|
|
|
|||
Loading…
Reference in a new issue