Skip to content

Commit 79152ce

Browse files
rosalyntanjoehan
andauthored
Temporary fix for firebase init dataconnect with Spark projects. (#7704)
Co-authored-by: joehan <[email protected]>
1 parent e0089d6 commit 79152ce

File tree

2 files changed

+57
-58
lines changed

2 files changed

+57
-58
lines changed

src/dataconnect/ensureApis.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,5 @@ export async function ensureApis(projectId: string): Promise<void> {
1111
export async function ensureSparkApis(projectId: string): Promise<void> {
1212
const prefix = "dataconnect";
1313
// These are the APIs that can be enabled without a billing account.
14-
await ensure(projectId, api.dataconnectOrigin(), prefix);
1514
await ensure(projectId, api.cloudSQLAdminOrigin(), prefix);
1615
}

src/init/features/dataconnect/index.ts

Lines changed: 57 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -228,66 +228,66 @@ async function promptForService(
228228
if (isBillingEnabled) {
229229
// Enabling compute.googleapis.com requires a Blaze plan.
230230
await ensureApis(setup.projectId);
231-
} else {
232-
await ensureSparkApis(setup.projectId);
233-
}
234-
// TODO (b/344021748): Support initing with services that have existing sources/files
235-
const existingServices = await listAllServices(setup.projectId);
236-
const existingServicesAndSchemas = await Promise.all(
237-
existingServices.map(async (s) => {
238-
return {
239-
service: s,
240-
schema: await getSchema(s.name),
241-
};
242-
}),
243-
);
244-
if (existingServicesAndSchemas.length) {
245-
const choices: { name: string; value: any }[] = existingServicesAndSchemas.map((s) => {
246-
const serviceName = parseServiceName(s.service.name);
247-
return {
248-
name: `${serviceName.location}/${serviceName.serviceId}`,
249-
value: s,
250-
};
251-
});
252-
choices.push({ name: "Create a new service", value: undefined });
253-
const choice: { service: Service; schema: Schema } = await promptOnce({
254-
message:
255-
"Your project already has existing services. Which would you like to set up local files for?",
256-
type: "list",
257-
choices,
258-
});
259-
if (choice) {
260-
const serviceName = parseServiceName(choice.service.name);
261-
info.serviceId = serviceName.serviceId;
262-
info.locationId = serviceName.location;
263-
if (choice.schema) {
264-
const primaryDatasource = choice.schema.datasources.find((d) => d.postgresql);
265-
if (primaryDatasource?.postgresql?.cloudSql.instance) {
266-
const instanceName = parseCloudSQLInstanceName(
267-
primaryDatasource.postgresql.cloudSql.instance,
268-
);
269-
info.cloudSqlInstanceId = instanceName.instanceId;
270-
}
271-
if (choice.schema.source.files) {
272-
info.schemaGql = choice.schema.source.files;
273-
}
274-
info.cloudSqlDatabase = primaryDatasource?.postgresql?.database ?? "";
275-
const connectors = await listConnectors(choice.service.name, [
276-
"connectors.name",
277-
"connectors.source.files",
278-
]);
279-
if (connectors.length) {
280-
info.connectors = connectors.map((c) => {
281-
const id = c.name.split("/").pop()!;
282-
return {
283-
id,
284-
path: connectors.length === 1 ? "./connector" : `./${id}`,
285-
files: c.source.files || [],
286-
};
287-
});
231+
// TODO (b/344021748): Support initing with services that have existing sources/files
232+
const existingServices = await listAllServices(setup.projectId);
233+
const existingServicesAndSchemas = await Promise.all(
234+
existingServices.map(async (s) => {
235+
return {
236+
service: s,
237+
schema: await getSchema(s.name),
238+
};
239+
}),
240+
);
241+
if (existingServicesAndSchemas.length) {
242+
const choices: { name: string; value: any }[] = existingServicesAndSchemas.map((s) => {
243+
const serviceName = parseServiceName(s.service.name);
244+
return {
245+
name: `${serviceName.location}/${serviceName.serviceId}`,
246+
value: s,
247+
};
248+
});
249+
choices.push({ name: "Create a new service", value: undefined });
250+
const choice: { service: Service; schema: Schema } = await promptOnce({
251+
message:
252+
"Your project already has existing services. Which would you like to set up local files for?",
253+
type: "list",
254+
choices,
255+
});
256+
if (choice) {
257+
const serviceName = parseServiceName(choice.service.name);
258+
info.serviceId = serviceName.serviceId;
259+
info.locationId = serviceName.location;
260+
if (choice.schema) {
261+
const primaryDatasource = choice.schema.datasources.find((d) => d.postgresql);
262+
if (primaryDatasource?.postgresql?.cloudSql.instance) {
263+
const instanceName = parseCloudSQLInstanceName(
264+
primaryDatasource.postgresql.cloudSql.instance,
265+
);
266+
info.cloudSqlInstanceId = instanceName.instanceId;
267+
}
268+
if (choice.schema.source.files) {
269+
info.schemaGql = choice.schema.source.files;
270+
}
271+
info.cloudSqlDatabase = primaryDatasource?.postgresql?.database ?? "";
272+
const connectors = await listConnectors(choice.service.name, [
273+
"connectors.name",
274+
"connectors.source.files",
275+
]);
276+
if (connectors.length) {
277+
info.connectors = connectors.map((c) => {
278+
const id = c.name.split("/").pop()!;
279+
return {
280+
id,
281+
path: connectors.length === 1 ? "./connector" : `./${id}`,
282+
files: c.source.files || [],
283+
};
284+
});
285+
}
288286
}
289287
}
290288
}
289+
} else {
290+
await ensureSparkApis(setup.projectId);
291291
}
292292
}
293293

0 commit comments

Comments
 (0)