export async function uploadAppSettingsInternal()

in src/commands/appSettings/uploadAppSettings.ts [32:86]


export async function uploadAppSettingsInternal(context: IActionContext, client: api.IAppSettingsClient, workspaceFolder?: vscode.WorkspaceFolder, exclude?: (RegExp | string)[]): Promise<void> {
    const message: string = localize('selectLocalSettings', 'Select the local settings file to upload.');
    const localSettingsPath: string = await getLocalSettingsFile(context, message, workspaceFolder);
    const localSettingsUri: vscode.Uri = vscode.Uri.file(localSettingsPath);

    let localSettings: ILocalSettingsJson = <ILocalSettingsJson>await fse.readJson(localSettingsPath);
    if (localSettings.IsEncrypted) {
        await decryptLocalSettings(context, localSettingsUri);
        try {
            localSettings = <ILocalSettingsJson>await fse.readJson(localSettingsPath);
        } finally {
            await encryptLocalSettings(context, localSettingsUri);
        }
    }

    if (localSettings.Values) {
        const remoteSettings: WebSiteManagementModels.StringDictionary = await client.listApplicationSettings();
        if (!remoteSettings.properties) {
            remoteSettings.properties = {};
        }

        const excludedAppSettings: string[] = [];
        if (exclude) {
            Object.keys(localSettings.Values).forEach((settingName) => {
                if (exclude.some((exclusion) => typeof exclusion === 'string' ? settingName.toLowerCase() === exclusion.toLowerCase() : settingName.match(new RegExp(exclusion, 'i')))) {
                    delete localSettings.Values?.[settingName];
                    excludedAppSettings.push(settingName);
                }
            });
        }

        const uploadSettings: string = localize('uploadingSettings', 'Uploading settings...');
        ext.outputChannel.appendLog(uploadSettings, { resourceName: client.fullName });
        await confirmOverwriteSettings(context, localSettings.Values, remoteSettings.properties, client.fullName);

        if (excludedAppSettings.length) {
            ext.outputChannel.appendLog(localize('excludedSettings', 'Excluded the following settings:'));
            excludedAppSettings.forEach((key) => ext.outputChannel.appendLine(`- ${key}`));
        }

        await vscode.window.withProgress({ location: vscode.ProgressLocation.Notification, title: localize('uploadingSettingsTo', 'Uploading settings to "{0}"...', client.fullName) }, async () => {
            await client.updateApplicationSettings(remoteSettings);
        });

        ext.outputChannel.appendLog(localize('uploadedSettings', 'Successfully uploaded settings.'), { resourceName: client.fullName });
        // don't wait
        void vscode.window.showInformationMessage(localize('uploadedSettingsTo', 'Successfully uploaded settings to "{0}".', client.fullName), viewOutput).then(result => {
            if (result === viewOutput) {
                ext.outputChannel.show();
            }
        });
    } else {
        throw new Error(localize('noSettings', 'No settings found in "{0}".', localSettingsFileName));
    }
}