private async handleInstallOperatorSettingsRequest()

in src/panels/AzureServiceOperatorPanel.ts [241:301]


    private async handleInstallOperatorSettingsRequest(
        appId: string,
        appSecret: string,
        cloudName: AzureCloudName,
        subscriptionId: string,
        tenantId: string,
        webview: MessageSink<ToWebViewMsgDef>,
    ): Promise<void> {
        const cloudEnv: ASOCloudName = azureToASOCloudMap[cloudName];
        const yamlPathOnDisk = vscode.Uri.file(
            path.join(this.extension.extensionPath, "resources", "yaml", "azureoperatorsettings.yaml"),
        );

        let settingsTemplate: string;
        try {
            settingsTemplate = await fs.readFile(yamlPathOnDisk.fsPath, "utf8");
        } catch (e) {
            webview.postInstallOperatorSettingsResponse({
                succeeded: false,
                errorMessage: `Failed to read settings template from ${yamlPathOnDisk.fsPath}: ${getErrorMessage(e)}`,
                commandResults: [],
            });
            return;
        }

        const settings = settingsTemplate
            .replace("<TENANT_ID>", tenantId)
            .replace("<SUB_ID>", subscriptionId)
            .replace("<APP_ID>", appId)
            .replace("<CLIENT_SECRET>", appSecret)
            .replace("<ENV_CLOUD>", cloudEnv);

        const templateYamlFile = await createTempFile(settings, "yaml");

        // Use a larger-than-default request timeout here, because cert-manager-cainjector is still busy updating resources, increasing response times.
        const kubectlArgs = `apply -f ${templateYamlFile.filePath} --request-timeout 120s`;
        const shellOutput = await invokeKubectlCommand(
            this.kubectl,
            this.kubeConfigFilePath,
            kubectlArgs,
            NonZeroExitCodeBehaviour.Succeed,
        );
        if (failed(shellOutput)) {
            webview.postInstallOperatorSettingsResponse({
                succeeded: false,
                errorMessage: shellOutput.error,
                commandResults: [],
            });
            return;
        }

        const succeeded = shellOutput.result.code === 0;
        const errorMessage = succeeded ? null : "Installing operator settings failed, see error output.";
        const { stdout, stderr } = shellOutput.result;
        const command = `kubectl ${kubectlArgs}`;
        webview.postInstallOperatorSettingsResponse({
            succeeded,
            errorMessage,
            commandResults: [{ command, stdout, stderr }],
        });
    }