sysinfo: return the ipv4 and ipv6 address

This commit is contained in:
Girish Ramakrishnan
2022-01-06 12:49:56 -08:00
parent 91b1265833
commit 0654d549db
2 changed files with 33 additions and 33 deletions

View File

@@ -18,25 +18,24 @@ async function getServerIPv4(config) {
if (process.env.BOX_ENV === 'test') return '127.0.0.1';
return await promiseRetry({ times: 10, interval: 5000, debug }, async () => {
debug('getServerIPv4: getting server IP');
debug('getServerIPv4: getting server IP');
const [networkError, response] = await safe(superagent.get('https://ipv4.api.cloudron.io/api/v1/helper/public_ip')
.timeout(30 * 1000)
.ok(() => true));
const [networkError, response] = await safe(superagent.get('https://ipv4.api.cloudron.io/api/v1/helper/public_ip')
.timeout(30 * 1000)
.retry(2)
.ok(() => true));
if (networkError || response.status !== 200) {
debug('getServerIPv4: Error getting IP', networkError);
throw new BoxError(BoxError.EXTERNAL_ERROR, 'Unable to detect IP. API server unreachable');
}
if (networkError || response.status !== 200) {
debug('getServerIPv4: Error getting IP', networkError);
throw new BoxError(BoxError.EXTERNAL_ERROR, 'Unable to detect IPv4. API server unreachable');
}
if (!response.body && !response.body.ip) {
debug('getServerIPv4: Unexpected answer. No "ip" found in response body.', response.body);
throw new BoxError(BoxError.EXTERNAL_ERROR, 'Unable to detect IP. No IP found in response');
}
if (!response.body && !response.body.ip) {
debug('getServerIPv4: Unexpected answer. No "ip" found in response body.', response.body);
throw new BoxError(BoxError.EXTERNAL_ERROR, 'Unable to detect IPv4. No IP found in response');
}
return response.body.ip;
});
return response.body.ip;
}
async function getServerIPv6(config) {
@@ -44,25 +43,24 @@ async function getServerIPv6(config) {
if (process.env.BOX_ENV === 'test') return '::1';
return await promiseRetry({ times: 10, interval: 5000, debug }, async () => {
debug('getServerIPv6: getting server IP');
debug('getServerIPv6: getting server IP');
const [networkError, response] = await safe(superagent.get('https://ipv6.api.cloudron.io/api/v1/helper/public_ip')
.timeout(30 * 1000)
.ok(() => true));
const [networkError, response] = await safe(superagent.get('https://ipv6.api.cloudron.io/api/v1/helper/public_ip')
.timeout(30 * 1000)
.retry(2)
.ok(() => true));
if (networkError || response.status !== 200) {
debug('getServerIPv6: Error getting IP', networkError);
throw new BoxError(BoxError.EXTERNAL_ERROR, 'Unable to detect IP. API server unreachable');
}
if (networkError || response.status !== 200) {
debug('getServerIPv6: Error getting IP', networkError);
throw new BoxError(BoxError.EXTERNAL_ERROR, 'Unable to detect IPv6. API server unreachable');
}
if (!response.body && !response.body.ip) {
debug('getServerIPv6: Unexpected answer. No "ip" found in response body.', response.body);
throw new BoxError(BoxError.EXTERNAL_ERROR, 'Unable to detect IP. No IP found in response');
}
if (!response.body && !response.body.ip) {
debug('getServerIPv6: Unexpected answer. No "ip" found in response body.', response.body);
throw new BoxError(BoxError.EXTERNAL_ERROR, 'Unable to detect IPv6. No IP found in response');
}
return response.body.ip;
});
return response.body.ip;
}
async function testConfig(config) {