示例#1
0
        private static ISafeguardA2AContext CreateA2AContext(ToolOptions opts)
        {
            ISafeguardA2AContext context;

            if (!string.IsNullOrEmpty(opts.CertificateFile))
            {
                var password = HandlePassword(opts.ReadPassword);
                if (opts.CertificateAsData)
                {
                    var bytes = File.ReadAllBytes(opts.CertificateFile);
                    context = Safeguard.A2A.GetContext(opts.Appliance, bytes, password, opts.ApiVersion, opts.Insecure);
                }
                else
                {
                    context = Safeguard.A2A.GetContext(opts.Appliance, opts.CertificateFile, password, opts.ApiVersion,
                                                       opts.Insecure);
                }
            }
            else if (!string.IsNullOrEmpty(opts.Thumbprint))
            {
                context = Safeguard.A2A.GetContext(opts.Appliance, opts.Thumbprint, opts.ApiVersion, opts.Insecure);
            }
            else
            {
                throw new Exception("Must specify CertificateFile or Thumbprint");
            }
            return(context);
        }
示例#2
0
        private static void Execute(ToolOptions opts)
        {
            try
            {
                var config = new LoggerConfiguration();
                config.WriteTo.ColoredConsole(outputTemplate: "{Message:lj}{NewLine}{Exception}");

                if (opts.Verbose)
                {
                    config.MinimumLevel.Debug();
                }
                else
                {
                    config.MinimumLevel.Information();
                }

                Log.Logger = config.CreateLogger();

                using (var context = CreateA2AContext(opts))
                {
                    var responseBody = context.RetrievePassword(opts.ApiKey.ToSecureString());
                    Log.Information(responseBody.ToInsecureString());
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex, "Fatal exception occurred");
                Environment.Exit(1);
            }
        }
示例#3
0
        private static void Execute(ToolOptions opts)
        {
            try
            {
                var config = new LoggerConfiguration();
                config.WriteTo.Console(outputTemplate: "{Message:lj}{NewLine}{Exception}", theme: AnsiConsoleTheme.Code);

                if (opts.Verbose)
                {
                    config.MinimumLevel.Debug();
                }
                else
                {
                    config.MinimumLevel.Information();
                }

                Log.Logger = config.CreateLogger();

                using (var context = CreateA2AContext(opts))
                {
                    if (opts.ApiKey.Equals("?"))
                    {
                        var responseBody = context.GetRetrievableAccounts();
                        foreach (var obj in responseBody)
                        {
                            Log.Information(obj.ToString());
                        }
                    }
                    else
                    {
                        if (opts.RetrievableAccounts)
                        {
                            var accounts = context.GetRetrievableAccounts();
                            Log.Information(ObjectDumper.Dump(accounts));
                        }
                        if (opts.PrivateKey)
                        {
                            using (var responseBody = context.RetrievePrivateKey(opts.ApiKey.ToSecureString(), opts.KeyFormat))
                                Log.Information(responseBody.ToInsecureString());
                        }
                        else
                        {
                            using (var responseBody = context.RetrievePassword(opts.ApiKey.ToSecureString()))
                                Log.Information(responseBody.ToInsecureString());
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex, "Fatal exception occurred");
                Environment.Exit(1);
            }
        }