-
-
Notifications
You must be signed in to change notification settings - Fork 415
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: properly parse includes outside the Configuration plugin
Signed-off-by: Valery Piashchynski <[email protected]>
- Loading branch information
Showing
5 changed files
with
106 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package rpc | ||
|
||
import ( | ||
"github.com/roadrunner-server/errors" | ||
"github.com/spf13/viper" | ||
) | ||
|
||
const ( | ||
versionKey string = "version" | ||
includeKey string = "include" | ||
defaultConfigVersion string = "3" | ||
prevConfigVersion string = "2.7" | ||
) | ||
|
||
func getConfiguration(path string) (map[string]any, string, error) { | ||
v := viper.New() | ||
v.SetConfigFile(path) | ||
err := v.ReadInConfig() | ||
if err != nil { | ||
return nil, "", err | ||
} | ||
|
||
// get configuration version | ||
ver := v.Get(versionKey) | ||
if ver == nil { | ||
return nil, "", errors.Str("rr configuration file should contain a version e.g: version: 2.7") | ||
} | ||
|
||
if _, ok := ver.(string); !ok { | ||
return nil, "", errors.Errorf("type of version should be string, actual: %T", ver) | ||
} | ||
|
||
// automatically inject ENV variables using ${ENV} pattern | ||
expandEnvViper(v) | ||
|
||
return v.AllSettings(), ver.(string), nil | ||
} | ||
|
||
func handleInclude(rootVersion string, v *viper.Viper) error { | ||
ifiles := v.GetStringSlice(includeKey) | ||
if ifiles == nil { | ||
return nil | ||
} | ||
|
||
for _, file := range ifiles { | ||
config, version, err := getConfiguration(file) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if version != rootVersion { | ||
return errors.Str("version in included file must be the same as in root") | ||
} | ||
|
||
// overriding configuration | ||
for key, val := range config { | ||
v.Set(key, val) | ||
} | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
version: "3" | ||
|
||
rpc: | ||
listen: tcp://127.0.0.1:6010 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
version: "3" | ||
|
||
server: | ||
command: "php app-with-domain-specific-routes.php" | ||
|
||
logs: | ||
level: debug | ||
mode: development | ||
|
||
include: | ||
- test/include1/.rr-include.yaml |