-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #62 from mondaycom/feature/shaika/use-compute-auth…
…-client Use compute auth client
- Loading branch information
Showing
6 changed files
with
923 additions
and
1,170 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
export default { name: '@mondaycom/apps-sdk', version: '3.0.7' }; | ||
export default { name: '@mondaycom/apps-sdk', version: '3.0.11' }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,49 @@ | ||
import { PubSub } from '@google-cloud/pubsub'; | ||
import { Compute, GoogleAuth } from 'google-auth-library'; | ||
import { JSONClient } from 'google-auth-library/build/src/auth/googleauth'; | ||
|
||
import {BadRequestError, InternalServerError} from 'errors/apps-sdk-error'; | ||
import { BadRequestError, InternalServerError } from 'errors/apps-sdk-error'; | ||
import { IQueue } from 'types/queue'; | ||
import { Logger } from 'utils/logger'; | ||
|
||
const logger = new Logger('Queue', { mondayInternal: true }); | ||
|
||
export class QueueProd implements IQueue { | ||
private pubSubClient: PubSub; | ||
constructor() { | ||
this.pubSubClient = new PubSub(); | ||
private pubSubClient: PubSub; | ||
|
||
constructor() { | ||
const computeClient = new Compute(); | ||
const auth = new GoogleAuth({ authClient: computeClient }) as unknown as GoogleAuth<JSONClient>; | ||
this.pubSubClient = new PubSub({ auth }); | ||
} | ||
|
||
async publishMessage(message: (Uint8Array | string), options?: { topicName: string }): Promise<string> { | ||
const topicName = options?.topicName || process.env.MNDY_TOPIC_NAME; | ||
if (!topicName) { | ||
throw new BadRequestError('topicName is missing or empty.'); | ||
} | ||
|
||
async publishMessage(message: (Uint8Array|string), options?: { topicName: string }): Promise<string> { | ||
const topicName = options?.topicName || process.env.MNDY_TOPIC_NAME; | ||
if (!topicName) { | ||
throw new BadRequestError('topicName is missing or empty.'); | ||
} | ||
|
||
try { | ||
const data = (typeof message === 'string') ? Buffer.from(message) : message; | ||
const messageId = await this.pubSubClient | ||
.topic(topicName) | ||
.publishMessage({data, attributes: {'Content-Type': 'application/json'}}); | ||
return messageId; | ||
} catch (err) { | ||
logger.error(JSON.stringify(err)); | ||
throw new InternalServerError('An error occurred while sending message toe queue.') | ||
} | ||
|
||
try { | ||
const data = (typeof message === 'string') ? Buffer.from(message) : message; | ||
const messageId = await this.pubSubClient | ||
.topic(topicName) | ||
.publishMessage({ data, attributes: { 'Content-Type': 'application/json' } }); | ||
return messageId; | ||
} catch (err) { | ||
logger.error(JSON.stringify(err)); | ||
throw new InternalServerError('An error occurred while sending message toe queue.'); | ||
} | ||
|
||
validateMessageSecret(secret: string) : boolean { | ||
const envMessageSecret = process.env.MNDY_TOPIC_MESSAGES_SECRET; | ||
if (!envMessageSecret) { | ||
throw new BadRequestError('En environment variable name "MNDY_TOPIC_MESSAGES_SECRET" is required.'); | ||
} | ||
if (!secret) { | ||
throw new BadRequestError('secret is required.'); | ||
} | ||
const topicMessageSecret = process.env.MNDY_TOPIC_MESSAGES_SECRET; | ||
return secret === topicMessageSecret; | ||
} | ||
|
||
validateMessageSecret(secret: string): boolean { | ||
const envMessageSecret = process.env.MNDY_TOPIC_MESSAGES_SECRET; | ||
if (!envMessageSecret) { | ||
throw new BadRequestError('En environment variable name "MNDY_TOPIC_MESSAGES_SECRET" is required.'); | ||
} | ||
if (!secret) { | ||
throw new BadRequestError('secret is required.'); | ||
} | ||
const topicMessageSecret = process.env.MNDY_TOPIC_MESSAGES_SECRET; | ||
return secret === topicMessageSecret; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.