<commit_before>/**
 * @author <NAME>
 * @since v1
 */
const { gatewayPatch } = require('@routr/utils/misc_util')
const {
    Status
} = require('@routr/core/status')

const AccountManager = Java.type('gov.nist.javax.sip.clientauthutils.AccountManager')
const UserCredentials = Java.type('gov.nist.javax.sip.clientauthutils.UserCredentials')

// There is something mysterious about this class that
// makes gatewaysAPI null beyond the constructor.
// The only way it works is by using this a global :(
var gatewaysAPI

/**
 * This serves as an authentication helper for Gateways
 */
class AccountManagerService {

    constructor(dataAPIs) {
        gatewaysAPI = dataAPIs.GatewaysAPI
    }

    getGateway(ct) {
        const gwRef = ct.getRequest().getHeader('X-Gateway-Ref').value
        const response = gatewaysAPI.getGateway(gwRef)

        if (response.status === Status.OK) {
            const gateway = response.result

            return {
                username: gateway.spec.credentials.username,
                secret: gateway.spec.credentials.secret,
                host: gatewayPatch(gateway.spec.host, gateway.spec.port)
            }
        }
<commit_msg>Refactored<commit_after>/**
 * @author <NAME>
 * @since v1
 */
const { buildAddr } = require('@routr/utils/misc_utils')
const {
    Status
} = require('@routr/core/status')

const AccountManager = Java.type('gov.nist.javax.sip.clientauthutils.AccountManager')
const UserCredentials = Java.type('gov.nist.javax.sip.clientauthutils.UserCredentials')

// There is something mysterious about this class that
// makes gatewaysAPI null beyond the constructor.
// The only way it works is by using this a global :(
var gatewaysAPI

/**
 * This serves as an authentication helper for Gateways
 */
class AccountManagerService {

    constructor(dataAPIs) {
        gatewaysAPI = dataAPIs.GatewaysAPI
    }

    getGateway(ct) {
        const gwRef = ct.getRequest().getHeader('X-Gateway-Ref').value
        const response = gatewaysAPI.getGateway(gwRef)

        if (response.status === Status.OK) {
            const gateway = response.result

            return {
                username: gateway.spec.credentials.username,
                secret: gateway.spec.credentials.secret,
                host: buildAddr(gateway.spec.host, gateway.spec.port)
            }
        }

{'fraction_non_alphanumeric': 0.10912190963341858, 'fraction_numerical': 0.0008525149190110827, 'mean_word_length': 2.8038897893030796, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3934504', 'n_tokens_mistral': 691, 'n_tokens_neox': 670, 'n_words': 156}