Exemplo n.º 1
0
        public async Task <OnCallOperatorDetails> GetDetailsForCurrentOnCallOperator(EmptyRequest request, ILambdaContext context)
        {
            string subdomain = Environment.GetEnvironmentVariable("PAGER_DUTY_DOMAIN");
            string apiToken  = Environment.GetEnvironmentVariable("PAGER_DUTY_API_KEY");

            string scheduleId = Environment.GetEnvironmentVariable("PAGER_DUTY_SCHEDULE_ID");

            LambdaLogger.Log($"REQUEST: {request}");

            LambdaLogger.Log($"PARAM: subdomain={subdomain}");
            LambdaLogger.Log($"PARAM: apiToken={apiToken}");
            LambdaLogger.Log($"PARAM: scheduleId={scheduleId}");

            PagerDutyClient service = new PagerDutyClient(subdomain, apiToken);

            User user = await GetCurrentOnCallOperator(subdomain, apiToken, scheduleId);

            if (user != null)
            {
                UserPhone phone = await GetUserContactMethods(subdomain, apiToken, user.Id);

                OnCallOperatorDetails result = new OnCallOperatorDetails()
                {
                    Name        = user.Name,
                    TimeZone    = WebHelpers.MapToOlsonTimeZone(user.TimeZone),
                    PhoneNumber = $"+{phone.CountryCode}{phone.PhoneNumber}"
                };

                LambdaLogger.Log($"RESPONSE: {result}");

                return(result);
            }
            else
            {
                return(null);
            }
        }