Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for deploying new blocking triggers #6384

Merged
merged 18 commits into from
Oct 21, 2024
Merged
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
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
- Added new command `dataconnect:sql:shell` which run queries against Data Connect CloudSQL instances (#7778).
- Add support for deploying new blocking triggers. (#6384)
36 changes: 33 additions & 3 deletions src/deploy/functions/services/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,18 @@
}
}

private configChanged(

Check warning on line 48 in src/deploy/functions/services/auth.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Missing return type on function
newConfig: identityPlatform.BlockingFunctionsConfig,
config: identityPlatform.BlockingFunctionsConfig,
) {
if (
newConfig.triggers?.beforeCreate?.functionUri !==
config.triggers?.beforeCreate?.functionUri ||
newConfig.triggers?.beforeSignIn?.functionUri !== config.triggers?.beforeSignIn?.functionUri
newConfig.triggers?.beforeSignIn?.functionUri !==
config.triggers?.beforeSignIn?.functionUri ||
newConfig.triggers?.beforeSendEmail?.functionUri !==
config.triggers?.beforeSendEmail?.functionUri ||
newConfig.triggers?.beforeSendSms?.functionUri !== config.triggers?.beforeSendSms?.functionUri
) {
return true;
}
Expand All @@ -79,16 +83,34 @@
newBlockingConfig.triggers = {
...newBlockingConfig.triggers,
beforeCreate: {
functionUri: endpoint.uri!,

Check warning on line 86 in src/deploy/functions/services/auth.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Forbidden non-null assertion
},
};
} else {
} else if (endpoint.blockingTrigger.eventType === events.v1.BEFORE_SIGN_IN_EVENT) {
newBlockingConfig.triggers = {
...newBlockingConfig.triggers,
beforeSignIn: {
functionUri: endpoint.uri!,

Check warning on line 93 in src/deploy/functions/services/auth.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Forbidden non-null assertion
},
};
} else if (endpoint.blockingTrigger.eventType === events.v1.BEFORE_SEND_EMAIL_EVENT) {
newBlockingConfig.triggers = {
...newBlockingConfig.triggers,
beforeSendEmail: {
functionUri: endpoint.uri!,

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

View workflow job for this annotation

GitHub Actions / lint (20)

Forbidden non-null assertion
},
};
} else if (endpoint.blockingTrigger.eventType === events.v1.BEFORE_SEND_SMS_EVENT) {
newBlockingConfig.triggers = {
...newBlockingConfig.triggers,
beforeSendSms: {
functionUri: endpoint.uri!,

Check warning on line 107 in src/deploy/functions/services/auth.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Forbidden non-null assertion
},
};
} else {
throw new FirebaseError(
`Received invalid blocking trigger event type ${endpoint.blockingTrigger.eventType}`,
);
}

newBlockingConfig.forwardInboundCredentials = {
Expand Down Expand Up @@ -121,7 +143,9 @@
const blockingConfig = await identityPlatform.getBlockingFunctionsConfig(endpoint.project);
if (
endpoint.uri !== blockingConfig.triggers?.beforeCreate?.functionUri &&
endpoint.uri !== blockingConfig.triggers?.beforeSignIn?.functionUri
endpoint.uri !== blockingConfig.triggers?.beforeSignIn?.functionUri &&
endpoint.uri !== blockingConfig.triggers?.beforeSendEmail?.functionUri &&
endpoint.uri !== blockingConfig.triggers?.beforeSendSms?.functionUri
) {
return;
}
Expand All @@ -135,6 +159,12 @@
if (endpoint.uri === blockingConfig.triggers?.beforeSignIn?.functionUri) {
delete blockingConfig.triggers?.beforeSignIn;
}
if (endpoint.uri === blockingConfig.triggers?.beforeSendEmail?.functionUri) {
delete blockingConfig.triggers?.beforeSendEmail;
}
if (endpoint.uri === blockingConfig.triggers?.beforeSendSms?.functionUri) {
delete blockingConfig.triggers?.beforeSendSms;
}

await identityPlatform.setBlockingFunctionsConfig(endpoint.project, blockingConfig);
}
Expand Down
2 changes: 2 additions & 0 deletions src/deploy/functions/services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
name: "noop",
api: "",
ensureTriggerRegion: noop,
validateTrigger: noop,

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

View workflow job for this annotation

GitHub Actions / lint (20)

Promise-returning function provided to property where a void return was expected
registerTrigger: noop,
unregisterTrigger: noop,
};
Expand All @@ -56,7 +56,7 @@
api: "pubsub.googleapis.com",
requiredProjectBindings: noopProjectBindings,
ensureTriggerRegion: noop,
validateTrigger: noop,

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

