Пример #1
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.BrokerAccessRequest(opts.ApiKey.ToSecureString(), GetBrokeredAccessRequestObject(opts));
                    Log.Information(responseBody);
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex, "Fatal exception occurred");
                Environment.Exit(1);
            }
        }
Пример #2
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);
        }
Пример #3
0
        private static BrokeredAccessRequest GetBrokeredAccessRequestObject(ToolOptions opts)
        {
            var accessRequest = new BrokeredAccessRequest
            {
                AccessType    = opts.AccessType,
                TicketNumber  = opts.TicketNumber,
                ReasonComment = opts.ReasonComment,
                RequestedFor  = opts.RequestedFor?.ToUniversalTime()
            };

            if (opts.ForUser.IsNumeric())
            {
                accessRequest.ForUserId = int.Parse(opts.ForUser);
            }
            else
            {
                accessRequest.ForUserName = opts.ForUser;
            }
            if (opts.Asset.IsNumeric())
            {
                accessRequest.AssetId = int.Parse(opts.Asset);
            }
            else
            {
                accessRequest.AssetName = opts.Asset;
            }
            if (!string.IsNullOrEmpty(opts.Account))
            {
                if (opts.Account.IsNumeric())
                {
                    accessRequest.AccountId = int.Parse(opts.Account);
                }
                else
                {
                    accessRequest.AccountName = opts.Account;
                }
            }
            if (!string.IsNullOrEmpty(opts.AccountAsset))
            {
                if (opts.AccountAsset.IsNumeric())
                {
                    accessRequest.AccountAssetId = int.Parse(opts.AccountAsset);
                }
                else
                {
                    accessRequest.AccountAssetName = opts.AccountAsset;
                }
            }
            if (!string.IsNullOrEmpty(opts.ReasonCode))
            {
                if (opts.ReasonCode.IsNumeric())
                {
                    accessRequest.ReasonCodeId = int.Parse(opts.ReasonCode);
                }
                else
                {
                    accessRequest.ReasonCode = opts.ReasonCode;
                }
            }
            if (!string.IsNullOrEmpty(opts.RequestedDuration))
            {
                accessRequest.RequestedDuration = TimeSpan.Parse(opts.RequestedDuration);
            }
            return(accessRequest);
        }