├── .gitignore
├── .mvn
└── wrapper
│ ├── maven-wrapper.jar
│ └── maven-wrapper.properties
├── .settings.xml
├── .travis.yml
├── LICENSE
├── LICENSE.txt
├── README.md
├── mvnw
├── mvnw.cmd
├── pom.xml
└── src
├── main
└── java
│ └── org
│ └── springframework
│ └── cloud
│ └── config
│ └── server
│ └── mongodb
│ ├── EnableMongoConfigServer.java
│ ├── config
│ └── MongoEnvironmentRepositoryConfiguration.java
│ └── environment
│ └── MongoEnvironmentRepository.java
└── test
└── java
└── org
└── springframework
└── cloud
└── config
└── server
└── mongodb
├── MongoConfigServerTests.java
└── environment
└── MongoEnvironmentRepositoryTests.java
/.gitignore:
--------------------------------------------------------------------------------
1 | *~
2 | #*
3 | *#
4 | .#*
5 | .classpath
6 | .project
7 | .settings/
8 | .springBeans
9 | target/
10 | bin/
11 | _site/
12 | .idea
13 | *.iml
14 | *.ipr
15 | *.iws
16 | .factorypath
17 | work
18 |
--------------------------------------------------------------------------------
/.mvn/wrapper/maven-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/spring-attic/spring-cloud-config-server-mongodb/2eb1bcac238a4db84266eddd65b66efb098b59a2/.mvn/wrapper/maven-wrapper.jar
--------------------------------------------------------------------------------
/.mvn/wrapper/maven-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.3.3/apache-maven-3.3.3-bin.zip
--------------------------------------------------------------------------------
/.settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
8 | ojo-central
9 | ${env.OJO_USERNAME}
10 | ${env.OJO_PASSWORD}
11 |
12 |
13 | ojo-snapshots
14 | ${env.OJO_USERNAME}
15 | ${env.OJO_PASSWORD}
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | dist: precise
2 | sudo: false
3 | cache:
4 | directories:
5 | - $HOME/.m2
6 | language: java
7 | jdk:
8 | - oraclejdk8
9 | install:
10 | - wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-${MONGODB}.tgz
11 | - tar zxf mongodb-linux-x86_64-${MONGODB}.tgz
12 | - ${PWD}/mongodb-linux-x86_64-${MONGODB}/bin/mongod --version
13 | - ./mvnw clean install -DskipTests=true -Dmaven.javadoc.skip=true -B -V -U
14 | before_script:
15 | - mkdir ${PWD}/mongodb-linux-x86_64-${MONGODB}/data
16 | - ${PWD}/mongodb-linux-x86_64-${MONGODB}/bin/mongod --dbpath ${PWD}/mongodb-linux-x86_64-${MONGODB}/data --logpath ${PWD}/mongodb-linux-x86_64-${MONGODB}/mongodb.log --fork
17 | after_script:
18 | - pkill mongod
19 | script:
20 | - '[ "${TRAVIS_BRANCH}" = master ] && [ "${TRAVIS_PULL_REQUEST}" != "false" ] || ./mvnw -s .settings.xml clean verify deploy'
21 | - '[ "${TRAVIS_PULL_REQUEST}" = "false" ] || ./mvnw clean verify'
22 | env:
23 | matrix:
24 | - MONGODB=3.2.20
25 | - MONGODB=3.4.16
26 | - MONGODB=3.6.6
27 | - MONGODB=4.0.0
28 | global:
29 | - secure: I0jAQdcRp1fu0se0Pqa2QuKRJrdqW1rPNuJdrpNsbqF1AGDOuHMjjjlZdIsSjRbCHNn1/R1igMSncaIQ+yASPJdAs9sQ7hUkvW/vitfLKvS7J51KSmblzPak7f6hE2VS10TfnKTJweWFKMpOX+OKiesNox+jdWDJk6TtjydTQLzPPXPdZZXEG//8OtjVIflRgJcT0xFSyiCaJFzyB/tai3wN6WDSGqyfs2FQfZdw+gcK4r6ZrdjXwA8w3S5wS8EyaTA1I6S/hCbDV9tpwEAAQQU3QUFs6YJ54pglm3KtguZIezySkJmNMixAvZ1xbW/sO1w7rWVD0eOwt2xa3HFiIKZmFnjj0c/MZ5mPPOYX2DcZ49mtP8lzWhcSjL1Q7myoErucxLDAInJ1u3/JCPy2QKB5YHUYXd2IT4qINMdEQFeOfRKFsBBjWpE+yGHmHKPNXtwRi8/+8VJ6eTss27WKgvGnVTRSrvJvf8vwfN48WDMoSwHHmC6crJEsQ6Q/QRAsZqMVm086055U6eFN2Lcm/xQv2b2FSvnmJQLP6XQ/oIb4RTCc/9P0SN5WXgtQCRlZWuQw/YUihKXV6NQyjHr+Ep8g3/+WJyae+XLe6ltm9h0oj984k0yKR91j5yACaitNjkbg8LX7GV4kzDd94gBrIFr3VbLfA7i0kaPKXnGkVS8=
30 | - secure: kWzQv1gaQ3rm+723iHr8I4LqQP55lOISn03Dm8qGqkREvO4lrukp9n34a6gQpPYi8sbh+KQe/ChlDnPOIGt1crKf3S3B4FQWb0AHOiyphutl3LRSq3tF5zvoSctmesVYOsVBfOmxD3dSw94VKK95aKhqmY3bFKSFsejVgd73xxPWewgcKoon7CrK5ugfY3tS8jLefHWOhfEKpmpCCW+UWGUoh3eJhIqbDFpV0Lv7pH5YaiZuMAY3J1Gpqxil2ET6vbj6bbLH/MSr27hg6SaJyszwO2XnHXqC1eLSOho3IVZVmSxfBPwerF8L1YMJqV8Dsu51e5qoRefbGVPv+0ElPLeiSJt4oQbG22qJfOKc2QQkvh6iB7U+E6act6QvSyzYEeX/7Rwk15H11nU0y20VQkEIE+qLV0LmeypZbFks5wADaBA+C5qC04PJJwJZiyVoqC2bAoEo0UMix4nGBbROGxI731UgjhmFhuV2UmLUunlE6EBt62ZoXi9ziOqPucGEWcYfS27RLPorfqIQVH8A9ZgTdZ5F8HXtMygEBIlMvsH29XQf1uXtu9kFGRybeKhk71Jvr+rYuo5nR1BLiGHmz1JHD6Ie0KtyCY3h3OVShnrD7LKdekoZo7CekRuVSnaFGZ8yJyRnjGLS6i1Xl7vEHG4Wb1W9QUpX2xQohrqib6A=
31 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 |
2 | Apache License
3 | Version 2.0, January 2004
4 | http://www.apache.org/licenses/
5 |
6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7 |
8 | 1. Definitions.
9 |
10 | "License" shall mean the terms and conditions for use, reproduction,
11 | and distribution as defined by Sections 1 through 9 of this document.
12 |
13 | "Licensor" shall mean the copyright owner or entity authorized by
14 | the copyright owner that is granting the License.
15 |
16 | "Legal Entity" shall mean the union of the acting entity and all
17 | other entities that control, are controlled by, or are under common
18 | control with that entity. For the purposes of this definition,
19 | "control" means (i) the power, direct or indirect, to cause the
20 | direction or management of such entity, whether by contract or
21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
22 | outstanding shares, or (iii) beneficial ownership of such entity.
23 |
24 | "You" (or "Your") shall mean an individual or Legal Entity
25 | exercising permissions granted by this License.
26 |
27 | "Source" form shall mean the preferred form for making modifications,
28 | including but not limited to software source code, documentation
29 | source, and configuration files.
30 |
31 | "Object" form shall mean any form resulting from mechanical
32 | transformation or translation of a Source form, including but
33 | not limited to compiled object code, generated documentation,
34 | and conversions to other media types.
35 |
36 | "Work" shall mean the work of authorship, whether in Source or
37 | Object form, made available under the License, as indicated by a
38 | copyright notice that is included in or attached to the work
39 | (an example is provided in the Appendix below).
40 |
41 | "Derivative Works" shall mean any work, whether in Source or Object
42 | form, that is based on (or derived from) the Work and for which the
43 | editorial revisions, annotations, elaborations, or other modifications
44 | represent, as a whole, an original work of authorship. For the purposes
45 | of this License, Derivative Works shall not include works that remain
46 | separable from, or merely link (or bind by name) to the interfaces of,
47 | the Work and Derivative Works thereof.
48 |
49 | "Contribution" shall mean any work of authorship, including
50 | the original version of the Work and any modifications or additions
51 | to that Work or Derivative Works thereof, that is intentionally
52 | submitted to Licensor for inclusion in the Work by the copyright owner
53 | or by an individual or Legal Entity authorized to submit on behalf of
54 | the copyright owner. For the purposes of this definition, "submitted"
55 | means any form of electronic, verbal, or written communication sent
56 | to the Licensor or its representatives, including but not limited to
57 | communication on electronic mailing lists, source code control systems,
58 | and issue tracking systems that are managed by, or on behalf of, the
59 | Licensor for the purpose of discussing and improving the Work, but
60 | excluding communication that is conspicuously marked or otherwise
61 | designated in writing by the copyright owner as "Not a Contribution."
62 |
63 | "Contributor" shall mean Licensor and any individual or Legal Entity
64 | on behalf of whom a Contribution has been received by Licensor and
65 | subsequently incorporated within the Work.
66 |
67 | 2. Grant of Copyright License. Subject to the terms and conditions of
68 | this License, each Contributor hereby grants to You a perpetual,
69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70 | copyright license to reproduce, prepare Derivative Works of,
71 | publicly display, publicly perform, sublicense, and distribute the
72 | Work and such Derivative Works in Source or Object form.
73 |
74 | 3. Grant of Patent License. Subject to the terms and conditions of
75 | this License, each Contributor hereby grants to You a perpetual,
76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77 | (except as stated in this section) patent license to make, have made,
78 | use, offer to sell, sell, import, and otherwise transfer the Work,
79 | where such license applies only to those patent claims licensable
80 | by such Contributor that are necessarily infringed by their
81 | Contribution(s) alone or by combination of their Contribution(s)
82 | with the Work to which such Contribution(s) was submitted. If You
83 | institute patent litigation against any entity (including a
84 | cross-claim or counterclaim in a lawsuit) alleging that the Work
85 | or a Contribution incorporated within the Work constitutes direct
86 | or contributory patent infringement, then any patent licenses
87 | granted to You under this License for that Work shall terminate
88 | as of the date such litigation is filed.
89 |
90 | 4. Redistribution. You may reproduce and distribute copies of the
91 | Work or Derivative Works thereof in any medium, with or without
92 | modifications, and in Source or Object form, provided that You
93 | meet the following conditions:
94 |
95 | (a) You must give any other recipients of the Work or
96 | Derivative Works a copy of this License; and
97 |
98 | (b) You must cause any modified files to carry prominent notices
99 | stating that You changed the files; and
100 |
101 | (c) You must retain, in the Source form of any Derivative Works
102 | that You distribute, all copyright, patent, trademark, and
103 | attribution notices from the Source form of the Work,
104 | excluding those notices that do not pertain to any part of
105 | the Derivative Works; and
106 |
107 | (d) If the Work includes a "NOTICE" text file as part of its
108 | distribution, then any Derivative Works that You distribute must
109 | include a readable copy of the attribution notices contained
110 | within such NOTICE file, excluding those notices that do not
111 | pertain to any part of the Derivative Works, in at least one
112 | of the following places: within a NOTICE text file distributed
113 | as part of the Derivative Works; within the Source form or
114 | documentation, if provided along with the Derivative Works; or,
115 | within a display generated by the Derivative Works, if and
116 | wherever such third-party notices normally appear. The contents
117 | of the NOTICE file are for informational purposes only and
118 | do not modify the License. You may add Your own attribution
119 | notices within Derivative Works that You distribute, alongside
120 | or as an addendum to the NOTICE text from the Work, provided
121 | that such additional attribution notices cannot be construed
122 | as modifying the License.
123 |
124 | You may add Your own copyright statement to Your modifications and
125 | may provide additional or different license terms and conditions
126 | for use, reproduction, or distribution of Your modifications, or
127 | for any such Derivative Works as a whole, provided Your use,
128 | reproduction, and distribution of the Work otherwise complies with
129 | the conditions stated in this License.
130 |
131 | 5. Submission of Contributions. Unless You explicitly state otherwise,
132 | any Contribution intentionally submitted for inclusion in the Work
133 | by You to the Licensor shall be under the terms and conditions of
134 | this License, without any additional terms or conditions.
135 | Notwithstanding the above, nothing herein shall supersede or modify
136 | the terms of any separate license agreement you may have executed
137 | with Licensor regarding such Contributions.
138 |
139 | 6. Trademarks. This License does not grant permission to use the trade
140 | names, trademarks, service marks, or product names of the Licensor,
141 | except as required for reasonable and customary use in describing the
142 | origin of the Work and reproducing the content of the NOTICE file.
143 |
144 | 7. Disclaimer of Warranty. Unless required by applicable law or
145 | agreed to in writing, Licensor provides the Work (and each
146 | Contributor provides its Contributions) on an "AS IS" BASIS,
147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148 | implied, including, without limitation, any warranties or conditions
149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150 | PARTICULAR PURPOSE. You are solely responsible for determining the
151 | appropriateness of using or redistributing the Work and assume any
152 | risks associated with Your exercise of permissions under this License.
153 |
154 | 8. Limitation of Liability. In no event and under no legal theory,
155 | whether in tort (including negligence), contract, or otherwise,
156 | unless required by applicable law (such as deliberate and grossly
157 | negligent acts) or agreed to in writing, shall any Contributor be
158 | liable to You for damages, including any direct, indirect, special,
159 | incidental, or consequential damages of any character arising as a
160 | result of this License or out of the use or inability to use the
161 | Work (including but not limited to damages for loss of goodwill,
162 | work stoppage, computer failure or malfunction, or any and all
163 | other commercial damages or losses), even if such Contributor
164 | has been advised of the possibility of such damages.
165 |
166 | 9. Accepting Warranty or Additional Liability. While redistributing
167 | the Work or Derivative Works thereof, You may choose to offer,
168 | and charge a fee for, acceptance of support, warranty, indemnity,
169 | or other liability obligations and/or rights consistent with this
170 | License. However, in accepting such obligations, You may act only
171 | on Your own behalf and on Your sole responsibility, not on behalf
172 | of any other Contributor, and only if You agree to indemnify,
173 | defend, and hold each Contributor harmless for any liability
174 | incurred by, or claims asserted against, such Contributor by reason
175 | of your accepting any such warranty or additional liability.
176 |
177 | END OF TERMS AND CONDITIONS
178 |
179 | APPENDIX: How to apply the Apache License to your work.
180 |
181 | To apply the Apache License to your work, attach the following
182 | boilerplate notice, with the fields enclosed by brackets "[]"
183 | replaced with your own identifying information. (Don't include
184 | the brackets!) The text should be enclosed in the appropriate
185 | comment syntax for the file format. We also recommend that a
186 | file or class name and description of purpose be included on the
187 | same "printed page" as the copyright notice for easier
188 | identification within third-party archives.
189 |
190 | Copyright 2015-Present Pivotal Software Inc.
191 |
192 | Licensed under the Apache License, Version 2.0 (the "License");
193 | you may not use this file except in compliance with the License.
194 | You may obtain a copy of the License at
195 |
196 | http://www.apache.org/licenses/LICENSE-2.0
197 |
198 | Unless required by applicable law or agreed to in writing, software
199 | distributed under the License is distributed on an "AS IS" BASIS,
200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201 | See the License for the specific language governing permissions and
202 | limitations under the License.
203 |
204 |
205 |
206 |
--------------------------------------------------------------------------------
/LICENSE.txt:
--------------------------------------------------------------------------------
1 |
2 | Apache License
3 | Version 2.0, January 2004
4 | https://www.apache.org/licenses/
5 |
6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7 |
8 | 1. Definitions.
9 |
10 | "License" shall mean the terms and conditions for use, reproduction,
11 | and distribution as defined by Sections 1 through 9 of this document.
12 |
13 | "Licensor" shall mean the copyright owner or entity authorized by
14 | the copyright owner that is granting the License.
15 |
16 | "Legal Entity" shall mean the union of the acting entity and all
17 | other entities that control, are controlled by, or are under common
18 | control with that entity. For the purposes of this definition,
19 | "control" means (i) the power, direct or indirect, to cause the
20 | direction or management of such entity, whether by contract or
21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
22 | outstanding shares, or (iii) beneficial ownership of such entity.
23 |
24 | "You" (or "Your") shall mean an individual or Legal Entity
25 | exercising permissions granted by this License.
26 |
27 | "Source" form shall mean the preferred form for making modifications,
28 | including but not limited to software source code, documentation
29 | source, and configuration files.
30 |
31 | "Object" form shall mean any form resulting from mechanical
32 | transformation or translation of a Source form, including but
33 | not limited to compiled object code, generated documentation,
34 | and conversions to other media types.
35 |
36 | "Work" shall mean the work of authorship, whether in Source or
37 | Object form, made available under the License, as indicated by a
38 | copyright notice that is included in or attached to the work
39 | (an example is provided in the Appendix below).
40 |
41 | "Derivative Works" shall mean any work, whether in Source or Object
42 | form, that is based on (or derived from) the Work and for which the
43 | editorial revisions, annotations, elaborations, or other modifications
44 | represent, as a whole, an original work of authorship. For the purposes
45 | of this License, Derivative Works shall not include works that remain
46 | separable from, or merely link (or bind by name) to the interfaces of,
47 | the Work and Derivative Works thereof.
48 |
49 | "Contribution" shall mean any work of authorship, including
50 | the original version of the Work and any modifications or additions
51 | to that Work or Derivative Works thereof, that is intentionally
52 | submitted to Licensor for inclusion in the Work by the copyright owner
53 | or by an individual or Legal Entity authorized to submit on behalf of
54 | the copyright owner. For the purposes of this definition, "submitted"
55 | means any form of electronic, verbal, or written communication sent
56 | to the Licensor or its representatives, including but not limited to
57 | communication on electronic mailing lists, source code control systems,
58 | and issue tracking systems that are managed by, or on behalf of, the
59 | Licensor for the purpose of discussing and improving the Work, but
60 | excluding communication that is conspicuously marked or otherwise
61 | designated in writing by the copyright owner as "Not a Contribution."
62 |
63 | "Contributor" shall mean Licensor and any individual or Legal Entity
64 | on behalf of whom a Contribution has been received by Licensor and
65 | subsequently incorporated within the Work.
66 |
67 | 2. Grant of Copyright License. Subject to the terms and conditions of
68 | this License, each Contributor hereby grants to You a perpetual,
69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70 | copyright license to reproduce, prepare Derivative Works of,
71 | publicly display, publicly perform, sublicense, and distribute the
72 | Work and such Derivative Works in Source or Object form.
73 |
74 | 3. Grant of Patent License. Subject to the terms and conditions of
75 | this License, each Contributor hereby grants to You a perpetual,
76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77 | (except as stated in this section) patent license to make, have made,
78 | use, offer to sell, sell, import, and otherwise transfer the Work,
79 | where such license applies only to those patent claims licensable
80 | by such Contributor that are necessarily infringed by their
81 | Contribution(s) alone or by combination of their Contribution(s)
82 | with the Work to which such Contribution(s) was submitted. If You
83 | institute patent litigation against any entity (including a
84 | cross-claim or counterclaim in a lawsuit) alleging that the Work
85 | or a Contribution incorporated within the Work constitutes direct
86 | or contributory patent infringement, then any patent licenses
87 | granted to You under this License for that Work shall terminate
88 | as of the date such litigation is filed.
89 |
90 | 4. Redistribution. You may reproduce and distribute copies of the
91 | Work or Derivative Works thereof in any medium, with or without
92 | modifications, and in Source or Object form, provided that You
93 | meet the following conditions:
94 |
95 | (a) You must give any other recipients of the Work or
96 | Derivative Works a copy of this License; and
97 |
98 | (b) You must cause any modified files to carry prominent notices
99 | stating that You changed the files; and
100 |
101 | (c) You must retain, in the Source form of any Derivative Works
102 | that You distribute, all copyright, patent, trademark, and
103 | attribution notices from the Source form of the Work,
104 | excluding those notices that do not pertain to any part of
105 | the Derivative Works; and
106 |
107 | (d) If the Work includes a "NOTICE" text file as part of its
108 | distribution, then any Derivative Works that You distribute must
109 | include a readable copy of the attribution notices contained
110 | within such NOTICE file, excluding those notices that do not
111 | pertain to any part of the Derivative Works, in at least one
112 | of the following places: within a NOTICE text file distributed
113 | as part of the Derivative Works; within the Source form or
114 | documentation, if provided along with the Derivative Works; or,
115 | within a display generated by the Derivative Works, if and
116 | wherever such third-party notices normally appear. The contents
117 | of the NOTICE file are for informational purposes only and
118 | do not modify the License. You may add Your own attribution
119 | notices within Derivative Works that You distribute, alongside
120 | or as an addendum to the NOTICE text from the Work, provided
121 | that such additional attribution notices cannot be construed
122 | as modifying the License.
123 |
124 | You may add Your own copyright statement to Your modifications and
125 | may provide additional or different license terms and conditions
126 | for use, reproduction, or distribution of Your modifications, or
127 | for any such Derivative Works as a whole, provided Your use,
128 | reproduction, and distribution of the Work otherwise complies with
129 | the conditions stated in this License.
130 |
131 | 5. Submission of Contributions. Unless You explicitly state otherwise,
132 | any Contribution intentionally submitted for inclusion in the Work
133 | by You to the Licensor shall be under the terms and conditions of
134 | this License, without any additional terms or conditions.
135 | Notwithstanding the above, nothing herein shall supersede or modify
136 | the terms of any separate license agreement you may have executed
137 | with Licensor regarding such Contributions.
138 |
139 | 6. Trademarks. This License does not grant permission to use the trade
140 | names, trademarks, service marks, or product names of the Licensor,
141 | except as required for reasonable and customary use in describing the
142 | origin of the Work and reproducing the content of the NOTICE file.
143 |
144 | 7. Disclaimer of Warranty. Unless required by applicable law or
145 | agreed to in writing, Licensor provides the Work (and each
146 | Contributor provides its Contributions) on an "AS IS" BASIS,
147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148 | implied, including, without limitation, any warranties or conditions
149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150 | PARTICULAR PURPOSE. You are solely responsible for determining the
151 | appropriateness of using or redistributing the Work and assume any
152 | risks associated with Your exercise of permissions under this License.
153 |
154 | 8. Limitation of Liability. In no event and under no legal theory,
155 | whether in tort (including negligence), contract, or otherwise,
156 | unless required by applicable law (such as deliberate and grossly
157 | negligent acts) or agreed to in writing, shall any Contributor be
158 | liable to You for damages, including any direct, indirect, special,
159 | incidental, or consequential damages of any character arising as a
160 | result of this License or out of the use or inability to use the
161 | Work (including but not limited to damages for loss of goodwill,
162 | work stoppage, computer failure or malfunction, or any and all
163 | other commercial damages or losses), even if such Contributor
164 | has been advised of the possibility of such damages.
165 |
166 | 9. Accepting Warranty or Additional Liability. While redistributing
167 | the Work or Derivative Works thereof, You may choose to offer,
168 | and charge a fee for, acceptance of support, warranty, indemnity,
169 | or other liability obligations and/or rights consistent with this
170 | License. However, in accepting such obligations, You may act only
171 | on Your own behalf and on Your sole responsibility, not on behalf
172 | of any other Contributor, and only if You agree to indemnify,
173 | defend, and hold each Contributor harmless for any liability
174 | incurred by, or claims asserted against, such Contributor by reason
175 | of your accepting any such warranty or additional liability.
176 |
177 | END OF TERMS AND CONDITIONS
178 |
179 | APPENDIX: How to apply the Apache License to your work.
180 |
181 | To apply the Apache License to your work, attach the following
182 | boilerplate notice, with the fields enclosed by brackets "[]"
183 | replaced with your own identifying information. (Don't include
184 | the brackets!) The text should be enclosed in the appropriate
185 | comment syntax for the file format. We also recommend that a
186 | file or class name and description of purpose be included on the
187 | same "printed page" as the copyright notice for easier
188 | identification within third-party archives.
189 |
190 | Copyright [yyyy] [name of copyright owner]
191 |
192 | Licensed under the Apache License, Version 2.0 (the "License");
193 | you may not use this file except in compliance with the License.
194 | You may obtain a copy of the License at
195 |
196 | https://www.apache.org/licenses/LICENSE-2.0
197 |
198 | Unless required by applicable law or agreed to in writing, software
199 | distributed under the License is distributed on an "AS IS" BASIS,
200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201 | See the License for the specific language governing permissions and
202 | limitations under the License.
203 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # spring-cloud-config-server-mongodb is no longer actively maintained by VMware, Inc.
2 |
3 | # Spring Cloud Config Server MongoDB
4 |
5 | [](https://travis-ci.org/spring-cloud-incubator/spring-cloud-config-server-mongodb)
6 | [](https://gitter.im/spring-cloud-incubator/spring-cloud-config-server-mongodb?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
7 |
8 | Spring Cloud Config Server MongoDB enables seamless integration of the regular Spring Cloud Config Server with MongoDB to manage external properties for applications across all environments.
9 |
10 | # Quick Start
11 | Configure pom.xml, like this:
12 | ```xml
13 |
14 |
15 | org.springframework.cloud
16 | spring-cloud-config-server-mongodb
17 | 0.0.3.BUILD-SNAPSHOT
18 |
19 |
20 |
21 |
22 |
23 | spring-snapshots
24 | Spring Snapshots
25 | https://repo.spring.io/libs-snapshot-local
26 |
27 | true
28 |
29 |
30 |
31 | ojo-snapshots
32 | OJO Snapshots
33 | https://oss.jfrog.org/artifactory/libs-snapshot
34 |
35 | true
36 |
37 |
38 |
39 | ```
40 |
41 | Create a standard Spring Boot application, like this:
42 | ```java
43 | @SpringBootApplication
44 | @EnableMongoConfigServer
45 | public class Application {
46 |
47 | public static void main(String[] args) {
48 | SpringApplication.run(Application.class, args);
49 | }
50 |
51 | }
52 | ```
53 |
54 | Configure the application's `spring.data.mongodb.*` properties in `application.yml`, like this:
55 | ```yaml
56 | spring:
57 | data:
58 | mongodb:
59 | uri: mongodb://localhost/config-db
60 | ```
61 |
62 | Add documents to the `config-db` mongo database, like this:
63 | ```javascript
64 | use config-db;
65 |
66 | db.gateway.insert({
67 | "label": "master",
68 | "profile": "prod",
69 | "source": {
70 | "user": {
71 | "max-connections": 1,
72 | "timeout-ms": 3600
73 | }
74 | }
75 | });
76 | ```
77 | In the above snippet we've configured properties for an application named `gateway` having profile `prod` and label `master`.
78 |
79 | The `application-name` is identified by the collection's `name` and a MongoDB document's `profile` and `label` values represent the Spring application's `profile` and `label` respectively. Note that documents with no `profile` or `label` values will have them considered `default`. All properties must be listed under the `source` key of the document.
80 |
81 | Finally, access these properties by invoking `http://localhost:8080/master/gateway-prod.properties`. The response would be like this:
82 | ```json
83 | user.max-connections: 1.0
84 | user.timeout-ms: 3600.0
85 | ```
86 |
87 | # References
88 | [spring-cloud-config](https://github.com/spring-cloud/spring-cloud-config)
89 |
--------------------------------------------------------------------------------
/mvnw:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | # ----------------------------------------------------------------------------
3 | # Licensed to the Apache Software Foundation (ASF) under one
4 | # or more contributor license agreements. See the NOTICE file
5 | # distributed with this work for additional information
6 | # regarding copyright ownership. The ASF licenses this file
7 | # to you under the Apache License, Version 2.0 (the
8 | # "License"); you may not use this file except in compliance
9 | # with the License. You may obtain a copy of the License at
10 | #
11 | # https://www.apache.org/licenses/LICENSE-2.0
12 | #
13 | # Unless required by applicable law or agreed to in writing,
14 | # software distributed under the License is distributed on an
15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 | # KIND, either express or implied. See the License for the
17 | # specific language governing permissions and limitations
18 | # under the License.
19 | # ----------------------------------------------------------------------------
20 |
21 | # ----------------------------------------------------------------------------
22 | # Maven2 Start Up Batch script
23 | #
24 | # Required ENV vars:
25 | # ------------------
26 | # JAVA_HOME - location of a JDK home dir
27 | #
28 | # Optional ENV vars
29 | # -----------------
30 | # M2_HOME - location of maven2's installed home dir
31 | # MAVEN_OPTS - parameters passed to the Java VM when running Maven
32 | # e.g. to debug Maven itself, use
33 | # set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
34 | # MAVEN_SKIP_RC - flag to disable loading of mavenrc files
35 | # ----------------------------------------------------------------------------
36 |
37 | if [ -z "$MAVEN_SKIP_RC" ] ; then
38 |
39 | if [ -f /etc/mavenrc ] ; then
40 | . /etc/mavenrc
41 | fi
42 |
43 | if [ -f "$HOME/.mavenrc" ] ; then
44 | . "$HOME/.mavenrc"
45 | fi
46 |
47 | fi
48 |
49 | # OS specific support. $var _must_ be set to either true or false.
50 | cygwin=false;
51 | darwin=false;
52 | mingw=false
53 | case "`uname`" in
54 | CYGWIN*) cygwin=true ;;
55 | MINGW*) mingw=true;;
56 | Darwin*) darwin=true
57 | #
58 | # Look for the Apple JDKs first to preserve the existing behaviour, and then look
59 | # for the new JDKs provided by Oracle.
60 | #
61 | if [ -z "$JAVA_HOME" ] && [ -L /System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK ] ; then
62 | #
63 | # Apple JDKs
64 | #
65 | export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home
66 | fi
67 |
68 | if [ -z "$JAVA_HOME" ] && [ -L /System/Library/Java/JavaVirtualMachines/CurrentJDK ] ; then
69 | #
70 | # Apple JDKs
71 | #
72 | export JAVA_HOME=/System/Library/Java/JavaVirtualMachines/CurrentJDK/Contents/Home
73 | fi
74 |
75 | if [ -z "$JAVA_HOME" ] && [ -L "/Library/Java/JavaVirtualMachines/CurrentJDK" ] ; then
76 | #
77 | # Oracle JDKs
78 | #
79 | export JAVA_HOME=/Library/Java/JavaVirtualMachines/CurrentJDK/Contents/Home
80 | fi
81 |
82 | if [ -z "$JAVA_HOME" ] && [ -x "/usr/libexec/java_home" ]; then
83 | #
84 | # Apple JDKs
85 | #
86 | export JAVA_HOME=`/usr/libexec/java_home`
87 | fi
88 | ;;
89 | esac
90 |
91 | if [ -z "$JAVA_HOME" ] ; then
92 | if [ -r /etc/gentoo-release ] ; then
93 | JAVA_HOME=`java-config --jre-home`
94 | fi
95 | fi
96 |
97 | if [ -z "$M2_HOME" ] ; then
98 | ## resolve links - $0 may be a link to maven's home
99 | PRG="$0"
100 |
101 | # need this for relative symlinks
102 | while [ -h "$PRG" ] ; do
103 | ls=`ls -ld "$PRG"`
104 | link=`expr "$ls" : '.*-> \(.*\)$'`
105 | if expr "$link" : '/.*' > /dev/null; then
106 | PRG="$link"
107 | else
108 | PRG="`dirname "$PRG"`/$link"
109 | fi
110 | done
111 |
112 | saveddir=`pwd`
113 |
114 | M2_HOME=`dirname "$PRG"`/..
115 |
116 | # make it fully qualified
117 | M2_HOME=`cd "$M2_HOME" && pwd`
118 |
119 | cd "$saveddir"
120 | # echo Using m2 at $M2_HOME
121 | fi
122 |
123 | # For Cygwin, ensure paths are in UNIX format before anything is touched
124 | if $cygwin ; then
125 | [ -n "$M2_HOME" ] &&
126 | M2_HOME=`cygpath --unix "$M2_HOME"`
127 | [ -n "$JAVA_HOME" ] &&
128 | JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
129 | [ -n "$CLASSPATH" ] &&
130 | CLASSPATH=`cygpath --path --unix "$CLASSPATH"`
131 | fi
132 |
133 | # For Migwn, ensure paths are in UNIX format before anything is touched
134 | if $mingw ; then
135 | [ -n "$M2_HOME" ] &&
136 | M2_HOME="`(cd "$M2_HOME"; pwd)`"
137 | [ -n "$JAVA_HOME" ] &&
138 | JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`"
139 | # TODO classpath?
140 | fi
141 |
142 | if [ -z "$JAVA_HOME" ]; then
143 | javaExecutable="`which javac`"
144 | if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then
145 | # readlink(1) is not available as standard on Solaris 10.
146 | readLink=`which readlink`
147 | if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then
148 | if $darwin ; then
149 | javaHome="`dirname \"$javaExecutable\"`"
150 | javaExecutable="`cd \"$javaHome\" && pwd -P`/javac"
151 | else
152 | javaExecutable="`readlink -f \"$javaExecutable\"`"
153 | fi
154 | javaHome="`dirname \"$javaExecutable\"`"
155 | javaHome=`expr "$javaHome" : '\(.*\)/bin'`
156 | JAVA_HOME="$javaHome"
157 | export JAVA_HOME
158 | fi
159 | fi
160 | fi
161 |
162 | if [ -z "$JAVACMD" ] ; then
163 | if [ -n "$JAVA_HOME" ] ; then
164 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
165 | # IBM's JDK on AIX uses strange locations for the executables
166 | JAVACMD="$JAVA_HOME/jre/sh/java"
167 | else
168 | JAVACMD="$JAVA_HOME/bin/java"
169 | fi
170 | else
171 | JAVACMD="`which java`"
172 | fi
173 | fi
174 |
175 | if [ ! -x "$JAVACMD" ] ; then
176 | echo "Error: JAVA_HOME is not defined correctly." >&2
177 | echo " We cannot execute $JAVACMD" >&2
178 | exit 1
179 | fi
180 |
181 | if [ -z "$JAVA_HOME" ] ; then
182 | echo "Warning: JAVA_HOME environment variable is not set."
183 | fi
184 |
185 | CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher
186 |
187 | # For Cygwin, switch paths to Windows format before running java
188 | if $cygwin; then
189 | [ -n "$M2_HOME" ] &&
190 | M2_HOME=`cygpath --path --windows "$M2_HOME"`
191 | [ -n "$JAVA_HOME" ] &&
192 | JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"`
193 | [ -n "$CLASSPATH" ] &&
194 | CLASSPATH=`cygpath --path --windows "$CLASSPATH"`
195 | fi
196 |
197 | # traverses directory structure from process work directory to filesystem root
198 | # first directory with .mvn subdirectory is considered project base directory
199 | find_maven_basedir() {
200 | local basedir=$(pwd)
201 | local wdir=$(pwd)
202 | while [ "$wdir" != '/' ] ; do
203 | if [ -d "$wdir"/.mvn ] ; then
204 | basedir=$wdir
205 | break
206 | fi
207 | wdir=$(cd "$wdir/.."; pwd)
208 | done
209 | echo "${basedir}"
210 | }
211 |
212 | # concatenates all lines of a file
213 | concat_lines() {
214 | if [ -f "$1" ]; then
215 | echo "$(tr -s '\n' ' ' < "$1")"
216 | fi
217 | }
218 |
219 | export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-$(find_maven_basedir)}
220 | MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS"
221 |
222 | # Provide a "standardized" way to retrieve the CLI args that will
223 | # work with both Windows and non-Windows executions.
224 | MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@"
225 | export MAVEN_CMD_LINE_ARGS
226 |
227 | WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
228 |
229 | exec "$JAVACMD" \
230 | $MAVEN_OPTS \
231 | -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \
232 | "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \
233 | ${WRAPPER_LAUNCHER} "$@"
234 |
--------------------------------------------------------------------------------
/mvnw.cmd:
--------------------------------------------------------------------------------
1 | @REM ----------------------------------------------------------------------------
2 | @REM Licensed to the Apache Software Foundation (ASF) under one
3 | @REM or more contributor license agreements. See the NOTICE file
4 | @REM distributed with this work for additional information
5 | @REM regarding copyright ownership. The ASF licenses this file
6 | @REM to you under the Apache License, Version 2.0 (the
7 | @REM "License"); you may not use this file except in compliance
8 | @REM with the License. You may obtain a copy of the License at
9 | @REM
10 | @REM https://www.apache.org/licenses/LICENSE-2.0
11 | @REM
12 | @REM Unless required by applicable law or agreed to in writing,
13 | @REM software distributed under the License is distributed on an
14 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | @REM KIND, either express or implied. See the License for the
16 | @REM specific language governing permissions and limitations
17 | @REM under the License.
18 | @REM ----------------------------------------------------------------------------
19 |
20 | @REM ----------------------------------------------------------------------------
21 | @REM Maven2 Start Up Batch script
22 | @REM
23 | @REM Required ENV vars:
24 | @REM JAVA_HOME - location of a JDK home dir
25 | @REM
26 | @REM Optional ENV vars
27 | @REM M2_HOME - location of maven2's installed home dir
28 | @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands
29 | @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending
30 | @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven
31 | @REM e.g. to debug Maven itself, use
32 | @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
33 | @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files
34 | @REM ----------------------------------------------------------------------------
35 |
36 | @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on'
37 | @echo off
38 | @REM enable echoing my setting MAVEN_BATCH_ECHO to 'on'
39 | @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO%
40 |
41 | @REM set %HOME% to equivalent of $HOME
42 | if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%")
43 |
44 | @REM Execute a user defined script before this one
45 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre
46 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending
47 | if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat"
48 | if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd"
49 | :skipRcPre
50 |
51 | @setlocal
52 |
53 | set ERROR_CODE=0
54 |
55 | @REM To isolate internal variables from possible post scripts, we use another setlocal
56 | @setlocal
57 |
58 | @REM ==== START VALIDATION ====
59 | if not "%JAVA_HOME%" == "" goto OkJHome
60 |
61 | echo.
62 | echo Error: JAVA_HOME not found in your environment. >&2
63 | echo Please set the JAVA_HOME variable in your environment to match the >&2
64 | echo location of your Java installation. >&2
65 | echo.
66 | goto error
67 |
68 | :OkJHome
69 | if exist "%JAVA_HOME%\bin\java.exe" goto init
70 |
71 | echo.
72 | echo Error: JAVA_HOME is set to an invalid directory. >&2
73 | echo JAVA_HOME = "%JAVA_HOME%" >&2
74 | echo Please set the JAVA_HOME variable in your environment to match the >&2
75 | echo location of your Java installation. >&2
76 | echo.
77 | goto error
78 |
79 | @REM ==== END VALIDATION ====
80 |
81 | :init
82 |
83 | set MAVEN_CMD_LINE_ARGS=%*
84 |
85 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn".
86 | @REM Fallback to current working directory if not found.
87 |
88 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR%
89 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir
90 |
91 | set EXEC_DIR=%CD%
92 | set WDIR=%EXEC_DIR%
93 | :findBaseDir
94 | IF EXIST "%WDIR%"\.mvn goto baseDirFound
95 | cd ..
96 | IF "%WDIR%"=="%CD%" goto baseDirNotFound
97 | set WDIR=%CD%
98 | goto findBaseDir
99 |
100 | :baseDirFound
101 | set MAVEN_PROJECTBASEDIR=%WDIR%
102 | cd "%EXEC_DIR%"
103 | goto endDetectBaseDir
104 |
105 | :baseDirNotFound
106 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR%
107 | cd "%EXEC_DIR%"
108 |
109 | :endDetectBaseDir
110 |
111 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig
112 |
113 | @setlocal EnableExtensions EnableDelayedExpansion
114 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a
115 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS%
116 |
117 | :endReadAdditionalConfig
118 |
119 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe"
120 |
121 | set WRAPPER_JAR="".\.mvn\wrapper\maven-wrapper.jar""
122 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
123 |
124 | %MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CMD_LINE_ARGS%
125 | if ERRORLEVEL 1 goto error
126 | goto end
127 |
128 | :error
129 | set ERROR_CODE=1
130 |
131 | :end
132 | @endlocal & set ERROR_CODE=%ERROR_CODE%
133 |
134 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost
135 | @REM check for post script, once with legacy .bat ending and once with .cmd ending
136 | if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat"
137 | if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd"
138 | :skipRcPost
139 |
140 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on'
141 | if "%MAVEN_BATCH_PAUSE%" == "on" pause
142 |
143 | if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE%
144 |
145 | exit /B %ERROR_CODE%
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | org.springframework.cloud
7 | spring-cloud-config-server-mongodb
8 | 0.0.3.BUILD-SNAPSHOT
9 | jar
10 |
11 | spring-cloud-config-server-mongodb
12 | Spring Cloud Config Server integration with MongoDB
13 |
14 |
15 | org.springframework.cloud
16 | spring-cloud-build
17 | 2.1.2.RELEASE
18 |
19 |
20 |
21 |
22 |
23 | UTF-8
24 | 1.8
25 |
26 |
27 |
28 |
29 | org.springframework.cloud
30 | spring-cloud-config-server
31 | 2.1.0.RELEASE
32 |
33 |
34 | org.springframework.boot
35 | spring-boot-starter-data-mongodb
36 |
37 |
38 | spring-core
39 | org.springframework
40 |
41 |
42 |
43 |
44 | org.springframework.boot
45 | spring-boot-starter-test
46 | test
47 |
48 |
49 |
50 |
51 | org.eclipse.jgit
52 | org.eclipse.jgit
53 | 3.6.1.201501031845-r
54 |
55 |
56 |
57 |
58 |
59 | spring-snapshots
60 | Spring Snapshots
61 | https://repo.spring.io/snapshot
62 |
63 | true
64 |
65 |
66 |
67 | spring-milestones
68 | Spring Milestones
69 | https://repo.spring.io/milestone
70 |
71 | false
72 |
73 |
74 |
75 |
76 |
77 |
78 | ojo-central
79 | oss-jfrog-artifactory-releases
80 | https://oss.jfrog.org/artifactory/oss-release-local
81 |
82 |
83 | ojo-snapshots
84 | oss-jfrog-artifactory-snapshots
85 | https://oss.jfrog.org/artifactory/oss-snapshot-local
86 |
87 |
88 |
89 |
90 |
--------------------------------------------------------------------------------
/src/main/java/org/springframework/cloud/config/server/mongodb/EnableMongoConfigServer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015-2016 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.springframework.cloud.config.server.mongodb;
17 |
18 | import java.lang.annotation.Documented;
19 | import java.lang.annotation.ElementType;
20 | import java.lang.annotation.Retention;
21 | import java.lang.annotation.RetentionPolicy;
22 | import java.lang.annotation.Target;
23 |
24 | import org.springframework.cloud.config.server.EnableConfigServer;
25 | import org.springframework.cloud.config.server.mongodb.config.MongoEnvironmentRepositoryConfiguration;
26 | import org.springframework.context.annotation.Configuration;
27 | import org.springframework.context.annotation.Import;
28 |
29 | /**
30 | * Add this annotation to a {@code @Configuration} class to enable Spring Cloud Config
31 | * Server backed by MongoDB.
32 | *
33 | * @author Venil Noronha
34 | * @see EnableConfigServer
35 | */
36 | @Target(ElementType.TYPE)
37 | @Retention(RetentionPolicy.RUNTIME)
38 | @Documented
39 | @Configuration
40 | @Import(MongoEnvironmentRepositoryConfiguration.class)
41 | @EnableConfigServer
42 | public @interface EnableMongoConfigServer {
43 |
44 | }
45 |
--------------------------------------------------------------------------------
/src/main/java/org/springframework/cloud/config/server/mongodb/config/MongoEnvironmentRepositoryConfiguration.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015-2017 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.springframework.cloud.config.server.mongodb.config;
17 |
18 | import org.springframework.beans.factory.annotation.Autowired;
19 | import org.springframework.cloud.config.server.environment.EnvironmentRepository;
20 | import org.springframework.cloud.config.server.mongodb.environment.MongoEnvironmentRepository;
21 | import org.springframework.context.annotation.Bean;
22 | import org.springframework.context.annotation.Configuration;
23 | import org.springframework.data.mongodb.core.MongoTemplate;
24 |
25 | /**
26 | * @author Venil Noronha
27 | */
28 | @Configuration
29 | public class MongoEnvironmentRepositoryConfiguration {
30 |
31 | @Autowired
32 | private MongoTemplate mongoTemplate;
33 |
34 | @Bean
35 | public EnvironmentRepository environmentRepository() {
36 | return new MongoEnvironmentRepository(mongoTemplate);
37 | }
38 |
39 | }
40 |
--------------------------------------------------------------------------------
/src/main/java/org/springframework/cloud/config/server/mongodb/environment/MongoEnvironmentRepository.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015-2016 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.cloud.config.server.mongodb.environment;
18 |
19 | import java.util.ArrayList;
20 | import java.util.Arrays;
21 | import java.util.Collections;
22 | import java.util.Comparator;
23 | import java.util.LinkedHashMap;
24 | import java.util.LinkedHashSet;
25 | import java.util.List;
26 | import java.util.Map;
27 |
28 | import org.springframework.beans.factory.config.YamlProcessor;
29 | import org.springframework.cloud.config.environment.Environment;
30 | import org.springframework.cloud.config.environment.PropertySource;
31 | import org.springframework.cloud.config.server.environment.EnvironmentRepository;
32 | import org.springframework.data.mongodb.core.MongoTemplate;
33 | import org.springframework.data.mongodb.core.query.Criteria;
34 | import org.springframework.data.mongodb.core.query.Query;
35 | import org.springframework.util.StringUtils;
36 |
37 | /**
38 | * Implementation of {@link EnvironmentRepository} that is backed by MongoDB. The
39 | * resulting {@link Environment} is composed of property sources where the
40 | * {@literal application-name} is identified by the collection's {@literal name} and a
41 | * MongoDB document's {@literal profile} and {@literal label} values represent the Spring
42 | * application's {@literal profile} and {@literal label} respectively. All properties must
43 | * be listed under the {@literal source} key of the document.
44 | *
45 | * @author Venil Noronha
46 | */
47 | public class MongoEnvironmentRepository implements EnvironmentRepository {
48 |
49 | private static final String LABEL = "label";
50 | private static final String PROFILE = "profile";
51 | private static final String DEFAULT = "default";
52 | private static final String DEFAULT_PROFILE = null;
53 | private static final String DEFAULT_LABEL = null;
54 |
55 | private MongoTemplate mongoTemplate;
56 | private MapFlattener mapFlattener;
57 |
58 | public MongoEnvironmentRepository(MongoTemplate mongoTemplate) {
59 | this.mongoTemplate = mongoTemplate;
60 | this.mapFlattener = new MapFlattener();
61 | }
62 |
63 | @Override
64 | public Environment findOne(String name, String profile, String label) {
65 | String[] profilesArr = StringUtils.commaDelimitedListToStringArray(profile);
66 | List profiles = new ArrayList(Arrays.asList(profilesArr.clone()));
67 | for (int i = 0; i < profiles.size(); i++) {
68 | if (DEFAULT.equals(profiles.get(i))) {
69 | profiles.set(i, DEFAULT_PROFILE);
70 | }
71 | }
72 | profiles.add(DEFAULT_PROFILE); // Default configuration will have 'null' profile
73 | profiles = sortedUnique(profiles);
74 |
75 | List labels = Arrays.asList(label, DEFAULT_LABEL); // Default configuration will have 'null' label
76 | labels = sortedUnique(labels);
77 |
78 | Query query = new Query();
79 | query.addCriteria(Criteria.where(PROFILE).in(profiles.toArray()));
80 | query.addCriteria(Criteria.where(LABEL).in(labels.toArray()));
81 |
82 | Environment environment;
83 | try {
84 | List sources = mongoTemplate.find(query, MongoPropertySource.class, name);
85 | sortSourcesByLabel(sources, labels);
86 | sortSourcesByProfile(sources, profiles);
87 | environment = new Environment(name, profilesArr, label, null, null);
88 | for (MongoPropertySource propertySource : sources) {
89 | String sourceName = generateSourceName(name, propertySource);
90 | Map flatSource = mapFlattener.flatten(propertySource.getSource());
91 | PropertySource propSource = new PropertySource(sourceName, flatSource);
92 | environment.add(propSource);
93 | }
94 | }
95 | catch (Exception e) {
96 | throw new IllegalStateException("Cannot load environment", e);
97 | }
98 |
99 | return environment;
100 | }
101 |
102 | private ArrayList sortedUnique(List values) {
103 | return new ArrayList(new LinkedHashSet(values));
104 | }
105 |
106 | private void sortSourcesByLabel(List sources,
107 | final List labels) {
108 | Collections.sort(sources, new Comparator() {
109 |
110 | @Override
111 | public int compare(MongoPropertySource s1, MongoPropertySource s2) {
112 | int i1 = labels.indexOf(s1.getLabel());
113 | int i2 = labels.indexOf(s2.getLabel());
114 | return Integer.compare(i1, i2);
115 | }
116 |
117 | });
118 | }
119 |
120 | private void sortSourcesByProfile(List sources,
121 | final List profiles) {
122 | Collections.sort(sources, new Comparator() {
123 |
124 | @Override
125 | public int compare(MongoPropertySource s1, MongoPropertySource s2) {
126 | int i1 = profiles.indexOf(s1.getProfile());
127 | int i2 = profiles.indexOf(s2.getProfile());
128 | return Integer.compare(i1, i2);
129 | }
130 |
131 | });
132 | }
133 |
134 | private String generateSourceName(String environmentName, MongoPropertySource source) {
135 | String sourceName;
136 | String profile = source.getProfile() != null ? source.getProfile() : DEFAULT;
137 | String label = source.getLabel();
138 | if (label != null) {
139 | sourceName = String.format("%s-%s-%s", environmentName, profile, label);
140 | }
141 | else {
142 | sourceName = String.format("%s-%s", environmentName, profile);
143 | }
144 | return sourceName;
145 | }
146 |
147 | public static class MongoPropertySource {
148 |
149 | private String profile;
150 | private String label;
151 | private LinkedHashMap source = new LinkedHashMap();
152 |
153 | public String getProfile() {
154 | return profile;
155 | }
156 |
157 | public void setProfile(String profile) {
158 | this.profile = profile;
159 | }
160 |
161 | public String getLabel() {
162 | return label;
163 | }
164 |
165 | public void setLabel(String label) {
166 | this.label = label;
167 | }
168 |
169 | public LinkedHashMap getSource() {
170 | return source;
171 | }
172 |
173 | public void setSource(LinkedHashMap source) {
174 | this.source = source;
175 | }
176 |
177 | }
178 |
179 | private static class MapFlattener extends YamlProcessor {
180 |
181 | public Map flatten(Map source) {
182 | return getFlattenedMap(source);
183 | }
184 |
185 | }
186 |
187 | }
188 |
--------------------------------------------------------------------------------
/src/test/java/org/springframework/cloud/config/server/mongodb/MongoConfigServerTests.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.cloud.config.server.mongodb;
18 |
19 | import static org.junit.Assert.assertEquals;
20 | import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
21 |
22 | import org.junit.Test;
23 | import org.junit.runner.RunWith;
24 | import org.springframework.beans.factory.annotation.Autowired;
25 | import org.springframework.boot.SpringApplication;
26 | import org.springframework.boot.autoconfigure.SpringBootApplication;
27 | import org.springframework.boot.web.server.LocalServerPort;
28 | import org.springframework.boot.test.context.SpringBootTest;
29 | import org.springframework.boot.test.web.client.TestRestTemplate;
30 | import org.springframework.cloud.config.environment.Environment;
31 | import org.springframework.cloud.config.server.mongodb.environment.MongoEnvironmentRepository.MongoPropertySource;
32 | import org.springframework.data.mongodb.core.MongoTemplate;
33 | import org.springframework.test.context.junit4.SpringRunner;
34 |
35 | /**
36 | * @author Venil Noronha
37 | */
38 | @RunWith(SpringRunner.class)
39 | @SpringBootTest(
40 | classes = MongoConfigServerTests.MongoConfigServerApplication.class,
41 | webEnvironment = RANDOM_PORT
42 | )
43 | public class MongoConfigServerTests {
44 |
45 | @LocalServerPort
46 | private int port;
47 |
48 | @Autowired
49 | private MongoTemplate mongoTemplate;
50 |
51 | @Test
52 | public void server() {
53 | mongoTemplate.dropCollection("testapp");
54 | MongoPropertySource ps = new MongoPropertySource();
55 | ps.getSource().put("testkey", "testval");
56 | mongoTemplate.save(ps, "testapp");
57 | Environment environment = new TestRestTemplate().getForObject("http://localhost:"
58 | + port + "/testapp/default", Environment.class);
59 | assertEquals("testapp-default", environment.getPropertySources().get(0).getName());
60 | assertEquals(1, environment.getPropertySources().size());
61 | assertEquals(true, environment.getPropertySources().get(0).getSource().containsKey("testkey"));
62 | assertEquals("testval", environment.getPropertySources().get(0).getSource().get("testkey"));
63 | }
64 |
65 | @SpringBootApplication
66 | @EnableMongoConfigServer
67 | public static class MongoConfigServerApplication {
68 |
69 | public static void main(String args[]) {
70 | SpringApplication.run(MongoConfigServerApplication.class, args);
71 | }
72 |
73 | }
74 |
75 | }
76 |
--------------------------------------------------------------------------------
/src/test/java/org/springframework/cloud/config/server/mongodb/environment/MongoEnvironmentRepositoryTests.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015-2016 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.cloud.config.server.mongodb.environment;
18 |
19 | import static org.junit.Assert.assertEquals;
20 |
21 | import java.util.HashMap;
22 | import java.util.Map;
23 |
24 | import org.junit.After;
25 | import org.junit.Before;
26 | import org.junit.Test;
27 |
28 | import org.springframework.boot.WebApplicationType;
29 | import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
30 | import org.springframework.boot.autoconfigure.data.mongo.MongoDataAutoConfiguration;
31 | import org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration;
32 | import org.springframework.boot.builder.SpringApplicationBuilder;
33 | import org.springframework.cloud.config.environment.Environment;
34 | import org.springframework.cloud.config.server.environment.EnvironmentRepository;
35 | import org.springframework.cloud.config.server.mongodb.EnableMongoConfigServer;
36 | import org.springframework.cloud.config.server.mongodb.environment.MongoEnvironmentRepository.MongoPropertySource;
37 | import org.springframework.context.ConfigurableApplicationContext;
38 | import org.springframework.context.annotation.Configuration;
39 | import org.springframework.context.annotation.Import;
40 | import org.springframework.data.mongodb.core.MongoTemplate;
41 |
42 | /**
43 | * @author Venil Noronha
44 | */
45 | public class MongoEnvironmentRepositoryTests {
46 |
47 | private ConfigurableApplicationContext context;
48 |
49 | @Before
50 | public void init() {
51 |
52 | }
53 |
54 | @After
55 | public void close() {
56 | if (this.context != null) {
57 | this.context.close();
58 | }
59 | }
60 |
61 | @Test
62 | public void defaultRepo() {
63 | // Prepare context
64 | Map props = new HashMap<>();
65 | props.put("spring.data.mongodb.database", "testdb");
66 | context = new SpringApplicationBuilder(TestConfiguration.class).web(WebApplicationType.NONE).properties(props).run();
67 | // Prepare test
68 | MongoTemplate mongoTemplate = this.context.getBean(MongoTemplate.class);
69 | mongoTemplate.dropCollection("testapp");
70 | MongoPropertySource ps = new MongoPropertySource();
71 | ps.getSource().put("testkey", "testval");
72 | mongoTemplate.save(ps, "testapp");
73 | // Test
74 | EnvironmentRepository repository = this.context.getBean(EnvironmentRepository.class);
75 | Environment environment = repository.findOne("testapp", "default", null);
76 | assertEquals("testapp-default", environment.getPropertySources().get(0).getName());
77 | assertEquals(1, environment.getPropertySources().size());
78 | assertEquals(true, environment.getPropertySources().get(0).getSource().containsKey("testkey"));
79 | assertEquals("testval", environment.getPropertySources().get(0).getSource().get("testkey"));
80 | }
81 |
82 | @Test
83 | public void nestedPropertySource() {
84 | // Prepare context
85 | Map props = new HashMap<>();
86 | props.put("spring.data.mongodb.database", "testdb");
87 | context = new SpringApplicationBuilder(TestConfiguration.class).web(WebApplicationType.NONE).properties(props).run();
88 | // Prepare test
89 | MongoTemplate mongoTemplate = this.context.getBean(MongoTemplate.class);
90 | mongoTemplate.dropCollection("testapp");
91 | MongoPropertySource ps = new MongoPropertySource();
92 | Map inner = new HashMap();
93 | inner.put("inner", "value");
94 | ps.getSource().put("outer", inner);
95 | mongoTemplate.save(ps, "testapp");
96 | // Test
97 | EnvironmentRepository repository = this.context.getBean(EnvironmentRepository.class);
98 | Environment environment = repository.findOne("testapp", "default", null);
99 | assertEquals("testapp-default", environment.getPropertySources().get(0).getName());
100 | assertEquals(1, environment.getPropertySources().size());
101 | assertEquals(true, environment.getPropertySources().get(0).getSource().containsKey("outer.inner"));
102 | assertEquals("value", environment.getPropertySources().get(0).getSource().get("outer.inner"));
103 | }
104 |
105 | @Test
106 | public void repoWithProfileAndLabelInSource() {
107 | // Prepare context
108 | Map props = new HashMap<>();
109 | props.put("spring.data.mongodb.database", "testdb");
110 | context = new SpringApplicationBuilder(TestConfiguration.class).web(WebApplicationType.NONE).properties(props).run();
111 | // Prepare test
112 | MongoTemplate mongoTemplate = this.context.getBean(MongoTemplate.class);
113 | mongoTemplate.dropCollection("testapp");
114 | MongoPropertySource ps = new MongoPropertySource();
115 | ps.setProfile("confprofile");
116 | ps.setLabel("conflabel");
117 | ps.getSource().put("profile", "sourceprofile");
118 | ps.getSource().put("label", "sourcelabel");
119 | mongoTemplate.save(ps, "testapp");
120 | // Test
121 | EnvironmentRepository repository = this.context.getBean(EnvironmentRepository.class);
122 | Environment environment = repository.findOne("testapp", "confprofile", "conflabel");
123 | assertEquals(1, environment.getPropertySources().size());
124 | assertEquals("testapp-confprofile-conflabel", environment.getPropertySources().get(0).getName());
125 | assertEquals(true, environment.getPropertySources().get(0).getSource().containsKey("profile"));
126 | assertEquals("sourceprofile", environment.getPropertySources().get(0).getSource().get("profile"));
127 | assertEquals(true, environment.getPropertySources().get(0).getSource().containsKey("label"));
128 | assertEquals("sourcelabel", environment.getPropertySources().get(0).getSource().get("label"));
129 | }
130 |
131 | @Configuration
132 | @EnableMongoConfigServer
133 | @Import({
134 | PropertyPlaceholderAutoConfiguration.class,
135 | MongoAutoConfiguration.class,
136 | MongoDataAutoConfiguration.class
137 | })
138 | protected static class TestConfiguration {
139 |
140 | }
141 |
142 | }
143 |
--------------------------------------------------------------------------------