/// <inheritdoc /> /// <summary> /// Report's main entry /// </summary> public override async Task Run() { Console.WriteLine(UserExtensions.PrintUserAttributesHeader(_attrs, _ofs)); var lines = _fileInfo == null ? Program.ReadConsoleLines() : File.ReadLines(_fileInfo.FullName); var semaphore = new SemaphoreSlim(16); var tasks = lines.Select( async line => { await semaphore.WaitAsync(); var userName = line.Trim().Split(' ', ',').First(); try { var users = string.IsNullOrWhiteSpace(_attrName) ? new List <IUser> { userName.Contains('/') ? await OktaClient.Users.ListUsers(search: $"profile.login eq \"{userName}\"").First() : await OktaClient.Users.GetUserAsync(userName) } : await OktaClient.Users.ListUsers(search: $"profile.{_attrName} eq \"{userName}\"") .ToList(); if (users.Count == 0) { Console.WriteLine(userName + " !!!!! user not found"); return; } foreach (var user in users) { Console.WriteLine(await user.PrintAttributesAsync(_attrs, OktaClient, _ofs)); } } catch (OktaApiException e) { if (e.Message.StartsWith("Not found:")) { Console.WriteLine(userName + " !!!!! user not found"); } } catch (Exception e) { Console.WriteLine(userName + " !!!!! exception processing the user"); Console.WriteLine(e); } finally { semaphore.Release(); } }); await Task.WhenAll(tasks); }
/// <summary> /// Main method to execute report /// </summary> public override async Task Run() { var lines = _fileInfo == null ? Program.ReadConsoleLines() : File.ReadLines(_fileInfo.FullName); var semaphore = new SemaphoreSlim(8); Console.WriteLine("userid" + _ofs + UserExtensions.PrintUserAttributesHeader(_attrs, _ofs)); var tasks = lines .Select( async line => { await semaphore.WaitAsync(); var userId = ""; try { userId = line.Trim().Split(' ', ',').First(); Console.WriteLine( userId + _ofs + await OktaClient.Logs .GetLogs( filter: $"eventType eq \"user.lifecycle.create\" and target.id eq \"{userId}\"", since: DateTime.Now.Add(TimeSpan.FromDays(-180d)).ToString("yyyy-MM-dd")) .Select(async ev => { var user = await OktaClient.Users.GetUserAsync(ev.Actor.Id); return(await user.PrintAttributesAsync(_attrs, OktaClient, _ofs)); }) .FirstOrDefault() .Unwrap()); } catch (Exception e) { Console.WriteLine($"{userId} - exception searching logs!!! {e.Message}"); } finally { semaphore.Release(); } }); await Task.WhenAll(tasks); }