Ejemplo n.º 1
0
        public async Task <IHttpActionResult> Register(Models.RegisterBindingModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var user = new ApplicationUser()
            {
                UserName = model.Email, Email = model.Email, Firstname = model.Firstname, Lastname = model.Lastname
            };

            IdentityResult result = await UserManager.CreateAsync(user, model.Password);

            if (!result.Succeeded)
            {
                return(GetErrorResult(result));
            }

            RegionEndpoint regionep  = Amazon.RegionEndpoint.GetBySystemName(System.Web.Configuration.WebConfigurationManager.AppSettings["region"]);
            string         awskey    = System.Web.Configuration.WebConfigurationManager.AppSettings["awskey"];
            string         awssecret = System.Web.Configuration.WebConfigurationManager.AppSettings["awssecret"];
            string         arn       = System.Web.Configuration.WebConfigurationManager.AppSettings["awssnstopic"];

            Amazon.SimpleNotificationService.AmazonSimpleNotificationServiceClient simp = new Amazon.SimpleNotificationService.AmazonSimpleNotificationServiceClient(awskey, awssecret, new Amazon.SimpleNotificationService.AmazonSimpleNotificationServiceConfig
            {
                RegionEndpoint = regionep
            });
            simp.Subscribe(arn, "email", model.Email);
            simp.PublishAsync(arn, "Please welcome to Tune World " + model.Firstname + " " + model.Lastname, "Tune World Registration");

            return(Ok());
        }
