()
| 936 | } |
| 937 | |
| 938 | _getConfig() { |
| 939 | let config; |
| 940 | try { |
| 941 | const data = fs.readFileSync(this.configPath, |
| 942 | { encoding: 'utf-8' }); |
| 943 | config = JSON.parse(data); |
| 944 | } catch (err) { |
| 945 | throw new Error(`could not parse config file: ${err.message}`); |
| 946 | } |
| 947 | if (this.replicationConfigPath) { |
| 948 | try { |
| 949 | const repData = fs.readFileSync(this.replicationConfigPath, |
| 950 | { encoding: 'utf-8' }); |
| 951 | const replicationEndpoints = JSON.parse(repData); |
| 952 | config.replicationEndpoints.push(...replicationEndpoints); |
| 953 | } catch (err) { |
| 954 | throw new Error( |
| 955 | `could not parse replication file: ${err.message}`); |
| 956 | } |
| 957 | } |
| 958 | |
| 959 | if (config.port !== undefined) { |
| 960 | assert(Number.isInteger(config.port) && config.port > 0, |
| 961 | 'bad config: port must be a positive integer'); |
| 962 | } |
| 963 | |
| 964 | if (config.internalPort !== undefined) { |
| 965 | assert(Number.isInteger(config.internalPort) && config.internalPort > 0, |
| 966 | 'bad config: internalPort must be a positive integer'); |
| 967 | } |
| 968 | |
| 969 | this.serverHeader = config.serverHeader || 'S3 Server'; |
| 970 | |
| 971 | this.port = config.port; |
| 972 | this.listenOn = this._parseEndpoints(config.listenOn, 'listenOn'); |
| 973 | this.internalPort = config.internalPort; |
| 974 | this.internalListenOn = this._parseEndpoints(config.internalListenOn, 'internalListenOn'); |
| 975 | |
| 976 | if (this.listenOn.length || (!this.internalPort && !this.internalListenOn.length)) { |
| 977 | // default to 8000 unless running in "internal" API mode only (i.e. internalPort/ListenOn) |
| 978 | // i.e. when either no port config is specified, or only listenOn is specified. |
| 979 | this.port ||= 8000; |
| 980 | } |
| 981 | |
| 982 | this.metricsPort = 8002; |
| 983 | if (config.metricsPort !== undefined) { |
| 984 | assert(Number.isInteger(config.metricsPort) && config.metricsPort > 0, |
| 985 | 'bad config: metricsPort must be a positive integer'); |
| 986 | this.metricsPort = config.metricsPort; |
| 987 | } |
| 988 | |
| 989 | this.metricsListenOn = this._parseEndpoints(config.metricsListenOn, 'metricsListenOn'); |
| 990 | |
| 991 | if (config.replicationGroupId) { |
| 992 | assert(typeof config.replicationGroupId === 'string', |
| 993 | 'bad config: replicationGroupId must be a string'); |
| 994 | this.replicationGroupId = config.replicationGroupId; |
| 995 | } else { |
no test coverage detected