沙尘暴 / configloader
此包的最新版本(1.0.0)没有可用的许可证信息。
1.0.0
2019-03-06 22:23 UTC
Requires
- neos/flow: *
This package is auto-updated.
Last update: 2024-09-07 15:58:43 UTC
README
此包能够从外部源(如文件)加载类型为Settings的配置。它还可以重新格式化存储在环境变量中的凭据(例如JSON格式),以便Flow可以使用。它是100%可扩展的,因此您可以定义自己的源和转换。
使用此包
此包是为以下用例开发的:需要在一个云提供商的虚拟机上运行Flow应用程序。此云提供商将环境信息(如数据库名称和密码)存储在JSON格式的环境变量中。以下是一个简短的示例
{
"databases": [
{
"label": "mariadb",
"name": "cf-neos-db",
"instance_name": "cf-neos-db",
"credentials": {
"hostname": "foo.example.com",
"name": "DBNAME_ASDF1234",
"username": "username",
"password": "password"
}
}
]
}
假设这些信息存储在一个名为SERVICES
的环境变量中。此包的任务是在Flow的启动过程中早期挂钩,读取环境变量,将JSON转换为关联数组,并将其注入到常规配置中。以下是完成此任务所需的配置
Sandstorm:
ConfigLoader:
externalConfig:
# This key can be chosen arbitrarily for each config source
'MyJson':
# The source's job is to read config from somewhere.
# The EnvSource is capable of reading an environment variable.
source: Sandstorm\ConfigLoader\Source\EnvSource
sourceOptions:
name: 'SERVICES'
# A transformation transforms the value provided by source.
# The JsonTransformation parses a JSON string and returns an
# associative array that is stored by this package.
transformation: Sandstorm\ConfigLoader\Transformation\JsonTransformation
# Now, you can inject the loaded transformation into the place where you want
# it to be. Use this format:
# %EXT:ExternalConfigKey.some.path%
Neos:
Flow:
persistence:
backendOptions:
host: '%EXT:MyJson.databases.0.credentials.hostname%'
dbname: '%EXT:MyJson.databases.0.credentials.name%'
user: '%EXT:MyJson.databases.0.credentials.username%'
password: '%EXT:MyJson.databases.0.credentials.password%'
如果您删除缓存并显示配置,您将看到以下内容。凭据已从JSON中解析出来并注入到配置中。
./flow configuration:show --path Neos.Flow.persistence.backendOptions
Configuration "Settings: Neos.Flow.persistence.backendOptions":
host: foo.example.com
dbname: DBNAME_ASDF1234
user: username
password: password
可扩展性
创建自己的自定义源和转换非常简单。只需让它们实现此包提供的SourceInterface
/ TransformationInterface
,并按照上述示例进行配置。这样,您可以从任何源加载任何配置格式(XML、JSON、...)。
待办事项
此包忽略了应用程序上下文,并在开发或生产(或任何其他)上下文中注入相同的值。这是一个缺少的功能。