/// <summary> /// Public constructor /// </summary> /// <param name="config">Okta Config instance</param> /// <param name="appLabel">Application label</param> /// <param name="attrs">Attributes to be reported for appUser profile</param> /// <param name="input">Input file with list of users</param> /// <param name="all">Output all users</param> /// <param name="ofs">Output field separator</param> public AppUserReport(OktaConfig config, string appLabel, string attrs, FileInfo input, bool all = true, string ofs = ",") : base(config) { _attrs = string.IsNullOrEmpty(attrs) ? Enumerable.Empty <string>() : attrs.Split(",").ToHashSet(); _ofs = ofs; _appLabel = appLabel; _all = all; if (all) { if (input != null) { Console.WriteLine("All records selected, ignoring --input"); } } else { _input = input; if (input == null) { Console.WriteLine("Filtered user list selected but no --input provided, reading user list from standard input... (provide --all true otherwise)"); } } }
/// <inheritdoc /> /// <summary> /// Public constructor /// </summary> /// <param name="config">Okta Config instance</param> /// <param name="fileInfo">FileInfo to use as a source of records</param> /// <param name="attrName">Attribute name to be set</param> /// <param name="attrValue">Attribute value to be set for all users</param> /// <param name="writeEmpty">Skip empty values while updating user profile</param> public AttributeSetter( OktaConfig config, FileInfo fileInfo, string attrName, string attrValue, bool writeEmpty = false) : base(config) { _fileInfo = fileInfo; _writeEmpty = writeEmpty; if (string.IsNullOrWhiteSpace(attrName)) { throw new InvalidOperationException("Required parameter --attrName is missing"); } _attrNames = attrName.Contains(',') ? attrName.Split(',') : new[] { attrName }; if (attrValue == null) { return; } _attrValues = Regex.Split(attrValue); if (_attrValues.Count() < _attrNames.Count()) { throw new Exception("List of values provided less than the number of fields to populate"); } }
/// <summary> /// Public constructor /// </summary> /// <param name="config">Okta Config instance</param> /// <param name="appLabel">Application label</param> /// <param name="input">Input file with list of users</param> /// <param name="action">Add/remove user to the application</param> /// <param name="ofs">Output field separator</param> public AppUserLifecycle(OktaConfig config, string appLabel, FileInfo input, string action, string attrs, string ofs = ",") : base(config) { _ofs = ofs; _appLabel = appLabel; _action = action; _input = input; _attrs = attrs.Split(","); }
/// <summary> /// Constructor /// </summary> /// <param name="oktaConfig">Config params to use while instantiating Okta client</param> protected OktaAction(OktaConfig oktaConfig) { _oktaConfig = oktaConfig; if (string.IsNullOrEmpty(_oktaConfig.ApiKey)) { _oktaConfig.ApiKey = PromptAndReadToken(); } }
/// <inheritdoc /> /// <summary> /// Public constructor /// </summary> /// <param name="config">Okta Config instance</param> /// <param name="fileInfo">FileInfo to take user ids from</param> /// <param name="attrName">Specifies a profile attribute which to identify user with against given list of values</param> /// <param name="attrs">User profile attributes to output</param> /// <param name="ofs">OFS string</param> public UserReport(OktaConfig config, FileInfo fileInfo, string attrName, string attrs, string ofs = ",") : base(config) { _fileInfo = fileInfo; _attrName = attrName; _attrs = string.IsNullOrEmpty(attrs) ? Enumerable.Empty <string>() : attrs.Trim().Split(',').Select(attr => attr.Trim()).ToHashSet(); _ofs = ofs; }
/// <summary> /// Public constructor /// </summary> /// <param name="config">Okta Config instance</param> /// <param name="search">User search expression in Okta API language</param> /// <param name="filter">User filter</param> /// <param name="attrs">List of attributes to output for each user (CSV)</param> /// <param name="ofs">Output field separator</param> public UserSearchReport(OktaConfig config, string search, string filter, string attrs, string ofs = " ") : base(config) { _search = search; _ofs = ofs; _attrs = string.IsNullOrEmpty(attrs) ? Enumerable.Empty <string>() : attrs.Split(",").ToHashSet(); _filter = new UserFilter(filter).F; }
/// <summary> /// Public constructor /// </summary> /// <param name="config">Okta Config instance</param> /// <param name="grpName">Group name</param> /// <param name="userFilter">not implemented yet</param> /// <param name="userAttrList">List of attributes to output for each user</param> /// <param name="input">File with the list of groups</param> /// <param name="ofs">Output field separator</param> public GroupMembersReportWithUserFilter(OktaConfig config, string grpName, string userFilter, string userAttrList, FileInfo input = null, string ofs = ",") : base(config) { _grpName = grpName; _input = input; _ofs = ofs; _attrs = string.IsNullOrEmpty(userAttrList) ? Enumerable.Empty <string>() : userAttrList.Trim().Split(","); _filter = new UserFilter(userFilter).F; }
/// <summary> /// Public constructor /// </summary> /// <param name="config">Okta Configuration object</param> /// <param name="fileInfo">File with UUID "comma separated list of groups"</param> /// <param name="action">String [add | remove] to indicate the operation for the given list of groups</param> /// <param name="grpName">String representing group(s) to be added or removed to every user</param> /// <param name="groupIdUsed">true if group UUID used instead of name</param> public ManageMembership(OktaConfig config, FileInfo fileInfo, string action, string grpName = null, bool groupIdUsed = false) : base(config) { _fileInfo = fileInfo; if (!new[] { "add", "remove", "display" }.Contains(action)) { throw new InvalidOperationException("action can be either 'add', 'remove' or 'display'"); } _action = action; _grpName = grpName; _grpIdUsed = groupIdUsed; }
static void Main(string[] args) { var oktaConfig = OktaConfig.BuildConfig(); var root = new RootCommand(); var optionOfs = new Option("-OFS", "output field separator", new Argument <string>()); root.AddOption(optionOfs); var optionAttrs = new Option("--attrs", "attributes to output", new Argument <string>()); var optionInputFile = new Option("--input", "input file name", new Argument <FileInfo>()); var optionGroupName = new Option("--grpName", "group name to run report for", new Argument <string>()); var optionSearch = new Option("--search", "search expression", new Argument <string>()); var optionFilter = new Option("--filter", "filter expression", new Argument <string>()); var optionAll = new Option("--all", "all records", new Argument <bool>()); var aCommand = new Command("findCreator", handler: CommandHandler.Create <FileInfo, string, string>( async(input, attrs, ofs) => { await new CreatorReport(oktaConfig, input, attrs, ofs).Run(); })); aCommand.AddOption(optionInputFile); aCommand.AddOption(optionAttrs); aCommand.AddOption(optionOfs); root.AddCommand(aCommand); var bCommand = new Command("setAttribute", handler: CommandHandler.Create <string, FileInfo, string, bool>( async(attrName, input, attrValue, writeEmpty) => { await new AttributeSetter(oktaConfig, input, attrName, attrValue, writeEmpty).Run(); })); bCommand.AddOption(new Option("--attrName", "profile attribute name to populate", new Argument <string>())); bCommand.AddOption(new Option("--attrValue", "profile attribute value to be set", new Argument <string>())); bCommand.AddOption(optionInputFile); bCommand.AddOption(optionOfs); bCommand.AddOption(new Option("--writeEmpty", "skip empty values", new Argument <bool>())); root.AddCommand(bCommand); var cCommand = new Command("emptyAttribute", handler: CommandHandler.Create <string, string>( async(attrName, since) => { await new EmptyAttributeReport(oktaConfig, attrName, since).Run(); })); cCommand.AddOption(new Option("--attrName", "profile attribute name to populate", new Argument <string>())); cCommand.AddOption(new Option("--since", "select users created since specified date (YYYY-MM-DD format)", new Argument <string>())); cCommand.AddOption(optionOfs); root.AddCommand(cCommand); var groupMembershipWithFilter = new Command("groupMembership", handler: CommandHandler.Create <string, string, string, FileInfo, string>( (grpName, filter, attrs, input, ofs) => new GroupMembersReportWithUserFilter(oktaConfig, grpName, filter, attrs, input, ofs) .Run())); groupMembershipWithFilter.AddOption(optionGroupName); groupMembershipWithFilter.AddOption(optionFilter); groupMembershipWithFilter.AddOption(optionAttrs); groupMembershipWithFilter.AddOption(optionOfs); groupMembershipWithFilter.AddOption(optionInputFile); root.AddCommand(groupMembershipWithFilter); var eCommand = new Command("listApps", handler: CommandHandler.Create <string>(async ofs => { await new ApplicationList(oktaConfig, ofs).Run(); })); eCommand.AddOption(optionOfs); root.AddCommand(eCommand); var appAssignmentCmd = new Command("appUser", handler: CommandHandler.Create <string, string, FileInfo, bool, string>(async(appLabel, attrs, input, all, ofs) => { await new AppUserReport(oktaConfig, appLabel, attrs, input, all, ofs).Run(); })); appAssignmentCmd.AddOption(optionOfs); appAssignmentCmd.AddOption(new Option("--appLabel", "application label", new Argument <string>())); appAssignmentCmd.AddOption(optionAttrs); appAssignmentCmd.AddOption(optionInputFile); appAssignmentCmd.AddOption(optionAll); root.AddCommand(appAssignmentCmd); var listGroups = new Command("listGroups", handler: CommandHandler.Create <string>((ofs) => { new GroupList(oktaConfig, ofs).Run(); })); listGroups.AddOption(optionOfs); root.AddCommand(listGroups); var fCommand = new Command("userReport", handler: CommandHandler.Create <FileInfo, string, string>(async(input, attrName, attrs) => { await new UserReport(oktaConfig, input, attrName, attrs).Run(); })); fCommand.AddOption(optionInputFile); fCommand.AddOption(optionAttrs); fCommand.AddOption(new Option("--attrName", "attribute name to check", new Argument <string>())); fCommand.AddOption(optionOfs); root.AddCommand(fCommand); var gCommand = new Command("userSearchReport", handler: CommandHandler.Create <string, string, string, string>(async(search, filter, attrs, ofs) => { await new UserSearchReport(oktaConfig, search, filter, attrs, ofs).Run(); })); gCommand.AddOption(optionSearch); gCommand.AddOption(optionFilter); gCommand.AddOption(optionAttrs); gCommand.AddOption(root.FirstOrDefault(sym => sym.Name == "OFS") as Option); root.AddCommand(gCommand); var userLifeCycle = new Command("userLifecycle", handler: CommandHandler.Create <FileInfo, string>(async(input, action) => await new UserLifecycle(oktaConfig, input, action).Run())); userLifeCycle.AddOption(optionOfs); userLifeCycle.AddOption(optionInputFile); userLifeCycle.AddOption(new Option("--action", "activate, deactivate, suspend, unsuspend or delete", new Argument <string>())); root.AddCommand(userLifeCycle); var manageGroups = new Command("manageMembership", handler: CommandHandler.Create <FileInfo, string, string, bool>(async(input, action, grpName, idUsed) => { await new ManageMembership(oktaConfig, input, action, grpName, idUsed).Run(); })); manageGroups.AddOption(optionInputFile); manageGroups.AddOption(optionOfs); manageGroups.AddOption(optionGroupName); manageGroups.AddOption(new Option("--action", "[add | remove | display]", new Argument <string>())); manageGroups.AddOption(new Option("--idUsed", "true if group id used instead of name", new Argument <bool>())); root.AddCommand(manageGroups); var groupRename = new Command("groupRename", handler: CommandHandler.Create <FileInfo, bool>(async(input, idUsed) => { await new GroupRename(oktaConfig, input, idUsed).Run(); })); groupRename.AddOption(optionInputFile); groupRename.AddOption(new Option("--idUsed", "true if group id used instead of name", new Argument <bool>())); groupRename.AddOption(optionOfs); root.AddCommand(groupRename); var injectedArgs = args.All(s => s != "-OFS") ? args.Concat(new[] { "-OFS", "," }).ToArray() : args; root.InvokeAsync(injectedArgs).Wait(); }
/// <summary> /// Public constructor /// </summary> /// <param name="config">Okta Configuration object</param> /// <param name="fileInfo">File with input data</param> /// <param name="action">Action to be taken: [activate, deactivate, suspend, unsuspend, delete]</param> public UserLifecycle(OktaConfig config, FileInfo fileInfo, string action) : base(config) { _fileInfo = fileInfo; _action = action; }
/// <summary> /// Public constructor /// </summary> /// <param name="config">Okta config instance</param> /// <param name="ofs">Output field separator</param> public ApplicationList(OktaConfig config, string ofs = " ") : base(config) { _ofs = ofs; }
/// <summary> /// Public constructor /// </summary> /// <param name="config">OktaConfig instance</param> /// <param name="ofs">Output field separator</param> public GroupList(OktaConfig config, string ofs = " ") : base(config) { _ofs = ofs; }
/// <summary> /// Public constructor /// </summary> /// <param name="config">OktaConfig instance</param> /// <param name="input">File to be used as input</param> /// <param name="useIds">Indicate that groups will be searched by their GUIDs</param> public GroupRename(OktaConfig config, FileInfo input, bool useIds = true) : base(config) { _input = input; _useIds = useIds; }
/// <inheritdoc /> /// <summary> /// Public constructor /// </summary> /// <param name="config">Okta Configuration object</param> /// <param name="attrName">Attribute name to check against nullability</param> /// <param name="since">Optional string representing a date of user creation since which to start inspection</param> public EmptyAttributeReport(OktaConfig config, string attrName, string since = null) : base(config) { _attrName = attrName; _since = since == null?DateTime.Parse("1990-01-01") : DateTime.Parse(since); }