{"size": 874, "ext": "js", "max_stars_repo_path": "src/settings/runtime/node.js", "max_stars_repo_name": "jap-cs/javascript-client", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/settings/runtime/node.js", "max_issues_repo_name": "jap-cs/javascript-client", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/settings/runtime/node.js", "max_forks_repo_name": "jap-cs/javascript-client", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 39.7272727273, "max_line_length": 157, "alphanum_fraction": 0.7162471396}
import osFunction from 'os';
import ipFunction from '../../utils/ip';

import { UNKNOWN, NA, CONSUMER_MODE } from '@splitsoftware/splitio-commons/src/utils/constants';

export function validateRuntime(settings) {
  const isIPAddressesEnabled = settings.core.IPAddressesEnabled === true;
  const isConsumerMode = settings.mode === CONSUMER_MODE;

  // If the values are not available, default to false (for standalone) or "unknown" (for consumer mode, to be used on Redis keys)
  let ip = ipFunction.address() || (isConsumerMode ? UNKNOWN : false);
  let hostname = osFunction.hostname() || (isConsumerMode ? UNKNOWN : false);

  if (!isIPAddressesEnabled) { // If IPAddresses setting is not enabled, set as false (for standalone) or "NA" (for consumer mode, to  be used on Redis keys)
    ip = hostname = isConsumerMode ? NA : false;
  }

  return {
    ip, hostname
  };
}
