代码之家  ›  专栏  ›  技术社区  ›  IsaacK

如何设置Pivotal Cloud Foundry配置服务器以使用来自git repo的多个搜索路径?

  •  0
  • IsaacK  · 技术社区  · 7 年前

    我有一个本地配置服务器,它可以与yml配置这样的设置?

    spring:
      cloud:
        config:
          server:
            git:
              uri: https://github.com/xxx/xxxxx
              search-paths:
              - 'kenya*' 
              - 'tanzania*' 
              - 'uganda*' 
              - 'congo*'
              - 'zimbabwe*'
    

    在我的本地项目中,我可以像

    http://localhost:8888/uganda/dev

    这将返回所选配置文件的正确文件。

    但是,当我设置Pivotal配置服务器时,无论向路径中添加什么参数,我都只获取默认属性。

    像这样的东西 https://configserver.cfapps.io/uganda/dev 仅返回回购协议根目录下的默认属性。

    我如何使用

    此处说明的搜索路径 https://docs.run.pivotal.io/spring-cloud-services/config-server/configuring-with-git.html

    添加所有子文件夹的标志?

    0 回复  |  直到 7 年前
        1
  •  1
  •   Daniel Mikusa    7 年前

    如果您使用的是关键的Spring云服务,那么可以使用多个 searchPaths 这样地:

    cf create-service -c '{ "git": { "uri": "https://github.com/dmikusa-pivotal/cook-config.git", "label": "search-paths", "searchPaths": "dev,prod" } }' cook-config-server
    

    这个 搜索路径 参数只接受以逗号分隔的搜索路径/模式列表。

    然后,指向的存储库应该具有名为 dev 和 prod . 配置服务器将返回 <app-name>.properties (它支持的所有其他变体)在“搜索路径”文件夹中。

    通过运行以下命令,可以验证是否接收到多个搜索路径值的数据:

    curl -k -H "Authorization: bearer $(curl -k -s -X POST 'https://p-spring-cloud-services.uaa.<system_domain>/oauth/token' -d 'grant_type=client_credentials&client_id=<insert client id>&client_secret=<insert client_secret>' | jq .access_token | cut -d '"' -f 2)" <insert uri>/cook/prod
    

    你需要替换 <system_domain> 以系统域为基础, <insert client id> 和 <insert client secret> 使用服务实例的客户端id和机密(运行 cf env <app> 针对具有绑定SCS配置服务器以获取这些值的应用程序)。

    这个命令可以做两件事。首先,它将使用 client_id 和 client_secret 去拿一个代币。然后,在第二个请求中使用该令牌从配置服务器实际请求一些数据。

    如果从多个搜索路径获取配置,则应该看到这样的输出(注意 开发 和 产品 子文件夹):

    {"name":"cook","profiles":["prod"],"label":null,"version":"5d5a3f26022dd00becdbad855c7d27ae530685f7","state":null,"propertySources":[{"name":"https://github.com/dmikusa-pivotal/cook-config.git/prod/cook.properties","source":{"cook.special":"Prod Config"}},{"name":"https://github.com/dmikusa-pivotal/cook-config.git/dev/cook.properties","source":{"cook.special":"Dev Config"}},{"name":"https://github.com/dmikusa-pivotal/cook-config.git/cook.properties","source":{"cook.special":"Not in Folder config"}}]}
    

    希望能有帮助!

    推荐文章