Skip to content

Commit 529f698

Browse files
committed
fix(gmail-watch): Allow setting subscription name for Gmail PubSub
1 parent 7a59ce9 commit 529f698

File tree

5 files changed

+61
-17
lines changed

5 files changed

+61
-17
lines changed

lib/oauth2-apps.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,8 @@ class OAuth2AppsHandler {
277277
'clientId',
278278
'serviceClientEmail',
279279
'serviceClient',
280-
'googleTopicName'
280+
'googleTopicName',
281+
'googleSubscriptionName'
281282
]) {
282283
let value = appData[key]?.replace(/\s+/g, ' ').toLowerCase().trim() || '';
283284
if (value.indexOf(queryStr) >= 0) {
@@ -834,9 +835,9 @@ class OAuth2AppsHandler {
834835

835836
async ensurePubsub(appData) {
836837
let project = appData.googleProjectId;
837-
let topic = appData.googleTopicName || `ee-pub-${appData.id}`;
838838

839-
let subscription = `ee-sub-${appData.id}`;
839+
let topic = appData.googleTopicName || `ee-pub-${appData.id}`;
840+
let subscription = appData.googleSubscriptionName || `ee-sub-${appData.id}`;
840841

841842
let results = {};
842843

lib/schemas.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1277,9 +1277,17 @@ const googleTopicNameSchema = Joi.string()
12771277
.allow('', false, null)
12781278
.pattern(/^(?!goog)[A-Za-z][A-Za-z0-9\-_.~+%]{2,254}$/)
12791279
.max(256)
1280-
.example('ee-pubsub-12345')
1280+
.example('ee-pub-12345')
12811281
.description('Topic name for Google Pub/Sub');
12821282

1283+
const googleSubscriptionNameSchema = Joi.string()
1284+
.trim()
1285+
.allow('', false, null)
1286+
.pattern(/^(?!goog)[A-Za-z][A-Za-z0-9\-_.~+%]{2,254}$/)
1287+
.max(256)
1288+
.example('ee-sub-12345')
1289+
.description('Subscription name for Google Pub/Sub');
1290+
12831291
const googleWorkspaceAccountsSchema = Joi.boolean()
12841292
.truthy('Y', 'true', '1', 'on')
12851293
.falsy('N', 'false', 0, '')
@@ -1375,6 +1383,7 @@ const oauthCreateSchema = {
13751383
googleProjectId: googleProjectIdSchema,
13761384
googleWorkspaceAccounts: googleWorkspaceAccountsSchema,
13771385
googleTopicName: googleTopicNameSchema,
1386+
googleSubscriptionName: googleSubscriptionNameSchema,
13781387

13791388
serviceClientEmail: Joi.string()
13801389
.trim()
@@ -1650,6 +1659,7 @@ module.exports = {
16501659
outboxEntrySchema,
16511660
googleProjectIdSchema,
16521661
googleTopicNameSchema,
1662+
googleSubscriptionNameSchema,
16531663
googleWorkspaceAccountsSchema,
16541664
messageReferenceSchema
16551665
};

views/config/oauth/app.hbs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@
228228
{{#if app.pubSubTopic}}
229229
<span class="badge badge-success" title="{{app.pubSubTopic}}" data-toggle="tooltip" data-placement="top"
230230
style="cursor: default;">Created</span>
231+
<small class="text-monospace">{{lastVal app.pubSubTopic "/"}}</small>
231232
{{else}}
232233
<span class="badge badge-danger" style="cursor: default;">Not set</span>
233234
{{/if}}
@@ -238,6 +239,8 @@
238239
{{#if app.pubSubSubscription}}
239240
<span class="badge badge-success" title="{{app.pubSubSubscription}}" data-toggle="tooltip"
240241
data-placement="top" style="cursor: default;">Created</span>
242+
243+
<small class="text-monospace">{{lastVal app.pubSubSubscription "/"}}</small>
241244
{{else}}
242245
<span class="badge badge-danger" style="cursor: default;">Not set</span>
243246
{{/if}}

views/partials/oauth_form.hbs

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@
138138
<label for="serviceClientEmail">
139139
Client Email
140140
</label>
141-
<input type="text" class="form-control {{#if errors.serviceClientEmail}}is-invalid{{/if}}"
141+
<input type="email" class="form-control {{#if errors.serviceClientEmail}}is-invalid{{/if}}"
142142
id="serviceClientEmail" name="serviceClientEmail" value="{{values.serviceClientEmail}}"
143143
placeholder="Enter the principal of the service, for example &quot;name@project-123.iam.gserviceaccount.com&quot;"
144144
required />
@@ -153,7 +153,8 @@
153153
Service client
154154
</label>
155155
<input type="text" class="form-control {{#if errors.serviceClient}}is-invalid{{/if}}" id="serviceClient"
156-
name="serviceClient" value="{{values.serviceClient}}" placeholder="Enter service client ID&mldr;" />
156+
name="serviceClient" value="{{values.serviceClient}}" placeholder="Enter service client ID&mldr;"
157+
required />
157158
{{#if errors.serviceClient}}
158159
<span class="invalid-feedback">{{errors.serviceClient}}</span>
159160
{{/if}}
@@ -167,8 +168,8 @@
167168
<textarea class="form-control droptxt autoselect {{#if errors.serviceKey}}is-invalid{{/if}}" id="serviceKey"
168169
name="serviceKey" rows="4" data-enable-grammarly="false" spellcheck="false" {{#if
169170
hasServiceKey}}placeholder="Service key is set but not shown&mldr;" {{else}}
170-
placeholder="Starts with &quot;-----BEGIN PRIVATE KEY-----&quot;&mldr;"
171-
{{/if}}>{{values.serviceKey}}</textarea>
171+
placeholder="Starts with &quot;-----BEGIN PRIVATE KEY-----&quot;&mldr;" {{/if}} {{#unless
172+
hasServiceKey}}required{{/unless}}>{{values.serviceKey}}</textarea>
172173
{{#if errors.serviceKey}}
173174
<span class="invalid-feedback">{{errors.serviceKey}}</span>
174175
{{/if}}
@@ -420,27 +421,52 @@
420421
</label>
421422
<input type="text" class="form-control {{#if errors.googleTopicName}}is-invalid{{/if}}" id="googleTopicName"
422423
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+
placeholder="Enter the Topic Name for the Google Pub/Sub subscription, for example &quot;ee-pub-12345&quot;" />
424425
{{#if errors.googleTopicName}}
425426
<span class="invalid-feedback">{{errors.googleTopicName}}</span>
426427
{{/if}}
427428
<small class="form-text text-muted">OAuth2 Pub/Sub Topic Name. Automatically generated if not set.</small>
428429
</div>
429430

431+
<div class="form-group">
432+
<label for="googleSubscriptionName">
433+
Google Pub/Sub Subscription Name
434+
</label>
435+
<input type="text" class="form-control {{#if errors.googleSubscriptionName}}is-invalid{{/if}}"
436+
id="googleSubscriptionName" name="googleSubscriptionName" value="{{values.googleSubscriptionName}}"
437+
placeholder="Enter the Subscription Name for the Google Pub/Sub subscription, for example &quot;ee-sub-12345&quot;" />
438+
{{#if errors.googleSubscriptionName}}
439+
<span class="invalid-feedback">{{errors.googleSubscriptionName}}</span>
440+
{{/if}}
441+
<small class="form-text text-muted">OAuth2 Pub/Sub Subscription Name. Automatically generated if not
442+
set.</small>
443+
</div>
444+
430445
{{else}}
431446

432-
{{#if appData.pubSubTopic}}
447+
<dl class="row">
433448

434-
Pub/Sub Topic:
435-
<code>
436-
{{lastVal appData.pubSubTopic "/"}}
437-
</code>
449+
<dt class="col-sm-3">Pub/Sub Topic</dt>
450+
<dd class="col-sm-9">
451+
{{#if appData.pubSubTopic}}
438452

439-
{{else}}
453+
<code>{{lastVal appData.pubSubTopic "/"}}</code>
454+
{{else}}
455+
Not initialized
456+
{{/if}}
457+
</dd>
440458

441-
Pub/Sub Topic not set up
442459

443-
{{/if}}
460+
<dt class="col-sm-3">Pub/Sub Subscription</dt>
461+
<dd class="col-sm-9">
462+
{{#if appData.pubSubSubscription}}
463+
<code>{{lastVal appData.pubSubSubscription "/"}}</code>
464+
{{else}}
465+
Not initialized
466+
{{/if}}
467+
</dd>
468+
</dl>
469+
444470

445471
{{/if}}
446472

workers/api.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ const {
164164
googleProjectIdSchema,
165165
googleWorkspaceAccountsSchema,
166166
googleTopicNameSchema,
167+
googleSubscriptionNameSchema,
167168
messageReferenceSchema
168169
} = require('../lib/schemas');
169170

@@ -6871,6 +6872,7 @@ const init = async () => {
68716872
googleProjectId: googleProjectIdSchema,
68726873
googleWorkspaceAccounts: googleWorkspaceAccountsSchema,
68736874
googleTopicName: googleTopicNameSchema,
6875+
googleSubscriptionName: googleSubscriptionNameSchema,
68746876

68756877
serviceClientEmail: Joi.string()
68766878
.email()
@@ -7001,6 +7003,7 @@ const init = async () => {
70017003
googleProjectId: googleProjectIdSchema,
70027004
googleWorkspaceAccounts: googleWorkspaceAccountsSchema,
70037005
googleTopicName: googleTopicNameSchema,
7006+
googleSubscriptionName: googleSubscriptionNameSchema,
70047007

70057008
serviceClientEmail: Joi.string()
70067009
.email()
@@ -7177,6 +7180,7 @@ const init = async () => {
71777180
googleProjectId: googleProjectIdSchema,
71787181
googleWorkspaceAccounts: googleWorkspaceAccountsSchema,
71797182
googleTopicName: googleTopicNameSchema,
7183+
googleSubscriptionName: googleSubscriptionNameSchema,
71807184

71817185
serviceClientEmail: Joi.string()
71827186
.email()

0 commit comments

Comments
 (0)