View workflow job for this annotation

GitHub Actions / lint (20)

Promise-returning function provided to property where a void return was expected
registerTrigger: noop,
unregisterTrigger: noop,
};
Expand All @@ -67,7 +67,7 @@
api: "storage.googleapis.com",
requiredProjectBindings: obtainStorageBindings,
ensureTriggerRegion: ensureStorageTriggerRegion,
validateTrigger: noop,

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

View workflow job for this annotation

GitHub Actions / lint (20)

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

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

View workflow job for this annotation

GitHub Actions / lint (20)

Promise-returning function provided to property where a void return was expected
registerTrigger: noop,
unregisterTrigger: noop,
};
Expand All @@ -92,7 +92,7 @@
api: "firebasedatabase.googleapis.com",
requiredProjectBindings: noopProjectBindings,
ensureTriggerRegion: ensureDatabaseTriggerRegion,
validateTrigger: noop,

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

View workflow job for this annotation

GitHub Actions / lint (20)

Promise-returning function provided to property where a void return was expected
registerTrigger: noop,
unregisterTrigger: noop,
};
Expand Down Expand Up @@ -140,6 +140,8 @@
"google.firebase.firebasealerts.alerts.v1.published": firebaseAlertsService,
"providers/cloud.auth/eventTypes/user.beforeCreate": authBlockingService,
"providers/cloud.auth/eventTypes/user.beforeSignIn": authBlockingService,
"providers/cloud.auth/eventTypes/user.beforeSendEmail": authBlockingService,
"providers/cloud.auth/eventTypes/user.beforeSendSms": authBlockingService,
"google.firebase.database.ref.v1.written": databaseService,
"google.firebase.database.ref.v1.created": databaseService,
"google.firebase.database.ref.v1.updated": databaseService,
Expand Down
5 changes: 5 additions & 0 deletions src/functions/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@ export const BLOCKING_LABEL = "deployment-blocking";
export const BLOCKING_LABEL_KEY_TO_EVENT: Record<string, (typeof AUTH_BLOCKING_EVENTS)[number]> = {
"before-create": "providers/cloud.auth/eventTypes/user.beforeCreate",
"before-sign-in": "providers/cloud.auth/eventTypes/user.beforeSignIn",
"before-send-email": "providers/cloud.auth/eventTypes/user.beforeSendEmail",
"before-send-sms": "providers/cloud.auth/eventTypes/user.beforeSendSms",
};

export const BLOCKING_EVENT_TO_LABEL_KEY: Record<(typeof AUTH_BLOCKING_EVENTS)[number], string> = {
"providers/cloud.auth/eventTypes/user.beforeCreate": "before-create",
"providers/cloud.auth/eventTypes/user.beforeSignIn": "before-sign-in",
"providers/cloud.auth/eventTypes/user.beforeSendEmail": "before-send-email",
"providers/cloud.auth/eventTypes/user.beforeSendSms": "before-send-sms",
};
11 changes: 10 additions & 1 deletion src/functions/events/v1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@ export const BEFORE_CREATE_EVENT = "providers/cloud.auth/eventTypes/user.beforeC

export const BEFORE_SIGN_IN_EVENT = "providers/cloud.auth/eventTypes/user.beforeSignIn";

export const AUTH_BLOCKING_EVENTS = [BEFORE_CREATE_EVENT, BEFORE_SIGN_IN_EVENT] as const;
export const BEFORE_SEND_EMAIL_EVENT = "providers/cloud.auth/eventTypes/user.beforeSendEmail";

export const BEFORE_SEND_SMS_EVENT = "providers/cloud.auth/eventTypes/user.beforeSendSms";

export const AUTH_BLOCKING_EVENTS = [
BEFORE_CREATE_EVENT,
BEFORE_SIGN_IN_EVENT,
BEFORE_SEND_EMAIL_EVENT,
BEFORE_SEND_SMS_EVENT,
] as const;

export type Event = (typeof AUTH_BLOCKING_EVENTS)[number];
2 changes: 2 additions & 0 deletions src/gcp/identityPlatform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ export interface BlockingFunctionsConfig {
triggers?: {
beforeCreate?: BlockingFunctionsEventDetails;
beforeSignIn?: BlockingFunctionsEventDetails;
beforeSendEmail?: BlockingFunctionsEventDetails;
beforeSendSms?: BlockingFunctionsEventDetails;
};
forwardInboundCredentials?: BlockingFunctionsOptions;
}
Expand Down
Loading