private static bool validatePath() { if (string.IsNullOrEmpty(path) || !Path.IsPathRooted(path)) { var pathToApplication = System.AppDomain.CurrentDomain.BaseDirectory; var useDefaultPathDisplay = $"No path provided. Use local path: " + $"{pathToApplication} instead?"; var useDefaultPath = UtilsConsole.Confirm(useDefaultPathDisplay); if (useDefaultPath) { path = pathToApplication; return(true); } else { Console.WriteLine("Please enter path that contains files to be renamed:"); path = Console.ReadLine(); if (string.IsNullOrEmpty(path) || !Path.IsPathRooted(path)) { var errorMessage = $"{path} is not a valid path, try again?"; var tryPathAgain = UtilsConsole.Confirm(errorMessage); if (!tryPathAgain) { return(false); } path = ""; validatePath(); } } } return(true); }
public void UnityUtilityTestSimplePasses() { MainLoop.Init(); UtilsConsole.Init(null); Log.Debug("debug test"); Log.Error("error test"); Timer.Execute(() => Log.Debug("timer test")).WithDelay(2f); }
private static async Task <bool> CheckTerminateInstance(EC2 ec2, ApplicationArguments applicationArguments) { bool terminateInstance = false; var results = await ec2.DescribeInstances(); int instanceNumber = 0; List <string> allowedKeys = new List <string>(); string InstanceList = ""; foreach (var result in results) { InstanceList = $"[{instanceNumber}] {result.InstanceName}-({result.InstanceState})-({result.Owner})-({result.InstanceId})"; if (applicationArguments.TerminateInstanceID == result.InstanceId) { InstanceList = $"[{instanceNumber}] * {result.InstanceName}-({result.InstanceState})-({result.Owner})-({result.InstanceId})"; } Console.WriteLine($"{InstanceList}"); allowedKeys.Add(instanceNumber.ToString()); instanceNumber++; } Console.WriteLine(); string terminate = Utils.UtilsConsole.ChooseOption("Which instance would you like to terminate? or press [N] for None ", allowedKeys); if (terminate != "N") { var ec2Terminate = results[Convert.ToInt32(terminate)]; Console.WriteLine(); if (UtilsConsole.Confirm($"Do you really want to terminate {ec2Terminate.InstanceName}?")) { ec2.TerminateInstance(ec2Terminate); terminateInstance = true; } } return(terminateInstance); }
static async Task Main(string[] args) { var arguments = new FluentCommandLineParser <ApplicationArguments>(); arguments.Setup(arg => arg.AccessKey) .As('k', "accesskey") .WithDescription("AWS Access Key"); arguments.Setup(arg => arg.SecretKey) .As('s', "secretkey") .WithDescription("AWS Secret Key"); arguments.Setup(arg => arg.AccountId) .As('a', "accountId") .WithDescription("AWS Account ID"); arguments.Setup(arg => arg.AllowedSubnet) .As('u', "allowedsubnet") .WithDescription("Only allow access from this subnet"); arguments.Setup(arg => arg.AWSRegion) .As('r', "awsregion") .WithDescription("AWS Region to delete and create new instance"); arguments.Setup(arg => arg.TerminateInstanceID) .As('i', "instanceid") .WithDescription("Existing InstanceID to terminate"); arguments.Setup(arg => arg.TerminateInstanceName) .As('n', "instancename") .WithDescription("Existing Instance Name to terminate"); arguments.Setup(arg => arg.KeyName) .As('p', "keyname") .WithDescription("PEM Key pair to use for the new instance"); arguments.Setup(arg => arg.WindowsInstanceType) .As('g', "windowsinstancetype") .SetDefault("t2.medium") .WithDescription("CPU Capacity, Memory and storage type for the Windows Forensic Instance"); arguments.Setup(arg => arg.WindowsEbsVolumeSize) .As('h', "windowsebsvolumesize") .SetDefault("30") .WithDescription("Size in Gb of the disk volume associated with the Windows Forensic Instance"); arguments.Setup(arg => arg.SiftInstanceType) .As('j', "siftinstancetype") .SetDefault("t2.micro") .WithDescription("CPU Capacity, Memory and storage type for the SIFT Forensic Instance"); arguments.Setup(arg => arg.SiftEbsVolumeSize) .As('l', "siftebsvolumesize") .SetDefault("8") .WithDescription("Size in Gb of the disk volume associated with the SIFT Forensic Instance"); arguments.SetupHelp("?", "help") .Callback(text => Console.WriteLine(text)); var argumentResult = arguments.Parse(args); if (argumentResult.HasErrors || argumentResult.EmptyArgs) { Console.WriteLine("Usage:"); arguments.HelpOption.ShowHelp(arguments.Options); } if (argumentResult.HasErrors == false) { var applicationArguments = arguments.Object; AppConfiguration(applicationArguments); EC2 ec2 = new EC2(arguments.Object.AccessKey, arguments.Object.SecretKey, arguments.Object.AccountId, arguments.Object.AWSRegion); bool instanceTerminated = false; if (UtilsConsole.Confirm("Would you like to terminate an existing Instance?")) { instanceTerminated = await CheckTerminateInstance(ec2, applicationArguments); } ReturnAMImage returnAmImage = await ChooseAmImage(ec2, applicationArguments); string securityGroupId = await ChooseSecurityGroup(ec2); string vpcId = await ChooseVpc(ec2); string owner = UtilsConsole.AskQuestion("Who is the owner of this Instance", Environment.UserName); string usageDescription = UtilsConsole.AskQuestion("What will be the usage for this Instance"); string instanceName = Utils.UtilsConsole.AskQuestion("What name will this instance have", EstimateInstanceName(owner, returnAmImage.Platform)); // TODO Public IP, owner, usage and name Tags // check how many Elastic IP addresses are available. If there are 5 or more then check if an instance was terminated // If an instance was terminated then ask if your want to use that one // Otherwise check which instances are stopped then suggest one which is of the same platform as the instance type you would like to take the // elastic IP from //List<AwsForensicRefresh.Models.Address> addresses = new Addresses(); Addresses addresses = new Addresses(ec2); int a = addresses.Count; ec2.RunInstance(returnAmImage.ImageId, vpcId, securityGroupId, owner, usageDescription, returnAmImage.InstanceType, Convert.ToInt32(returnAmImage.EbsVolumeSize), applicationArguments.KeyName, instanceName); } Console.ReadLine(); }