|
19 | 19 | public class APIManagerConfigAdapter { |
20 | 20 |
|
21 | 21 | private static final Logger LOG = LoggerFactory.getLogger(APIManagerConfigAdapter.class); |
22 | | - private APIManagerConfig managerConfig; |
23 | 22 | private final StandardImportParams importParams; |
24 | 23 |
|
25 | 24 | public APIManagerConfigAdapter(StandardImportParams params) { |
26 | 25 | this.importParams = params; |
27 | 26 | } |
28 | 27 |
|
29 | | - private void readConfig() throws AppException { |
| 28 | + |
| 29 | + public APIManagerConfig getManagerConfig() throws AppException { |
30 | 30 | ObjectMapper mapper; |
31 | 31 | String config = importParams.getConfig(); |
32 | 32 | String stage = importParams.getStage(); |
33 | 33 | File configFile = Utils.locateConfigFile(config); |
34 | | - if (!configFile.exists()) return; |
| 34 | + if (!configFile.exists()) return null; |
35 | 35 | File stageConfig = Utils.getStageConfig(stage, importParams.getStageConfig(), configFile); |
36 | 36 | APIManagerConfig baseConfig; |
37 | 37 | try { |
38 | 38 | mapper = Utils.createObjectMapper(configFile); |
39 | 39 | mapper.configOverride(Map.class).setMergeable(true); |
40 | 40 | baseConfig = mapper.reader() |
41 | | - .withAttribute(UserDeserializer.Params.USE_LOGIN_NAME, true) |
42 | | - .withAttribute(RemotehostDeserializer.Params.validateRemoteHost, true) |
43 | | - .forType(APIManagerConfig.class) |
44 | | - .readValue(Utils.substituteVariables(configFile)); |
| 41 | + .withAttribute(UserDeserializer.Params.USE_LOGIN_NAME, true) |
| 42 | + .withAttribute(RemotehostDeserializer.Params.validateRemoteHost, true) |
| 43 | + .forType(APIManagerConfig.class) |
| 44 | + .readValue(Utils.substituteVariables(configFile)); |
45 | 45 | } catch (Exception e) { |
46 | 46 | throw new AppException("Cannot read API-Manager configuration from config file: " + config, ErrorCode.CANT_READ_CONFIG_FILE, e); |
47 | 47 | } |
48 | 48 | if (stageConfig != null) { |
49 | 49 | try { |
50 | 50 | ObjectReader updater = mapper.readerForUpdating(baseConfig); |
51 | | - this.managerConfig = updater.readValue(Utils.substituteVariables(stageConfig)); |
| 51 | + APIManagerConfig managerConfig = updater.readValue(Utils.substituteVariables(stageConfig)); |
52 | 52 | LOG.info("Successfully read stage configuration file: {}", stageConfig); |
| 53 | + return managerConfig; |
53 | 54 | } catch (IOException e) { |
54 | 55 | LOG.warn("No config file found for stage: {}", stage); |
55 | 56 | } |
56 | | - } else { |
57 | | - this.managerConfig = baseConfig; |
58 | 57 | } |
59 | | - } |
60 | | - |
61 | | - public APIManagerConfig getManagerConfig() throws AppException { |
62 | | - if (this.managerConfig == null) readConfig(); |
63 | | - return this.managerConfig; |
| 58 | + return baseConfig; |
64 | 59 | } |
65 | 60 | } |
0 commit comments