Skip to content

Commit 41f362b

Browse files
committed
fix(google-oauth): Allow to specify the PubSub Topic Name instead of using the autogenerated value
1 parent 05b4be8 commit 41f362b

File tree

5 files changed

+88
-6
lines changed

5 files changed

+88
-6
lines changed

Diff for: lib/oauth/gmail.js

+1
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ class GmailOauth {
144144

145145
this.serviceClient = opts.serviceClient;
146146
this.googleProjectId = opts.googleProjectId;
147+
147148
this.serviceClientEmail = opts.serviceClientEmail;
148149
this.serviceKey = opts.serviceKey;
149150

Diff for: lib/oauth2-apps.js

+12-2
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,17 @@ class OAuth2AppsHandler {
268268
if (opts.query) {
269269
let queryStr = opts.query.replace(/\s+/g, ' ').toLowerCase().trim();
270270
response.apps = response.apps.filter(appData => {
271-
for (let key of ['id', 'name', 'description', 'title', 'googleProjectId', 'clientId', 'serviceClientEmail', 'serviceClient']) {
271+
for (let key of [
272+
'id',
273+
'name',
274+
'description',
275+
'title',
276+
'googleProjectId',
277+
'clientId',
278+
'serviceClientEmail',
279+
'serviceClient',
280+
'googleTopicName'
281+
]) {
272282
let value = appData[key]?.replace(/\s+/g, ' ').toLowerCase().trim() || '';
273283
if (value.indexOf(queryStr) >= 0) {
274284
return true;
@@ -824,7 +834,7 @@ class OAuth2AppsHandler {
824834

825835
async ensurePubsub(appData) {
826836
let project = appData.googleProjectId;
827-
let topic = `ee-pub-${appData.id}`;
837+
let topic = appData.googleTopicName || `ee-pub-${appData.id}`;
828838

829839
let subscription = `ee-sub-${appData.id}`;
830840

Diff for: lib/schemas.js

+9
Original file line numberDiff line numberDiff line change
@@ -1272,6 +1272,13 @@ const accountSchemas = {
12721272
};
12731273

12741274
const googleProjectIdSchema = Joi.string().trim().allow('', false, null).max(256).example('project-name-425411').description('Google Cloud Project ID');
1275+
const googleTopicNameSchema = Joi.string()
1276+
.trim()
1277+
.allow('', false, null)
1278+
.pattern(/^(?!goog)[A-Za-z][A-Za-z0-9\-_.~+%]{2,254}$/)
1279+
.max(256)
1280+
.example('ee-pubsub-12345')
1281+
.description('Topic name for Google Pub/Sub');
12751282

12761283
const googleWorkspaceAccountsSchema = Joi.boolean()
12771284
.truthy('Y', 'true', '1', 'on')
@@ -1367,6 +1374,7 @@ const oauthCreateSchema = {
13671374

13681375
googleProjectId: googleProjectIdSchema,
13691376
googleWorkspaceAccounts: googleWorkspaceAccountsSchema,
1377+
googleTopicName: googleTopicNameSchema,
13701378

13711379
serviceClientEmail: Joi.string()
13721380
.trim()
@@ -1641,6 +1649,7 @@ module.exports = {
16411649
fromAddressSchema,
16421650
outboxEntrySchema,
16431651
googleProjectIdSchema,
1652+
googleTopicNameSchema,
16441653
googleWorkspaceAccountsSchema,
16451654
messageReferenceSchema
16461655
};

Diff for: views/partials/oauth_form.hbs

+54-4
Original file line numberDiff line numberDiff line change
@@ -356,8 +356,8 @@
356356
<tr>
357357
<td>
358358
<div class="form-check">
359-
<input class="form-check-input" type="radio" name="baseScopes" id="baseScopesImap" value="imap"
360-
{{#if baseScopesImap}}checked{{/if}}>
359+
<input class="form-check-input base-scopes-radio" type="radio" name="baseScopes"
360+
id="baseScopesImap" value="imap" {{#if baseScopesImap}}checked{{/if}}>
361361
<label class="form-check-label" for="baseScopesImap">
362362
IMAP and SMTP
363363
</label>
@@ -370,8 +370,8 @@
370370
<tr>
371371
<td>
372372
<div class="form-check">
373-
<input class="form-check-input" type="radio" name="baseScopes" id="baseScopesPubsub"
374-
value="pubsub" {{#if baseScopesPubsub}}checked{{/if}}>
373+
<input class="form-check-input base-scopes-radio" type="radio" name="baseScopes"
374+
id="baseScopesPubsub" value="pubsub" {{#if baseScopesPubsub}}checked{{/if}}>
375375
<label class="form-check-label" for="baseScopesPubsub">
376376
Cloud Pub/Sub <span class="badge badge-dark">beta</span>
377377
</label>
@@ -410,6 +410,42 @@
410410

411411
</table>
412412

413+
<div id="select-pubsub-app" class="card-footer {{#unless baseScopesPubsub}}d-none{{/unless}}">
414+
415+
{{#if actionCreate}}
416+
417+
<div class="form-group">
418+
<label for="googleTopicName">
419+
Google Pub/Sub Topic Name
420+
</label>
421+
<input type="text" class="form-control {{#if errors.googleTopicName}}is-invalid{{/if}}" id="googleTopicName"
422+
name="googleTopicName" value="{{values.googleTopicName}}"
423+
placeholder="Enter the Topic Name for the Google Pub/Sub subscription, for example &quot;ee-pubsub-12345&quot;" />
424+
{{#if errors.googleTopicName}}
425+
<span class="invalid-feedback">{{errors.googleTopicName}}</span>
426+
{{/if}}
427+
<small class="form-text text-muted">OAuth2 Pub/Sub Topic Name. Automatically generated if not set.</small>
428+
</div>
429+
430+
{{else}}
431+
432+
{{#if appData.pubSubTopic}}
433+
434+
Pub/Sub Topic:
435+
<code>
436+
{{lastVal appData.pubSubTopic "/"}}
437+
</code>
438+
439+
{{else}}
440+
441+
Pub/Sub Topic not set up
442+
443+
{{/if}}
444+
445+
{{/if}}
446+
447+
</div>
448+
413449
</div>
414450
{{/if}}
415451

@@ -709,6 +745,7 @@
709745
710746
function checkScopesRadio() {
711747
let baseScopesAPIElm = document.getElementById('baseScopesAPI');
748+
let baseScopesPubsubElm = document.getElementById('baseScopesPubsub');
712749
let selectPubsubAppElm = document.getElementById('select-pubsub-app');
713750
714751
if (baseScopesAPIElm && selectPubsubAppElm) {
@@ -720,6 +757,15 @@
720757
pubSubAppElm.disabled = true;
721758
}
722759
}
760+
761+
if (baseScopesPubsubElm && selectPubsubAppElm) {
762+
if (baseScopesPubsubElm.checked) {
763+
selectPubsubAppElm.classList.remove('d-none');
764+
} else {
765+
selectPubsubAppElm.classList.add('d-none');
766+
}
767+
}
768+
723769
}
724770
725771
document.querySelectorAll('.base-scopes-radio').forEach(radioElm => {
@@ -805,6 +851,10 @@
805851
let authorityElms = document.querySelectorAll('.r-auth');
806852
let tenantElm = document.getElementById('tenant');
807853
let checkAuthorityState = () => {
854+
if (!tenantElm) {
855+
return
856+
}
857+
808858
let showtenant = false;
809859
for (let aElm of authorityElms) {
810860
if (aElm.checked) {

Diff for: workers/api.js

+12
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ const {
163163
outboxEntrySchema,
164164
googleProjectIdSchema,
165165
googleWorkspaceAccountsSchema,
166+
googleTopicNameSchema,
166167
messageReferenceSchema
167168
} = require('../lib/schemas');
168169

@@ -528,6 +529,14 @@ const init = async () => {
528529
return new handlebars.SafeString(res);
529530
});
530531

532+
handlebars.registerHelper('lastVal', (value, separator) => {
533+
separator = separator || '/';
534+
535+
let res = (value || '').toString().split(separator).pop();
536+
537+
return new handlebars.SafeString(res);
538+
});
539+
531540
handlebars.registerHelper('formatInteger', (intVal, locale) => {
532541
if (isNaN(intVal)) {
533542
// ignore non-numbers
@@ -6861,6 +6870,7 @@ const init = async () => {
68616870

68626871
googleProjectId: googleProjectIdSchema,
68636872
googleWorkspaceAccounts: googleWorkspaceAccountsSchema,
6873+
googleTopicName: googleTopicNameSchema,
68646874

68656875
serviceClientEmail: Joi.string()
68666876
.email()
@@ -6990,6 +7000,7 @@ const init = async () => {
69907000

69917001
googleProjectId: googleProjectIdSchema,
69927002
googleWorkspaceAccounts: googleWorkspaceAccountsSchema,
7003+
googleTopicName: googleTopicNameSchema,
69937004

69947005
serviceClientEmail: Joi.string()
69957006
.email()
@@ -7165,6 +7176,7 @@ const init = async () => {
71657176

71667177
googleProjectId: googleProjectIdSchema,
71677178
googleWorkspaceAccounts: googleWorkspaceAccountsSchema,
7179+
googleTopicName: googleTopicNameSchema,
71687180

71697181
serviceClientEmail: Joi.string()
71707182
.email()

0 commit comments

Comments
 (0)