@@ -137,6 +137,19 @@ local function parse_resp_body(self, resp_body)
137
137
return cjson .encode (config )
138
138
end
139
139
140
+ local function use_service_version (portal_endpoint_has_path )
141
+ local vars = resty_env .list ()
142
+ for n , v in pairs (vars ) do
143
+ if match (n , " APICAST_SERVICE_\\ d+_CONFIGURATION_VERSION" ) and v and v ~= ' '
144
+ and portal_endpoint_has_path then
145
+ ngx .log (ngx .INFO , " APICAST_SERVICE_${ID}_CONFIGURATION_VERSION is configured: " ,
146
+ " all services will be loaded" )
147
+ return true
148
+ end
149
+ end
150
+ return false
151
+ end
152
+
140
153
-- When the APICAST_LOAD_SERVICES_WHEN_NEEDED is enabled, but the config loader
141
154
-- is boot, APICAST_LOAD_SERVICES_WHEN_NEEDED is going to be ignored. But in
142
155
-- that case, env refers to a host and we need to reset it to pick the env
150
163
-- http://${THREESCALE_PORTAL_ENDPOINT}/<env>.json?host=host
151
164
-- http://${THREESCALE_PORTAL_ENDPOINT}/admin/api/account/proxy_configs/<env>.json?host=host&version=version
152
165
local function configuration_endpoint_params (env , host , portal_endpoint_path )
153
- local version = resty_env .get (
154
- format (' APICAST_SERVICE_%s_CONFIGURATION_VERSION' , service_id )
155
- ) or " latest"
156
-
157
166
return portal_endpoint_path and {path = env , args = {host = host }}
158
- or {path = ' /admin/api/account/proxy_configs/' .. env , args = {host = host , version = version } }
167
+ or {path = ' /admin/api/account/proxy_configs/' .. env , args = {host = host , version = " latest " } }
159
168
end
160
169
161
170
function _M :index (host )
@@ -172,6 +181,13 @@ function _M:index(host)
172
181
return nil , ' missing environment'
173
182
end
174
183
184
+ -- Exit from index if a service version is configured because
185
+ -- in that case we have to retrieve the services individually
186
+ -- through the "old" services endpoint.
187
+ if use_service_version (not self .path and true ) then
188
+ return nil , ' wrong endpoint url'
189
+ end
190
+
175
191
local endpoint_params = configuration_endpoint_params (env , host , self .path )
176
192
local base_url = resty_url .join (self .endpoint , endpoint_params .path .. ' .json' )
177
193
local query_args = encode_args (endpoint_params .args ) ~= ' ' and ' ?' .. encode_args (endpoint_params .args )
@@ -211,16 +227,14 @@ function _M:call(environment)
211
227
return ret , err
212
228
end
213
229
214
- if load_just_for_host then
215
- return m :call (host )
216
- else
217
- return m :call ()
218
- end
230
+ return m :call ()
231
+
219
232
end
220
233
221
- -- Everything past this point in `call()` is deprecated because
222
- -- now the configuration load is handled completely by `index()`.
223
- -- Service filtering is done in configuration.lua
234
+ -- Unless APICAST_SERVICE_${ID}_CONFIGURATION_VERSION is set,
235
+ -- everything past this point in `call()` is skipped because
236
+ -- otherwise the configuration load is handled completely by
237
+ -- `index()`. Service filtering is done in configuration.lua
224
238
local http_client = self .http_client
225
239
226
240
if not http_client then
0 commit comments