Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
47 changes: 47 additions & 0 deletions src/deploy/functions/services/authEventarc.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { expect } from "chai";
import { Endpoint } from "../backend";
import * as authEventarc from "./authEventarc";

const projectNumber = "123456789";

const endpoint: Endpoint = {
id: "endpoint",
region: "us-central1",
project: projectNumber,
eventTrigger: {
retry: false,
eventType: "google.firebase.auth.user.v2.created",
eventFilters: {},
},
entryPoint: "endpoint",
platform: "gcfv2",
runtime: "nodejs16",
};

describe("ensureAuthEventarcTriggerRegion", () => {
it("should set the trigger location to global", async () => {
const ep = { ...endpoint, eventTrigger: { ...endpoint.eventTrigger } };

await authEventarc.ensureAuthEventarcTriggerRegion(ep);

expect(ep.eventTrigger.region).to.eq("global");
});
Comment thread
shettyvarun268 marked this conversation as resolved.

it("should not error if the trigger location is global", async () => {
const ep = { ...endpoint, eventTrigger: { ...endpoint.eventTrigger } };
ep.eventTrigger.region = "global";

await authEventarc.ensureAuthEventarcTriggerRegion(ep);

expect(ep.eventTrigger.region).to.eq("global");
});
Comment thread
shettyvarun268 marked this conversation as resolved.

it("should error if the trigger location is not global", () => {
const ep = { ...endpoint, eventTrigger: { ...endpoint.eventTrigger } };
ep.eventTrigger.region = "us-west1";

expect(() => authEventarc.ensureAuthEventarcTriggerRegion(ep)).to.throw(
"A Firebase Auth Eventarc trigger must specify 'global' trigger location",
);
});
Comment thread
shettyvarun268 marked this conversation as resolved.
});
20 changes: 20 additions & 0 deletions src/deploy/functions/services/authEventarc.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import * as backend from "../backend";
import { FirebaseError } from "../../../error";

/**
* Sets a Firebase Auth Eventarc event trigger's region to 'global' since the service is global.
* @param endpoint the auth eventarc endpoint
*/
export function ensureAuthEventarcTriggerRegion(
endpoint: backend.Endpoint & backend.EventTriggered,
): Promise<void> {
if (!endpoint.eventTrigger.region) {
endpoint.eventTrigger.region = "global";
}
if (endpoint.eventTrigger.region !== "global") {
throw new FirebaseError(
"A Firebase Auth Eventarc trigger must specify 'global' trigger location",
);
}
return Promise.resolve();
}
Comment thread
shettyvarun268 marked this conversation as resolved.
18 changes: 17 additions & 1 deletion src/deploy/functions/services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
getDefaultRegion as ensureDataConnectDefaultRegion,
} from "./dataconnect";
import { AILogicService } from "./ailogic";
import { ensureAuthEventarcTriggerRegion } from "./authEventarc";

/** A standard void No Op */
export const noop = (): Promise<void> => Promise.resolve();
Expand All @@ -49,7 +50,8 @@
| "testlab"
| "firestore"
| "dataconnect"
| "ailogic";
| "ailogic"
| "autheventarc";

