export async function addEndpoint()

in src/entityExplorer.ts [170:217]


export async function addEndpoint(context: vscode.ExtensionContext) {
    const manager = new StorageManager(context.globalState);
    const endpoints = manager.getEndpoints();
    const baseOptions = { ignoreFocusOut: true };

    const rawApihost = await vscode.window.showInputBox({
        ...baseOptions,
        prompt: 'Openwhisk API Host',
        placeHolder: 'Enter Openwhisk API Host',
    });
    if (rawApihost === undefined) {
        throw Error('Empty apihost');
    }

    const [isValid, apihost] = await validateURL(rawApihost);
    if (!isValid) {
        vscode.window.showErrorMessage(
            'Failed to add new API host, please check the API host is valid'
        );
        return;
    }

    if (endpoints[apihost]) {
        vscode.window.showErrorMessage('This API host is already registered');
        return;
    }

    let alias = await vscode.window.showInputBox({
        ...baseOptions,
        prompt: 'Alias for the endpoint',
        placeHolder: 'Enter alias for the endpoint',
    });
    if (alias === undefined) {
        return;
    } else if (alias === '') {
        alias = apihost;
    }
    if (Object.values(endpoints).find((e) => e.alias === alias)) {
        vscode.window.showErrorMessage('Already existed alias');
        return;
    }

    return manager.updateEndpoints(apihost, {
        apihost,
        alias: alias as string,
        namespaces: [],
    });
}