Skip to content

Commit

Permalink
merge + nits
Browse files Browse the repository at this point in the history
  • Loading branch information
fredzqm committed May 10, 2024
1 parent 0710754 commit 4b055d4
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 23 deletions.
14 changes: 8 additions & 6 deletions firebase-vscode/src/data-connect/index.ts
Expand Up @@ -153,17 +153,19 @@ export function registerFdc(
);
const schemaCodeLensProvider = new SchemaCodeLensProvider(emulatorController);

// activate language client/serer
let client: LanguageClient;
const lsOutputChannel: vscode.OutputChannel = vscode.window.createOutputChannel(
"Firebase GraphQL Language Server",
);

// setup new language client on config change
context.subscriptions.push({
dispose: effect(() => {
const configs = dataConnectConfigs.value?.tryReadValue;
if (client) client.stop();
if (configs && configs.values.length > 0) {
client = setupLanguageClient(
context,
configs,
);
client = setupLanguageClient(context, configs, lsOutputChannel);
vscode.commands.executeCommand("fdc-graphql.start");
}
}),
Expand All @@ -179,7 +181,7 @@ export function registerFdc(
vscode.commands.executeCommand(
"firebase.dataConnect.executeIntrospection",
);
runEmulatorIssuesStream(configs,fdcService.localEndpoint.value);
runEmulatorIssuesStream(configs, fdcService.localEndpoint.value);
runDataConnectCompiler(configs, fdcService.localEndpoint.value);
}
}),
Expand All @@ -205,7 +207,7 @@ export function registerFdc(
return Disposable.from(
codeActions,
selectedProjectStatus,
{dispose: sub1},
{ dispose: sub1 },
{
dispose: effect(() => {
selectedProjectStatus.text = `$(mono-firebase) ${
Expand Down
6 changes: 1 addition & 5 deletions firebase-vscode/src/data-connect/language-client.ts
Expand Up @@ -12,12 +12,8 @@ import { ResolvedDataConnectConfigs } from "./config";
export function setupLanguageClient(
context,
configs: ResolvedDataConnectConfigs,
outputChannel: vscode.OutputChannel,
) {
// activate language client/serer
const outputChannel: vscode.OutputChannel = vscode.window.createOutputChannel(
"Firebase GraphQL Language Server",
);

const serverPath = path.join("dist", "server.js");
const serverModule = context.asAbsolutePath(serverPath);

Expand Down
23 changes: 11 additions & 12 deletions src/dataconnect/provisionCloudSql.ts
Expand Up @@ -27,14 +27,15 @@ export async function provisionCloudSql(args: {
const existingInstance = await cloudSqlAdminClient.getInstance(projectId, instanceId);
silent || utils.logLabeledBullet("dataconnect", `Found existing instance ${instanceId}.`);
connectionName = existingInstance?.connectionName || "";
const why = checkInstanceConfig(existingInstance, enableGoogleMlIntegration);
const why = getUpdateReason(existingInstance, enableGoogleMlIntegration);
if (why) {
// TODO: Return message from checkInstanceConfig to explain exactly what changes are made
silent ||
utils.logLabeledBullet(
"dataconnect",
`Instance ${instanceId} settings not compatible with Firebase Data Connect. ` +
`Updating instance to ${why}. This may take a few minutes...`,
`Updating instance. This may take a few minutes...` +
why +
"\n",
);
await promiseWithSpinner(
() =>
Expand Down Expand Up @@ -103,26 +104,24 @@ export async function provisionCloudSql(args: {
/**
* Validate that existing CloudSQL instances have the necessary settings.
*/
export function checkInstanceConfig(
instance: Instance,
requireGoogleMlIntegration: boolean,
): string | false {
export function getUpdateReason(instance: Instance, requireGoogleMlIntegration: boolean): string {
let reason = "";
const settings = instance.settings;
// CloudSQL instances must have public IP enabled to be used with Firebase Data Connect.
if (!settings.ipConfiguration?.ipv4Enabled) {
return "enable public IP";
reason += "\n - to enable public IP";
}

if (requireGoogleMlIntegration) {
if (!settings.enableGoogleMlIntegration) {
return "enable Google ML integration";
reason += "\n - to enable Google ML integration";
}
if (
!settings.databaseFlags?.some(
(f) => f.name === "cloudsql.enable_google_ml_integration" && f.value === "on",
)
) {
return "enable Google ML integration database flag";
reason += "\n - to enable Google ML integration database flag";
}
}

Expand All @@ -132,8 +131,8 @@ export function checkInstanceConfig(
(f) => f.name === "cloudsql.iam_authentication" && f.value === "on",
) ?? false;
if (!isIamEnabled) {
return "enable IAM authentication database flag";
reason += "\n - to enable IAM authentication database flag";
}

return false;
return reason;
}

0 comments on commit 4b055d4

Please sign in to comment.