Ejemplo n.º 2
0
        public static string Send(string _message,
                                  string _phone)
        {
            /* get rid of anything in the phone number that is not numeric and format it to 11 digits */
            _phone = new String(_phone.Where(c => char.IsDigit(c)).ToArray());

            _phone = (_phone.Length == 10 ? string.Format("1{0}", _phone) : _phone);

            if (_phone.Length != 11)
            {
                return("Invalid phone number");
            }

            try
            {
                var _credentials = MyHttpGatewayApi.Utilities.AmazonWebServices.SecretsManager.amazon_web_services_credentials.credentials.Find(x => x.service == "SNS");

                var _aws = new Amazon.SimpleNotificationService.AmazonSimpleNotificationServiceClient(
                    _credentials.access_key_id,
                    _credentials.access_key,
                    Amazon.RegionEndpoint.USEast1
                    );

                _aws.PublishAsync(new Amazon.SimpleNotificationService.Model.PublishRequest()
                {
                    Message = _message, PhoneNumber = _phone
                }).Wait();

                return("Message sent");
            } catch (Exception _ex)
            {
                return(_ex.InnerException.ToString());
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Function that executes when all the check usage type lambdas are done executing.
        /// </summary>
        /// <param name="input"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        public void FunctionHandler(Stream inputStream, ILambdaContext context)
        {
            Amazon.XRay.Recorder.Handlers.AwsSdk.AWSSDKHandler.RegisterXRayForAllServices();

            TextReader textReader = new StreamReader(inputStream);

            var strInput = textReader.ReadToEnd();

            LambdaLogger.Log($"Received input {strInput}");

            var message = JsonConvert.DeserializeObject <SqsEvents>(strInput);

            // Could have multiple records in the message from SQS
            if (message.Records == null || message.Records.Length <= 0)
            {
                return;
            }

            string JobId = message.Records[0].body;

            if (GetUnprocessedItems(JobId) > 0)
            {
                return;
            }

            var tsTimeTaken = GetTimeTaken(JobId);

            var strSnsOutput = BuildSnsTopicString(tsTimeTaken);

            if (string.IsNullOrEmpty(strSnsOutput))
            {
                LambdaLogger.Log("No SNS data to publish, exiting.");
                return;
            }

            string SNSTopicArn = GetSNSTopicARN();

            if (SNSTopicArn == null)
            {
                LambdaLogger.Log("SNS topic ARN is missing.");
                return;
            }

            Amazon.SimpleNotificationService.AmazonSimpleNotificationServiceClient snsClient = new Amazon.SimpleNotificationService.AmazonSimpleNotificationServiceClient(Amazon.RegionEndpoint.APSoutheast2);

            var snsClientResult = snsClient.PublishAsync(new PublishRequest
            {
                TopicArn = SNSTopicArn,
                Message  = strSnsOutput,
                Subject  = "AWS Billing Anomaly Tracker"
            }).GetAwaiter().GetResult();

            if (snsClientResult.HttpStatusCode == System.Net.HttpStatusCode.OK)
            {
                LambdaLogger.Log("Successfully published to SNS.");
            }
        }
Ejemplo n.º 4
0
 public static void SendSnsMessage(string snsTopicArn, string snsMessage)
 {
     try
     {
         var snsClient = new Amazon.SimpleNotificationService.AmazonSimpleNotificationServiceClient();
         snsClient.PublishAsync(snsTopicArn, snsMessage).Wait();
     }
     catch (Exception e)
     {
         Logger.LogLine("Unable to log to SNS!!");
         Logger.LogLine(e.Message);
     }
 }
Ejemplo n.º 5
0
        public async static Task SendGetNotification(object data)
        {
            if (string.IsNullOrEmpty(SnsTopicArn))
            {
                return;
            }

            Amazon.SimpleNotificationService.AmazonSimpleNotificationServiceClient client = new Amazon.SimpleNotificationService.AmazonSimpleNotificationServiceClient();
            string strMessage = "Message";

            if (data != null)
            {
                strMessage = Newtonsoft.Json.JsonConvert.SerializeObject(data);
            }
            await client.PublishAsync(new PublishRequest { TopicArn = SnsTopicArn, Message = strMessage });
        }
Ejemplo n.º 6
0
        public static ServiceResponse Send(Message message)
        {
            ServiceResponse response = new ServiceResponse();

            if (message.IsValid())
            {
                var snsService = new Amazon.SimpleNotificationService.AmazonSimpleNotificationServiceClient(AWSCredentials.AccessKey, AWSCredentials.SecretKey, RegionEndpoint.USEast1);

                var attributes = new Dictionary <string, MessageAttributeValue>();
                attributes.Add("AWS.SNS.SMS.SenderID", new MessageAttributeValue()
                {
                    StringValue = message.SenderId, DataType = "String"
                });
                attributes.Add("AWS.SNS.SMS.SMSType", new MessageAttributeValue()
                {
                    StringValue = message.Type.GetDescription(), DataType = "String"
                });

                var request = new Amazon.SimpleNotificationService.Model.PublishRequest();
                request.PhoneNumber       = $"+{message.PhoneNumber}";
                request.Message           = message.TextMessage;
                request.MessageAttributes = attributes;

                var result = snsService.PublishAsync(request).Result;
                if (result.HttpStatusCode == System.Net.HttpStatusCode.OK)
                {
                    response.IsValid = true;
                }
                else
                {
                    response.Errors.Add("SMS failed!");
                    response.IsValid = false;
                }
            }
            else
            {
                response.Errors  = message.Errors;
                response.IsValid = false;
            }
            return(response);
        }
Ejemplo n.º 7
0
        private void PushLogToSNS(string snsSubject, string log)
        {
            if (string.IsNullOrEmpty(Settings.ResultsTopic))
            {
                return;
            }

            try
            {
                if (log.Length > snsMaxMessageSize)
                {
                    WriteInfo("Log too long for SNS, truncating...");
                    var tooLongPrefix = string.Format(logTooLongMessage, snsMaxMessageSizeKb);
                    var maxCharacters = snsMaxMessageSize - (tooLongPrefix.Length + truncationSuffix.Length);
                    log =
                        tooLongPrefix +
                        log.Substring(0, maxCharacters) +
                        truncationSuffix;
                }

                WriteInfo("Pushing log to SNS...");
                using (var sns = new Amazon.SimpleNotificationService.AmazonSimpleNotificationServiceClient(Credentials, RegionEndpoint))
                {
                    sns.PublishAsync(new PublishRequest
                    {
                        TopicArn = Settings.ResultsTopic,
                        Subject  = snsSubject,
                        Message  = log
                    }).Wait();
                }
            }
            catch (Exception e)
            {
                WriteError("Error pushing logs to SNS: {0}", e);
            }
        }
Ejemplo n.º 8
0
        private void PushLogToSNS(string snsSubject, string log)
        {
            if (string.IsNullOrEmpty(Settings.ResultsTopic))
                return;

            try
            {
                if (log.Length > snsMaxMessageSize)
                {
                    WriteInfo("Log too long for SNS, truncating...");
                    var tooLongPrefix = string.Format(logTooLongMessage, snsMaxMessageSizeKb);
                    var maxCharacters = snsMaxMessageSize - (tooLongPrefix.Length + truncationSuffix.Length);
                    log =
                        tooLongPrefix +
                        log.Substring(0, maxCharacters) +
                        truncationSuffix;
                }

                WriteInfo("Pushing log to SNS...");
                using (var sns = new Amazon.SimpleNotificationService.AmazonSimpleNotificationServiceClient(Credentials, RegionEndpoint))
                {
                    sns.PublishAsync(new PublishRequest
                    {
                        TopicArn = Settings.ResultsTopic,
                        Subject = snsSubject,
                        Message = log
                    }).Wait();
                }
            }
            catch(Exception e)
            {
                WriteError("Error pushing logs to SNS: {0}", e);
            }
        }
        private async void NotifyAsync(string message)
        {
            var client = new Amazon.SimpleNotificationService.AmazonSimpleNotificationServiceClient(RegionEndpoint.EUWest1);

            await client.PublishAsync("arn:aws:sns:eu-west-1:160534783289:adex_parsed", message);
        }