async function readWskPropFile()

in src/authentication.ts [32:70]


async function readWskPropFile(path: string): Promise<AuthInfo | null> {
    const regex = /^[^=]+=(.*)$/;
    const properties: AuthInfo = {
        api_key: '',
        apihost: '',
    };

    let propFile: string;
    try {
        propFile = await fs.promises.readFile(path, 'ascii');
    } catch (e) {
        return Promise.resolve(null);
    }

    propFile.split('\n').forEach((line: string) => {
        if (line.match(regex)) {
            const keyvalue = line.split('=');
            switch (keyvalue[0]) {
                case 'AUTH':
                    properties.api_key = keyvalue[1];
                    break;
                case 'APIHOST':
                    properties.apihost = keyvalue[1];
                    break;
                case 'APIGW_ACCESS_TOKEN':
                    properties.apigw_token = keyvalue[1];
                    break;
                case 'APIGW_TENANT_ID':
                    properties.apigw_space_quid = keyvalue[1];
                    break;
            }
        }
    });

    if (!!properties.api_key && !!properties.apihost) {
        return Promise.resolve(properties);
    }
    return Promise.resolve(null);
}