/** A service interface for the underlying GCP event services */
export interface Service {
Expand All @@ -71,7 +73,7 @@
name: "noop",
api: "",
ensureTriggerRegion: noop,
validateTrigger: noop,

Check warning on line 76 in src/deploy/functions/services/index.ts

View workflow job for this annotation

GitHub Actions / lint (24)

Promise-returning function provided to property where a void return was expected
registerTrigger: noop,
unregisterTrigger: noop,
getDefaultRegion: () => Promise.resolve(FALLBACK_DEPLOYMENT_REGION),
Expand All @@ -83,7 +85,7 @@
api: "pubsub.googleapis.com",
requiredProjectBindings: noopProjectBindings,
ensureTriggerRegion: noop,
validateTrigger: noop,

Check warning on line 88 in src/deploy/functions/services/index.ts

View workflow job for this annotation

GitHub Actions / lint (24)

Promise-returning function provided to property where a void return was expected
registerTrigger: noop,
unregisterTrigger: noop,
getDefaultRegion: () => Promise.resolve(DEFAULT_GLOBAL_TRIGGER_REGION),
Expand All @@ -95,7 +97,7 @@
api: "storage.googleapis.com",
requiredProjectBindings: obtainStorageBindings,
ensureTriggerRegion: ensureStorageTriggerRegion,
validateTrigger: noop,

Check warning on line 100 in src/deploy/functions/services/index.ts

View workflow job for this annotation

GitHub Actions / lint (24)

Promise-returning function provided to property where a void return was expected
registerTrigger: noop,
unregisterTrigger: noop,
getDefaultRegion: ensureStorageDefaultRegion,
Expand All @@ -107,7 +109,7 @@
api: "firebasealerts.googleapis.com",
requiredProjectBindings: noopProjectBindings,
ensureTriggerRegion: ensureFirebaseAlertsTriggerRegion,
validateTrigger: noop,

Check warning on line 112 in src/deploy/functions/services/index.ts

View workflow job for this annotation

GitHub Actions / lint (24)

Promise-returning function provided to property where a void return was expected
registerTrigger: noop,
unregisterTrigger: noop,
getDefaultRegion: () => Promise.resolve(DEFAULT_GLOBAL_TRIGGER_REGION),
Expand All @@ -123,7 +125,7 @@
api: "firebasedatabase.googleapis.com",
requiredProjectBindings: noopProjectBindings,
ensureTriggerRegion: ensureDatabaseTriggerRegion,
validateTrigger: noop,

Check warning on line 128 in src/deploy/functions/services/index.ts

View workflow job for this annotation

GitHub Actions / lint (24)

Promise-returning function provided to property where a void return was expected
registerTrigger: noop,
unregisterTrigger: noop,
getDefaultRegion: ensureDatabaseDefaultRegion,
Expand All @@ -135,7 +137,7 @@
api: "firebaseremoteconfig.googleapis.com",
requiredProjectBindings: noopProjectBindings,
ensureTriggerRegion: ensureRemoteConfigTriggerRegion,
validateTrigger: noop,

Check warning on line 140 in src/deploy/functions/services/index.ts

View workflow job for this annotation

GitHub Actions / lint (24)

Promise-returning function provided to property where a void return was expected
registerTrigger: noop,
unregisterTrigger: noop,
getDefaultRegion: () => Promise.resolve(DEFAULT_GLOBAL_TRIGGER_REGION),
Expand All @@ -147,7 +149,7 @@
api: "testing.googleapis.com",
requiredProjectBindings: noopProjectBindings,
ensureTriggerRegion: ensureTestLabTriggerRegion,
validateTrigger: noop,

Check warning on line 152 in src/deploy/functions/services/index.ts

View workflow job for this annotation

GitHub Actions / lint (24)

Promise-returning function provided to property where a void return was expected
registerTrigger: noop,
unregisterTrigger: noop,
getDefaultRegion: () => Promise.resolve(DEFAULT_GLOBAL_TRIGGER_REGION),
Expand All @@ -159,7 +161,7 @@
api: "firestore.googleapis.com",
requiredProjectBindings: noopProjectBindings,
ensureTriggerRegion: ensureFirestoreTriggerRegion,
validateTrigger: noop,

Check warning on line 164 in src/deploy/functions/services/index.ts

View workflow job for this annotation

GitHub Actions / lint (24)

Promise-returning function provided to property where a void return was expected
registerTrigger: noop,
unregisterTrigger: noop,
getDefaultRegion: ensureFirestoreDefaultRegion,
Expand All @@ -171,12 +173,24 @@
api: "firebasedataconnect.googleapis.com",
requiredProjectBindings: noopProjectBindings,
ensureTriggerRegion: ensureDataConnectTriggerRegion,
validateTrigger: noop,

Check warning on line 176 in src/deploy/functions/services/index.ts

View workflow job for this annotation

GitHub Actions / lint (24)

Promise-returning function provided to property where a void return was expected
registerTrigger: noop,
unregisterTrigger: noop,
getDefaultRegion: ensureDataConnectDefaultRegion,
};

/** A Firebase Auth Eventarc service object */
const authEventarcService: Service = {
name: "autheventarc",
api: "eventarc.googleapis.com",
requiredProjectBindings: noopProjectBindings,
ensureTriggerRegion: ensureAuthEventarcTriggerRegion,
validateTrigger: noop,

Check warning on line 188 in src/deploy/functions/services/index.ts

View workflow job for this annotation

GitHub Actions / lint (24)

Promise-returning function provided to property where a void return was expected
registerTrigger: noop,
unregisterTrigger: noop,
getDefaultRegion: () => Promise.resolve(DEFAULT_GLOBAL_TRIGGER_REGION),
};

/** Mapping from event type string to service object */
// TODO: See if there's a way to deduplicate these consts while still ensuring type safety and exhaustion
const EVENT_SERVICE_MAPPING: Record<events.Event, Service> = {
Expand Down Expand Up @@ -207,6 +221,8 @@
"google.firebase.dataconnect.connector.v1.mutationExecuted": dataconnectService,
"google.firebase.ailogic.v1.beforeGenerate": aiLogicService,
"google.firebase.ailogic.v1.afterGenerate": aiLogicService,
"google.firebase.auth.user.v2.created": authEventarcService,
"google.firebase.auth.user.v2.deleted": authEventarcService,
};

export function serviceForEndpoint(endpoint: backend.Endpoint | build.Endpoint): Service {
Expand Down
8 changes: 7 additions & 1 deletion src/functions/events/v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ export const FIREALERTS_EVENT = "google.firebase.firebasealerts.alerts.v1.publis

export const DATACONNECT_EVENT = "google.firebase.dataconnect.connector.v1.mutationExecuted";

export const AUTH_EVENTS = [
"google.firebase.auth.user.v2.created",
"google.firebase.auth.user.v2.deleted",
] as const;

export type Event =
| typeof PUBSUB_PUBLISH_EVENT
| (typeof STORAGE_EVENTS)[number]
Expand All @@ -51,7 +56,8 @@ export type Event =
| (typeof FIRESTORE_EVENTS)[number]
| typeof FIREALERTS_EVENT
| typeof DATACONNECT_EVENT
| (typeof AI_LOGIC_EVENTS)[number];
| (typeof AI_LOGIC_EVENTS)[number]
| (typeof AUTH_EVENTS)[number];

// Why can't auth context be removed? This is map was added to correct a bug where a regex
// allowed any non-auth type to be converted to any auth type, but we should follow up for why
Expand Down
Loading