public static IProfile SetupProfile(IProfileManager profileManager, string profileName, bool persist = true) { start: Console.WriteLine(); Console.WriteLine("You don't have a profile set up yet. Please enter your API credentials."); Console.WriteLine("You can create a new API key at https://console.aws.amazon.com/iam/home?#/security_credentials"); string enteredKeyId = GetKeyId(); byte[] accessKey = GetAccessKey(); AwsRegion region = GetRegion(); Console.WriteLine(); Console.WriteLine("Please confirm the following information:"); Console.WriteLine("Key id: " + enteredKeyId); Console.WriteLine("Region: " + GetEnumMember(region) + " -- " + region.GetRegionName()); Console.WriteLine(); ConsoleKey key; do { Console.WriteLine("Is it correct? Y/N"); key = Console.ReadKey(true).Key; } while (key != ConsoleKey.Y && key != ConsoleKey.N); if (key == ConsoleKey.N) { goto start; } IProfile profile = profileManager.CreateProfile(profileName, enteredKeyId, accessKey, region, persist); if (persist) { if (!string.IsNullOrEmpty(profile.Location)) { Console.WriteLine("Successfully saved the profile to " + profile.Location); } else { Console.WriteLine("Successfully saved profile"); } } //Clear the access key from memory Array.Clear(accessKey, 0, accessKey.Length); return(profile); }
private static AwsRegion GetRegion() { Console.WriteLine(); Console.WriteLine("Choose the default region. You can choose it by index or region code"); string[] names = Enum.GetNames(typeof(AwsRegion)).Skip(1).ToArray(); Console.WriteLine("{0,-8}{1,-20}{2}", "Index", "Region Code", "Region Name"); foreach (string name in names) { AwsRegion region = (AwsRegion)Enum.Parse(typeof(AwsRegion), name); Console.WriteLine("{0,-8}{1,-20}{2}", (int)region, GetEnumMember(region), region.GetRegionName()); } string? enteredRegion; bool validRegion = true; AwsRegion parsedRegion; do { if (!validRegion) { Console.Error.WriteLine("Invalid region. Try again."); } enteredRegion = Console.ReadLine(); } while (!(validRegion = Enum.TryParse(enteredRegion, out parsedRegion) && Enum.IsDefined(typeof(AwsRegion), parsedRegion))); return(parsedRegion); }