public Task <ListUserTagsResponse> ListUserTagsAsync(ListUserTagsRequest request, CancellationToken cancellationToken = new CancellationToken())
 {
     throw new System.NotImplementedException();
 }
Example #2
0
        private async Task NotifyUsers(Notifications notifications)
        {
            // We'll re-use this to query for each user's tags
            var userTagsRequ = new ListUserTagsRequest();

            var notifyCount = 0;

            foreach (var userNotifications in notifications)
            {
                // Get tags for IAM user and extract the email and slack if they have them
                var    username  = userNotifications.Key;
                string userEmail = null;
                string userSlack = null;

                // Root account is included in the report but we can't query
                // for tags so it will have to fallback to "default" behavior
                // as if there were no notification-related tags for the account
                if (username != Function.RootAccountName)
                {
                    userTagsRequ.UserName = userNotifications.Key;
                    var userTagsResp = await _iamClient.ListUserTagsAsync(userTagsRequ);

                    userEmail = userTagsResp.Tags.FirstOrDefault(
                        x => x.Key == Function.EmailUserTag)?.Value;
                    userSlack = userTagsResp.Tags.FirstOrDefault(
                        x => x.Key == Function.SlackUserTag)?.Value;
                }

                else
                {
                    continue;
                }

                // IAM User Tags don't allow '#' character
                userEmail = userEmail?.Replace('+', '#');
                userSlack = userSlack?.Replace('+', '#');

                LogLine($"Sending Notification to [{username}]:");
                LogLine($"  * at email = [{userEmail}]:");
                LogLine($"  * at slack = [{userSlack}]:");

                if (IsEmailEnabled)
                {
                    await NotifyUserByEmail(username, userEmail, userNotifications.Value);
                }
                if (IsSlackEnabled)
                {
                    await NotifyUserBySlack(username, userSlack, userNotifications.Value);
                }

                ++notifyCount;

                if (_settings.NotificationCountLimit > 0 &&
                    notifyCount >= _settings.NotificationCountLimit)
                {
                    LogLine("REACHED LIMIT OF NUMBER NOTIFICATIONS TO BE SENT -- STOPPING");
                    break;
                }
            }

            LogLine($"Sent [{notifyCount}] notification(s) of a total of [{notifications.Count}]");
        }