Name

sn_em_connector.AWSSNSMessage

Description

No description available

Script

var AWSSNSMessage = Class.create();
AWSSNSMessage.prototype = {
  initialize: function() {
      this.subscribeURLProperty = "sn_em_connector.evt_mgmt.subscription.URL.Regex";
      this.subscribeURLDefaultValue = "(http:\\/\\/sns\\.|https:\\/\\/sns\\.)?[a-zA-Z0-9-]*\\.amazonaws\\.com\\/\\?Action\\=ConfirmSubscription\\&TopicArn\\=arn\\:aws.*\\:sns\\:?.*$";
      this.regValue = gs.getProperty(this.subscribeURLProperty, this.subscribeURLDefaultValue);
      this.subscribeURLRegex = new RegExp(this.regValue);

  },

  subscibeAndGetType: function(request, body) {
      var messageType = request.headers["x-amz-sns-message-type"];


      if (messageType == "SubscriptionConfirmation") {
          var jsonObject = JSON.parse(body);
          var subscribeURL = jsonObject["SubscribeURL"];
          if (!this.regValue || this.validateSubscribeURL(subscribeURL)) {
  			try { 
  				var r = new sn_ws.RESTMessageV2('AWS SNS API', 'Default GET');
  				//r.setStringParameterNoEscape('topic_arn', jsonObject["TopicArn"]);
  				
  				r.setEndpoint(subscribeURL);

  				//override authentication profile 
  				//authentication type ='basic'/ 'oauth2'
  				//r.setAuthenticationProfile(authentication type, profile name);

  				//set a MID server name if one wants to run the message on MID
  				//r.setMIDServer('MY_MID_SERVER');

  				//if the message is configured to communicate through ECC queue, either
  				//by setting a MID server or calling executeAsync, one needs to set skip_sensor
  				//to true. Otherwise, one may get an intermittent error that the response body is null
  				//r.setEccParameter('skip_sensor', true);

  				var response = r.execute();
  				var responseBody = response.getBody();
  				var httpStatus = response.getStatusCode();
  				gs.info("Subscription confirmation (" + subscribeURL + ") Return value: " + subscrResp);
  				return messageType;
  			} catch(ex) {
  				var message = ex.message;
  			}
          }
      }
  	return messageType;
  },

  validateSubscribeURL: function(url) {
      var match = this.subscribeURLRegex.test(url);
      if (!match)
          gs.error("SubscriberUL " + url + " for AWS SubscriptionConfirmation is not matching the regex " + this.subscribeURLRegex.subscribeURLRegex + ". The url is not confirmed");

      return match;

  },

  type: 'AWSSNSMessage'
};

Sys ID

3a1a9f895b031410ea1d1b800481c766

Offical Documentation

Official Docs: