Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async function main() {
const capabilityService = new ClientCapabilityService(
logger,
Config.get('clientCapabilityFetch')
);
const webhookService = new ClientWebhookService(
logger,
Config.get('clientCapabilityFetch.refreshInterval'),
db
);
const pubsub = new PubSub();
// Extract region for SQS object
const serviceNotificationQueueUrl = Config.get('serviceNotificationQueueUrl');
const region = extractRegionFromUrl(serviceNotificationQueueUrl);
if (!region) {
logger.error('invalidServiceUrl', {
message: 'Cant find region in service url',
serviceNotificationQueueUrl
});
process.exit(8);
}
const metrics = new StatsD(Config.get('metrics'));
const processor = new ServiceNotificationProcessor(
logger,
db,
metrics,
async function getTopicPolicy(topicName) {
// [START pubsub_get_topic_policy]
// Imports the Google Cloud client library
const {PubSub} = require('@google-cloud/pubsub');
// Creates a client
const pubsub = new PubSub();
/**
* TODO(developer): Uncomment the following line to run the sample.
*/
// const topicName = 'my-topic';
// Retrieves the IAM policy for the topic
const [policy] = await pubsub.topic(topicName).iam.getPolicy();
console.log(`Policy for topic: %j.`, policy.bindings);
// [END pubsub_get_topic_policy]
}
async function publishBatchedMessages(
topicName,
data,
maxMessages,
maxWaitTime
) {
// [START pubsub_publisher_batch_settings]
// Imports the Google Cloud client library
const {PubSub} = require('@google-cloud/pubsub');
// Creates a client
const pubsub = new PubSub();
/**
* TODO(developer): Uncomment the following lines to run the sample.
*/
// const topicName = 'my-topic';
// const data = JSON.stringify({ foo: 'bar' });
// const maxMessages = 10;
// const maxWaitTime = 10000;
// Publishes the message as a string, e.g. "Hello, world!" or JSON.stringify(someObject)
const dataBuffer = Buffer.from(data);
const batchPublisher = pubsub.topic(topicName, {
batching: {
maxMessages: maxMessages,
maxMilliseconds: maxWaitTime,
callingProjectId,
tableProjectId,
datasetId,
tableId,
topicId,
subscriptionId,
quasiIds
) {
// [START dlp_k_anonymity]
// Import the Google Cloud client libraries
const DLP = require('@google-cloud/dlp');
const {PubSub} = require('@google-cloud/pubsub');
// Instantiates clients
const dlp = new DLP.DlpServiceClient();
const pubsub = new PubSub();
// The project ID to run the API call under
// const callingProjectId = process.env.GCLOUD_PROJECT;
// The project ID the table is stored under
// This may or (for public datasets) may not equal the calling project ID
// const tableProjectId = process.env.GCLOUD_PROJECT;
// The ID of the dataset to inspect, e.g. 'my_dataset'
// const datasetId = 'my_dataset';
// The ID of the table to inspect, e.g. 'my_table'
// const tableId = 'my_table';
// The name of the Pub/Sub topic to notify once the job completes
// TODO(developer): create a Pub/Sub topic to use for this
kind,
topicId,
subscriptionId,
minLikelihood,
maxFindings,
infoTypes,
customInfoTypes
) {
// [START dlp_inspect_datastore]
// Import the Google Cloud client libraries
const DLP = require('@google-cloud/dlp');
const {PubSub} = require('@google-cloud/pubsub');
// Instantiates clients
const dlp = new DLP.DlpServiceClient();
const pubsub = new PubSub();
// The project ID to run the API call under
// const callingProjectId = process.env.GCLOUD_PROJECT;
// The project ID the target Datastore is stored under
// This may or may not equal the calling project ID
// const dataProjectId = process.env.GCLOUD_PROJECT;
// (Optional) The ID namespace of the Datastore document to inspect.
// To ignore Datastore namespaces, set this to an empty string ('')
// const namespaceId = '';
// The kind of the Datastore entity to inspect.
// const kind = 'Person';
// The minimum likelihood required before returning a match
describe('pubsub_in Node', () => {
const pubsub = new PubSub();
beforeEach((done) => {
helper.startServer(done);
});
afterEach((done)=> {
helper.unload();
helper.stopServer(done);
});
it('receive pubsub message', (done) => {
const flow = [
{
"id": "n1",
"type": "google-cloud-pubsub in",
"subscription": "node-red-subscription",
constructor(private args: PubsubEmulatorArgs) {
const { host, port } = this.getInfo();
this.pubsub = new PubSub({
apiEndpoint: `${host}:${port}`,
projectId: this.args.projectId,
});
this.triggers = new Map();
this.subscriptions = new Map();
}
useFactory: async (config: GooglePubSubConfig): Promise => {
const pubSub = new PubSub({ projectId: config.projectId });
return pubSub;
},
inject: [GOOGLE_PUBSUB_CONFIG]
constructor(
config?,
topic2SubName: Topic2SubName = topicName => `${topicName}-subscription`,
commonMessageHandler: CommonMessageHandler = message => message,
pubSubClient = new PubSub(config)
) {
this.clientId2GoogleSubNameAndClientCallback = {};
this.googleSubName2GoogleSubAndClientIds = {};
this.currentClientId = 0;
this.pubSubClient = pubSubClient;
this.topic2SubName = topic2SubName;
this.commonMessageHandler = commonMessageHandler;
}
exports.controller = functions.https.onRequest((req, res) => __awaiter(void 0, void 0, void 0, function* () {
if (!pubsub) {
pubsub = new pubsub_1.PubSub();
}
yield pubsub
.topic(process.env.EXT_INSTANCE_ID)
.publish(Buffer.from(JSON.stringify({})));
res.status(200).send("Ok");
}));
/**