Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@
"source-map-support": "^0.5.9",
"supertest": "^6.2.3",
"swagger2openapi": "^7.0.8",
"ts-node": "^10.4.0",
"ts-node": "^10.9.2",
"typescript": "^4.5.4",
"typescript-json-schema": "^0.65.1",
"vite": "^4.2.1"
Expand Down
14 changes: 11 additions & 3 deletions src/commands/dataconnect-sdk-generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,32 @@ import { Command } from "../command";
import { Options } from "../options";
import { DataConnectEmulator } from "../emulator/dataconnectEmulator";
import { needProjectId } from "../projectUtils";
import { loadAll } from "../dataconnect/load";
import { loadAll, pickService } from "../dataconnect/load";
import { logger } from "../logger";
import { getProjectDefaultAccount } from "../auth";
import { logLabeledSuccess } from "../utils";
import { ServiceInfo } from "../dataconnect/types";

type GenerateOptions = Options & { watch?: boolean };
type GenerateOptions = Options & { watch?: boolean; service?: string };

export const command = new Command("dataconnect:sdk:generate")
.description("generate typed SDKs for your Data Connect connectors")
.option(
"--service <serviceId>",
"the serviceId of the Data Connect service. If not provided, generates SDKs for all services.",
)
.option("--location <location>", "the location of the Data Connect service", "us-central1")
.option(
"--watch",
"watch for changes to your connector GQL files and regenerate your SDKs when updates occur",
)
.action(async (options: GenerateOptions) => {
const projectId = needProjectId(options);
const location = options.location as string;

const serviceInfos = await loadAll(projectId, options.config);
const serviceInfos = options.service
? [await pickService(projectId, options.config, options.service, location)]
: await loadAll(projectId, options.config, location);
const serviceInfosWithSDKs = serviceInfos.filter((serviceInfo) =>
serviceInfo.connectorInfo.some((c) => {
return (
Expand Down
13 changes: 10 additions & 3 deletions src/commands/dataconnect-sql-diff.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,27 @@
import { diffSchema } from "../dataconnect/schemaMigration";
import { requireAuth } from "../requireAuth";

export const command = new Command("dataconnect:sql:diff [serviceId]")
export const command = new Command("dataconnect:sql:diff")
.description(
"display the differences between a local Data Connect schema and your CloudSQL database's current schema",
)
.option("--service <serviceId>", "the serviceId of the Data Connect service")
.option("--location <location>", "the location of the Data Connect service", "us-central1")
.before(requirePermissions, [
"firebasedataconnect.services.list",
"firebasedataconnect.schemas.list",
"firebasedataconnect.schemas.update",
])
.before(requireAuth)
.action(async (serviceId: string, options: Options) => {
.action(async (options: Options) => {
const projectId = needProjectId(options);
if (!options.service) {
throw new FirebaseError("Missing required flag --service");

Check failure on line 25 in src/commands/dataconnect-sql-diff.ts

View workflow job for this annotation

GitHub Actions / unit (20)

Cannot find name 'FirebaseError'.

Check failure on line 25 in src/commands/dataconnect-sql-diff.ts

View workflow job for this annotation

GitHub Actions / unit (22)

Cannot find name 'FirebaseError'.

Check failure on line 25 in src/commands/dataconnect-sql-diff.ts

View workflow job for this annotation

GitHub Actions / vscode_unit (20)

Cannot find name 'FirebaseError'.

Check failure on line 25 in src/commands/dataconnect-sql-diff.ts

View workflow job for this annotation

GitHub Actions / check-json-schema (20)

Cannot find name 'FirebaseError'.

Check failure on line 25 in src/commands/dataconnect-sql-diff.ts

View workflow job for this annotation

GitHub Actions / check-json-schema (22)

Cannot find name 'FirebaseError'.

Check failure on line 25 in src/commands/dataconnect-sql-diff.ts

View workflow job for this annotation

GitHub Actions / check-json-schema (22)

Cannot find name 'FirebaseError'.

Check failure on line 25 in src/commands/dataconnect-sql-diff.ts

View workflow job for this annotation

GitHub Actions / vscode_unit (22)

Cannot find name 'FirebaseError'.

Check failure on line 25 in src/commands/dataconnect-sql-diff.ts

View workflow job for this annotation

GitHub Actions / unit (20)

Cannot find name 'FirebaseError'.

Check failure on line 25 in src/commands/dataconnect-sql-diff.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Cannot find name 'FirebaseError'.

Check failure on line 25 in src/commands/dataconnect-sql-diff.ts

View workflow job for this annotation

GitHub Actions / unit (22)

Cannot find name 'FirebaseError'.

Check failure on line 25 in src/commands/dataconnect-sql-diff.ts

View workflow job for this annotation

GitHub Actions / check-json-schema (20)

Cannot find name 'FirebaseError'.
}
const serviceId = options.service as string;
const location = options.location as string;
await ensureApis(projectId);
const serviceInfo = await pickService(projectId, options.config, serviceId);
const serviceInfo = await pickService(projectId, options.config, serviceId, location);

const diffs = await diffSchema(
options,
Expand Down
13 changes: 10 additions & 3 deletions src/commands/dataconnect-sql-grant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,23 @@ import { iamUserIsCSQLAdmin } from "../gcp/cloudsql/cloudsqladmin";

const allowedRoles = Object.keys(fdcSqlRoleMap);

export const command = new Command("dataconnect:sql:grant [serviceId]")
export const command = new Command("dataconnect:sql:grant")
.description("grants the SQL role <role> to the provided user or service account <email>")
.option("--service <serviceId>", "the serviceId of the Data Connect service")
.option("--location <location>", "the location of the Data Connect service", "us-central1")
.option("-R, --role <role>", "The SQL role to grant. One of: owner, writer, or reader.")
.option(
"-E, --email <email>",
"The email of the user or service account we would like to grant the role to.",
)
.before(requirePermissions, ["firebasedataconnect.services.list"])
.before(requireAuth)
.action(async (serviceId: string, options: Options) => {
.action(async (options: Options) => {
if (!options.service) {
throw new FirebaseError("Missing required flag --service");
}
const serviceId = options.service as string;
const location = options.location as string;
const role = options.role as string;
const email = options.email as string;
if (!role) {
Expand Down Expand Up @@ -49,7 +56,7 @@ export const command = new Command("dataconnect:sql:grant [serviceId]")

const projectId = needProjectId(options);
await ensureApis(projectId);
const serviceInfo = await pickService(projectId, options.config, serviceId);
const serviceInfo = await pickService(projectId, options.config, serviceId, location);

await grantRoleToUserInSchema(options, serviceInfo.schema);
return { projectId, serviceId };
Expand Down
13 changes: 10 additions & 3 deletions src/commands/dataconnect-sql-migrate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ import { requirePermissions } from "../requirePermissions";
import { ensureApis } from "../dataconnect/ensureApis";
import { logLabeledSuccess } from "../utils";

export const command = new Command("dataconnect:sql:migrate [serviceId]")
export const command = new Command("dataconnect:sql:migrate")
.description("migrate your CloudSQL database's schema to match your local Data Connect schema")
.option("--service <serviceId>", "the serviceId of the Data Connect service")
.option("--location <location>", "the location of the Data Connect service", "us-central1")
.before(requirePermissions, [
"firebasedataconnect.services.list",
"firebasedataconnect.schemas.list",
Expand All @@ -19,10 +21,15 @@ export const command = new Command("dataconnect:sql:migrate [serviceId]")
])
.before(requireAuth)
.withForce("execute any required database changes without prompting")
.action(async (serviceId: string, options: Options) => {
.action(async (options: Options) => {
const projectId = needProjectId(options);
if (!options.service) {
throw new FirebaseError("Missing required flag --service");
}
const serviceId = options.service as string;
const location = options.location as string;
await ensureApis(projectId);
const serviceInfo = await pickService(projectId, options.config, serviceId);
const serviceInfo = await pickService(projectId, options.config, serviceId, location);
const instanceId =
serviceInfo.dataConnectYaml.schema.datasource.postgresql?.cloudSql.instanceId;
if (!instanceId) {
Expand Down
13 changes: 10 additions & 3 deletions src/commands/dataconnect-sql-setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,26 @@ import { DEFAULT_SCHEMA } from "../gcp/cloudsql/permissions";
import { getIdentifiers, ensureServiceIsConnectedToCloudSql } from "../dataconnect/schemaMigration";
import { setupIAMUsers } from "../gcp/cloudsql/connect";

export const command = new Command("dataconnect:sql:setup [serviceId]")
export const command = new Command("dataconnect:sql:setup")
.description("set up your CloudSQL database")
.option("--service <serviceId>", "the serviceId of the Data Connect service")
.option("--location <location>", "the location of the Data Connect service", "us-central1")
.before(requirePermissions, [
"firebasedataconnect.services.list",
"firebasedataconnect.schemas.list",
"firebasedataconnect.schemas.update",
"cloudsql.instances.connect",
])
.before(requireAuth)
.action(async (serviceId: string, options: Options) => {
.action(async (options: Options) => {
const projectId = needProjectId(options);
if (!options.service) {
throw new FirebaseError("Missing required flag --service");
}
const serviceId = options.service as string;
const location = options.location as string;
await ensureApis(projectId);
const serviceInfo = await pickService(projectId, options.config, serviceId);
const serviceInfo = await pickService(projectId, options.config, serviceId, location);
const instanceId =
serviceInfo.dataConnectYaml.schema.datasource.postgresql?.cloudSql.instanceId;
if (!instanceId) {
Expand Down
13 changes: 10 additions & 3 deletions src/commands/dataconnect-sql-shell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,23 @@ async function mainShellLoop(conn: pg.PoolClient) {
}
}

export const command = new Command("dataconnect:sql:shell [serviceId]")
export const command = new Command("dataconnect:sql:shell")
.description(
"start a shell connected directly to your Data Connect service's linked CloudSQL instance",
)
.option("--service <serviceId>", "the serviceId of the Data Connect service")
.option("--location <location>", "the location of the Data Connect service", "us-central1")
.before(requirePermissions, ["firebasedataconnect.services.list", "cloudsql.instances.connect"])
.before(requireAuth)
.action(async (serviceId: string, options: Options) => {
.action(async (options: Options) => {
const projectId = needProjectId(options);
if (!options.service) {
throw new FirebaseError("Missing required flag --service");
}
const serviceId = options.service as string;
const location = options.location as string;
await ensureApis(projectId);
const serviceInfo = await pickService(projectId, options.config, serviceId);
const serviceInfo = await pickService(projectId, options.config, serviceId, location);
const { instanceId, databaseId } = getIdentifiers(serviceInfo.schema);
const { user: username } = await getIAMUser(options);
const instance = await cloudSqlAdminClient.getInstance(projectId, instanceId);
Expand Down
15 changes: 12 additions & 3 deletions src/dataconnect/load.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ export async function pickService(
projectId: string,
config: Config,
serviceId?: string,
location?: string,
): Promise<ServiceInfo> {
const serviceInfos = await loadAll(projectId, config);
const serviceInfos = await loadAll(projectId, config, location);
if (serviceInfos.length === 0) {
throw new FirebaseError(
"No Data Connect services found in firebase.json." +
Expand Down Expand Up @@ -58,9 +59,17 @@ export async function pickService(
/**
* Loads all Data Connect service configurations from the firebase.json file.
*/
export async function loadAll(projectId: string, config: Config): Promise<ServiceInfo[]> {
export async function loadAll(
projectId: string,
config: Config,
location?: string,
): Promise<ServiceInfo[]> {
const serviceCfgs = readFirebaseJson(config);
return await Promise.all(serviceCfgs.map((c) => load(projectId, config, c.source)));
let serviceInfos = await Promise.all(serviceCfgs.map((c) => load(projectId, config, c.source)));
if (location) {
serviceInfos = serviceInfos.filter((si) => si.dataConnectYaml.location === location);
}
return serviceInfos;
}

/**
Expand Down
Loading