コード例 #1
0
ファイル: NewEnv.cs プロジェクト: punitganshani/KonfDB
        public bool IsValid(CommandInput input)
        {
            EnvironmentType envType;

            return input.HasArgument("name") && input.HasArgument("type") && input.HasArgument("sid")
                   && Enum.TryParse(input["type"], out environmentType);
        }
コード例 #2
0
ファイル: NewSuite.cs プロジェクト: punitganshani/KonfDB
        public CommandOutput OnExecute(CommandInput arguments)
        {
            var output = new CommandOutput {PostAction = CommandOutput.PostCommandAction.None};

            var name = arguments["name"];

            long userId = arguments.GetUserId();

            if (string.IsNullOrEmpty(name))
            {
                output.DisplayMessage = "Suite Name missing";
                output.PostAction = CommandOutput.PostCommandAction.ShowCommandHelp;
                output.MessageType = CommandOutput.DisplayMessageType.Error;
            }
            else
            {
                var keys = EncryptionEngine.Default.CreateKeys();
                var model = new SuiteCreateModel
                {
                    SuiteName = name,
                    SuiteType = SuiteTypes.PersonalWithMultiEnvironment,
                    PrivateKey = keys.Item1,
                    UsesSysEncryption = true,
                    PublicKey = keys.Item2,
                    UserId = userId
                };

                model.Environments.Add(new EnvironmentModel
                {
                    EnvironmentName = "*",
                    EnvironmentType = EnvironmentType.PROD
                });

                model.Applications.Add(new ApplicationModel
                {
                    ApplicationName = "*",
                    Description = "All Applications in Suite " + name
                });

                model.Regions.Add(new RegionModel
                {
                    RegionName = "*",
                    Description = "All Regions in Suite " + name
                });

                model.Servers.Add(new ServerModel
                {
                    ServerName = "*",
                    Description = "All Servers in Suite " + name
                });

                var suite = CurrentHostContext.Default.Provider.ConfigurationStore.AddSuite(model);
                output.Data = suite;
                output.DisplayMessage = "Success";

                output.PostAction = CommandOutput.PostCommandAction.None;
            }

            return output;
        }
コード例 #3
0
ファイル: AddAudit.cs プロジェクト: punitganshani/KonfDB
        public bool IsValid(CommandInput input)
        {
            if (input.HasArgument("record"))
            {
                model = input["record"].FromJsonToObject<AuditRecordModel>();
                return model != null;
            }
            AuditArea auditArea = AuditArea.Suite;
            AuditReason auditReason = AuditReason.Retrieved;
            bool valid = Enum.TryParse(input["a"], out auditArea)
                         && input.HasArgument("akey")
                         && input.HasArgument("m")
                         && Enum.TryParse(input["r"], out auditReason);

            if (valid)
            {
                model = new AuditRecordModel
                {
                    Area = auditArea,
                    Key = input["akey"],
                    Message = input["m"],
                    Reason = auditReason
                };
            }

            return valid;
        }
コード例 #4
0
ファイル: NewMap.cs プロジェクト: punitganshani/KonfDB
        public CommandOutput OnExecute(CommandInput arguments)
        {
            var output = new CommandOutput {PostAction = CommandOutput.PostCommandAction.None};
            long parameterId = long.Parse(arguments["pid"]);
            long suiteId = long.Parse(arguments["sid"]);
            long serverId = -1, appId = -1, regionId = -1, environmentId = -1;
            long userId = arguments.GetUserId();

            var suite = CurrentHostContext.Default.Provider.ConfigurationStore.GetSuite(userId, suiteId);
            var parameter = CurrentHostContext.Default.Provider.ConfigurationStore.GetParameter(userId, parameterId);
            if (parameter.SuiteId != suite.SuiteId)
            {
                output.DisplayMessage = "No such parameter id (pid) exists for suite id:" + suite.SuiteId;
                output.MessageType = CommandOutput.DisplayMessageType.Error;
                return output;
            }

            if (!long.TryParse(arguments["srid"], out serverId) && suite.Servers.Any(x => x.ServerName == "*"))
                serverId = suite.Servers.First(x => x.ServerName == "*").ServerId.GetValueOrDefault();

            if (!long.TryParse(arguments["aid"], out appId) && suite.Applications.Any(x => x.ApplicationName == "*"))
                appId = suite.Applications.First(x => x.ApplicationName == "*").ApplicationId.GetValueOrDefault();

            if (!long.TryParse(arguments["rid"], out regionId) && suite.Regions.Any(x => x.RegionName == "*"))
                regionId = suite.Regions.First(x => x.RegionName == "*").RegionId.GetValueOrDefault();

            if (!long.TryParse(arguments["eid"], out environmentId) &&
                suite.Environments.Any(x => x.EnvironmentName == "*" && x.EnvironmentType == EnvironmentType.PROD))
                environmentId =
                    suite.Environments.First(x => x.EnvironmentName == "*" && x.EnvironmentType == EnvironmentType.PROD)
                        .EnvironmentId.GetValueOrDefault();

            if (serverId == 0 || appId == 0 || regionId == 0 || environmentId == 0)
            {
                output.DisplayMessage = "Invalid Map Parameters. Please try providing optional fields";
                output.MessageType = CommandOutput.DisplayMessageType.Error;
                output.PostAction = CommandOutput.PostCommandAction.ShowCommandHelp;

                return output;
            }

            var model = new MappingModel
            {
                ApplicationId = appId,
                EnvironmentId = environmentId,
                ParameterId = parameterId,
                RegionId = regionId,
                ServerId = serverId,
                SuiteId = suiteId,
                UserId = userId
            };

            MappingModel mapping = CurrentHostContext.Default.Provider.ConfigurationStore.AddMapping(model);

            output.Data = mapping;
            output.DisplayMessage = "Success";

            return output;
        }
コード例 #5
0
ファイル: GetParamLike.cs プロジェクト: punitganshani/KonfDB
        public CommandOutput OnExecute(CommandInput arguments)
        {
            var output = new CommandOutput {PostAction = CommandOutput.PostCommandAction.None};
            long suiteId = -1;
            long userId = arguments.GetUserId();
            long.TryParse(arguments["sid"], out suiteId);
            var name = arguments["name"];

            List<ParameterModel> listOfParams = new List<ParameterModel>();

            if (suiteId != -1)
            {
                listOfParams = CurrentHostContext.Default.Provider.ConfigurationStore.GetParametersLike(userId, suiteId,
                    name);
            }
            else
            {
                output.DisplayMessage = "No such suite id exists: " + suiteId;
                output.PostAction = CommandOutput.PostCommandAction.ShowCommandHelp;
                output.MessageType = CommandOutput.DisplayMessageType.Error;
            }

            if (listOfParams.Count > 0)
            {
                var pk = arguments["pk"];
                if (pk != null)
                {
                    var suite = CurrentHostContext.Default.Provider.ConfigurationStore.GetSuite(userId, suiteId);

                    if (suite.PublicKey.Equals(pk, StringComparison.InvariantCulture))
                    {
                        listOfParams.ForEach(
                            x =>
                            {
                                x.ParameterValue = EncryptionEngine.Default.Decrypt(x.ParameterValue, suite.PrivateKey,
                                    null);
                            });
                    }
                    else
                    {
                        output.DisplayMessage = "Invalid combination of Private / Public Key to decrypt ParameterValue";
                        output.MessageType = CommandOutput.DisplayMessageType.Error;

                        return output;
                    }
                }
                output.Data = listOfParams;
                output.DisplayMessage = "Success";
            }
            else
            {
                output.DisplayMessage = DoesNotExist;
                output.MessageType = CommandOutput.DisplayMessageType.Error;
            }

            return output;
        }
コード例 #6
0
ファイル: GetSuites.cs プロジェクト: punitganshani/KonfDB
        public CommandOutput OnExecute(CommandInput arguments)
        {
            var output = new CommandOutput {PostAction = CommandOutput.PostCommandAction.None};
            var listOfSuites = CurrentHostContext.Default.Provider.ConfigurationStore.GetSuites(arguments.GetUserId());

            output.Data = listOfSuites;
            output.DisplayMessage = "Success";

            return output;
        }
コード例 #7
0
ファイル: DeleteMap.cs プロジェクト: punitganshani/KonfDB
 public AuditRecordModel GetAuditCommand(CommandInput input)
 {
     return new AuditRecordModel
     {
         Area = AuditArea.Mapping,
         Reason = AuditReason.Removed,
         Message = input.Command,
         Key = input["mid"],
         UserId = input.GetUserId()
     };
 }
コード例 #8
0
ファイル: Who.cs プロジェクト: punitganshani/KonfDB
 public CommandOutput OnExecute(CommandInput arguments)
 {
     var authOutput = CurrentHostContext.Default.GetUsers();
     var output = new CommandOutput
     {
         PostAction = CommandOutput.PostCommandAction.None,
         Data = authOutput,
         DisplayMessage = "Success"
     };
     return output;
 }
コード例 #9
0
ファイル: GetRegions.cs プロジェクト: punitganshani/KonfDB
 public AuditRecordModel GetAuditCommand(CommandInput input)
 {
     return new AuditRecordModel
     {
         Area = AuditArea.Region,
         Reason = AuditReason.Retrieved,
         Message = input.Command,
         Key = input["sid"],
         UserId = input.GetUserId()
     };
 }
コード例 #10
0
ファイル: DeleteRegion.cs プロジェクト: punitganshani/KonfDB
        public CommandOutput OnExecute(CommandInput arguments)
        {
            var output = new CommandOutput {PostAction = CommandOutput.PostCommandAction.None};
            var regionId = long.Parse(arguments["rid"]);
            long userId = arguments.GetUserId();
            var success = CurrentHostContext.Default.Provider.ConfigurationStore.DeleteRegion(userId, regionId);

            output.DisplayMessage = success ? "Region deleted successfully!" : "Could not delete Region";

            return output;
        }
コード例 #11
0
ファイル: GrantAccess.cs プロジェクト: punitganshani/KonfDB
 public AuditRecordModel GetAuditCommand(CommandInput input)
 {
     return new AuditRecordModel
     {
         Area = AuditArea.User,
         Reason = AuditReason.Changed,
         Message = input.Command,
         Key = input["user"],
         UserId = input.GetUserId()
     };
 }
コード例 #12
0
ファイル: NewApp.cs プロジェクト: punitganshani/KonfDB
 public AuditRecordModel GetAuditCommand(CommandInput input)
 {
     return new AuditRecordModel
     {
         Area = AuditArea.Application,
         Reason = AuditReason.Added,
         Message = input.Command,
         Key = input["name"],
         UserId = input.GetUserId()
     };
 }
コード例 #13
0
ファイル: AddAudit.cs プロジェクト: punitganshani/KonfDB
        public CommandOutput OnExecute(CommandInput arguments)
        {
            model.UserId = arguments.GetUserId();
            if (model.Key == null)
                model.Key = "<Unknown>";
            CurrentHostContext.Default.Provider.ConfigurationStore.AddAuditRecord(model);

            return new CommandOutput
            {
                PostAction = CommandOutput.PostCommandAction.None
            };
        }
コード例 #14
0
ファイル: GetRegions.cs プロジェクト: punitganshani/KonfDB
        public CommandOutput OnExecute(CommandInput arguments)
        {
            var output = new CommandOutput {PostAction = CommandOutput.PostCommandAction.None};
            long suiteId = -1;
            long userId = arguments.GetUserId();
            long.TryParse(arguments["sid"], out suiteId);
            var model = CurrentHostContext.Default.Provider.ConfigurationStore.GetRegions(userId, suiteId);

            output.Data = model;
            output.DisplayMessage = "Success";
            return output;
        }
コード例 #15
0
ファイル: GetMap.cs プロジェクト: punitganshani/KonfDB
        public CommandOutput OnExecute(CommandInput arguments)
        {
            var output = new CommandOutput {PostAction = CommandOutput.PostCommandAction.None};
            long suiteId = long.Parse(arguments["sid"]);
            long userId = arguments.GetUserId();
            List<MappingModel> listOfMaps = CurrentHostContext.Default.Provider.ConfigurationStore.GetMapping(userId,
                suiteId);
            output.Data = listOfMaps;
            output.DisplayMessage = "Success";

            return output;
        }
コード例 #16
0
ファイル: DeleteSuite.cs プロジェクト: punitganshani/KonfDB
        public CommandOutput OnExecute(CommandInput arguments)
        {
            var output = new CommandOutput {PostAction = CommandOutput.PostCommandAction.None};
            var suiteId = long.Parse(arguments["sid"]);
            long userId = arguments.GetUserId();
            var success = CurrentHostContext.Default.Provider.ConfigurationStore.DeleteSuite(new SuiteModel
            {
                UserId = userId,
                SuiteId = suiteId
            });

            output.DisplayMessage = success ? "Suite deleted successfully!" : "Could not delete suite";

            return output;
        }
コード例 #17
0
ファイル: RevokeAccess.cs プロジェクト: punitganshani/KonfDB
        public CommandOutput OnExecute(CommandInput arguments)
        {
            var output = new CommandOutput {PostAction = CommandOutput.PostCommandAction.None};
            long suiteId = long.Parse(arguments["sid"]);
            string username = arguments["user"];
            long loggedInUserId = arguments.GetUserId();

            bool success = CurrentHostContext.Default.Provider.ConfigurationStore.RevokeRoleAccessToSuite(suiteId,
                loggedInUserId, username);
            output.Data = success;
            output.DisplayMessage = success
                ? "Grants revoked successfully"
                : "Some problem occured while revoking rights from user";

            return output;
        }
コード例 #18
0
ファイル: GrantAccess.cs プロジェクト: punitganshani/KonfDB
        public CommandOutput OnExecute(CommandInput arguments)
        {
            var output = new CommandOutput {PostAction = CommandOutput.PostCommandAction.None};
            long suiteId = long.Parse(arguments["sid"]);
            string username = arguments["user"];
            long loggedInUserId = arguments.GetUserId();
            RoleType role = arguments.HasArgument("role") ? arguments["role"].ToEnum<RoleType>() : RoleType.ReadOnly;
            bool success = CurrentHostContext.Default.Provider.ConfigurationStore.GrantRoleAccessToSuite(suiteId,
                loggedInUserId,
                username, role);

            output.Data = success;
            output.DisplayMessage = success
                ? "Grants added successfully"
                : "Some problem occured while granting rights to user";
            return output;
        }
コード例 #19
0
ファイル: NewRegion.cs プロジェクト: punitganshani/KonfDB
        public CommandOutput OnExecute(CommandInput arguments)
        {
            var output = new CommandOutput {PostAction = CommandOutput.PostCommandAction.None};
            var name = arguments["name"];
            long suiteId = long.Parse(arguments["sid"]);
            long userId = arguments.GetUserId();
            var region = CurrentHostContext.Default.Provider.ConfigurationStore.AddRegion(new RegionModel
            {
                RegionName = name,
                IsActive = true,
                SuiteId = suiteId,
                UserId = userId
            });

            output.Data = region;
            output.DisplayMessage = "Success";

            return output;
        }
コード例 #20
0
ファイル: GetApp.cs プロジェクト: punitganshani/KonfDB
        public CommandOutput OnExecute(CommandInput arguments)
        {
            var output = new CommandOutput {PostAction = CommandOutput.PostCommandAction.None};
            bool completed = false;
            long userId = arguments.GetUserId();
            ApplicationModel model = default(ApplicationModel);

            if (arguments["name"] != null)
            {
                model = CurrentHostContext.Default.Provider.ConfigurationStore.GetApplication(userId, arguments["name"]);
                completed = true;
            }
            else if (arguments["id"] != null)
            {
                long appId = -1;
                long.TryParse(arguments["id"], out appId);

                if (appId != -1)
                {
                    model = CurrentHostContext.Default.Provider.ConfigurationStore.GetApplication(userId, appId);
                    completed = true;
                }
            }

            if (!completed)
            {
                output.DisplayMessage = "Invalid data in command received";
                output.PostAction = CommandOutput.PostCommandAction.ShowCommandHelp;
                output.MessageType = CommandOutput.DisplayMessageType.Error;
            }
            else if (model != null)
            {
                output.Data = model;
                output.DisplayMessage = "Success";
            }
            else
            {
                output.DisplayMessage = DoesNotExist;
                output.MessageType = CommandOutput.DisplayMessageType.Error;
            }

            return output;
        }
コード例 #21
0
ファイル: GetSettings.cs プロジェクト: punitganshani/KonfDB
        public CommandOutput OnExecute(CommandInput arguments)
        {
            var output = new CommandOutput
            {
                PostAction = CommandOutput.PostCommandAction.None,
                DisplayMessage = "Success"
            };

            bool active = true, autoLoad = true;
            if (arguments.HasArgument("active"))
                bool.TryParse(arguments["active"], out active);

            if (arguments.HasArgument("autoLoad"))
                bool.TryParse(arguments["autoLoad"], out autoLoad);

            output.Data = CurrentHostContext.Default.Provider.ConfigurationStore.GetSettings(active, autoLoad);

            return output;
        }
コード例 #22
0
ファイル: Help.cs プロジェクト: punitganshani/KonfDB
        public CommandOutput OnExecute(CommandInput arguments)
        {
            var commandFactory = CurrentHostContext.Default.CommandFactory;
            var commands = commandFactory.Commands.OrderBy(x => x.Keyword);
            var output = new CommandOutput();
            var builder = new StringBuilder();

            builder.AppendLine("Usage: <command>");
            builder.AppendLine();
            builder.AppendLine("Commands:");
            builder.AppendLine();

            foreach (var command in commands)
            {
                builder.AppendLine(String.Format("{0,-15}\t{1}", command.Keyword, command.Help));
            }

            output.DisplayMessage = builder.ToString();

            return output;
        }
コード例 #23
0
ファイル: NewParam.cs プロジェクト: punitganshani/KonfDB
        public CommandOutput OnExecute(CommandInput arguments)
        {
            var output = new CommandOutput {PostAction = CommandOutput.PostCommandAction.None};
            var name = arguments["name"];
            long suiteId = long.Parse(arguments["sid"]);
            var value = arguments["val"];
            var isEncrypted = arguments.HasArgument("protect");
            long userId = arguments.GetUserId();
            if (isEncrypted)
            {
                var suite = CurrentHostContext.Default.Provider.ConfigurationStore.GetSuite(userId, suiteId);
                if (suite != null)
                {
                    value = EncryptionEngine.Default.Encrypt(value, suite.PublicKey, null);
                }
                else
                {
                    output.DisplayMessage = "Could not retrieve suite :" + suiteId;
                    output.MessageType = CommandOutput.DisplayMessageType.Error;
                    output.PostAction = CommandOutput.PostCommandAction.ShowCommandHelp;

                    return output;
                }
            }

            var parameter = CurrentHostContext.Default.Provider.ConfigurationStore.AddParameter(new ParameterModel
            {
                ParameterName = name,
                ParameterValue = string.IsNullOrEmpty(value) ? string.Empty : value,
                IsActive = true,
                IsEncrypted = isEncrypted,
                SuiteId = suiteId,
                UserId = userId
            });

            output.Data = parameter;
            output.DisplayMessage = "Success";

            return output;
        }
コード例 #24
0
ファイル: NewUser.cs プロジェクト: punitganshani/KonfDB
        public CommandOutput OnExecute(CommandInput arguments)
        {
            var output = new CommandOutput();
            var username = arguments["name"];
            var password = arguments["pwd"];
            var confirmPassword = arguments["cpwd"];
            bool runSilent = arguments.HasArgument("silent");

            if (!password.Equals(confirmPassword))
            {
                output.DisplayMessage = "Password and Confirm Password do not match";
                output.PostAction = CommandOutput.PostCommandAction.ShowCommandHelp;
                return output;
            }
            try
            {
                RegisterModel model = CurrentHostContext.Default.Provider.ConfigurationStore.AddUser(username, password,
                    username.GetRandom());

                output.DisplayMessage = "User Added";
                output.Data = model;
                output.PostAction = CommandOutput.PostCommandAction.None;
            }
            catch (UserAlreadyExistsException ex)
            {
                if (!runSilent)
                {
                    output.DisplayMessage = ex.Message;
                }
                output.PostAction = CommandOutput.PostCommandAction.None;
            }
            catch
            {
                throw;
            }

            return output;
        }
コード例 #25
0
ファイル: UserAuth.cs プロジェクト: punitganshani/KonfDB
        public CommandOutput OnExecute(CommandInput arguments)
        {
            var username = arguments["name"];
            var password = arguments["pwd"];
            DateTime nowUtc = DateTime.UtcNow;
            int uniqueTime = (nowUtc.Day*10) + (nowUtc.Month*100) + ((nowUtc.Year%100)*1000);

            string token =
                EncryptionEngine.Get<SHA256Encryption>()
                    .Encrypt(String.Format("{0}{1}{2}", uniqueTime, username, password), null, null);

            // Authenticate in DB
            AuthenticationModel authInfo =
                CurrentHostContext.Default.Provider.ConfigurationStore.GetAuthenticatedInfo(username, password, token);

            if (!CurrentHostContext.Default.UserTokens.Contains(token))
                CurrentHostContext.Default.UserTokens.Add(token);

            var authenticationOutput = CurrentContext.Default.Cache.Get(token,
                () => new AuthenticationOutput
                {
                    Token = token,
                    Username = username,
                    IsAuthenticated = authInfo.IsAuthenticated,
                    UserId = authInfo.UserId,
                    ExpireUtc = DateTime.MaxValue
                }, CachePolicy.AlwaysLive);

            var output = new CommandOutput
            {
                PostAction = CommandOutput.PostCommandAction.None,
                Data = authenticationOutput,
                DisplayMessage = "Success"
            };
            return output;
        }
コード例 #26
0
ファイル: ServiceCore.cs プロジェクト: punitganshani/KonfDB
        internal CommandOutput ExecuteCommand(ServiceRequestContext context)
        {
            var userTokenFromCache = CurrentHostContext.Default.Cache.Get<AuthenticationOutput>(context.Token);

            CommandOutput commandOutput = null;
            try
            {
                var input = new CommandInput(new CommandArgs(context.Command));
                input.Add("Request.SessionId", context.SessionId);
                if (input.Keyword == null)
                    throw new InvalidDataException("Could not parse the command");

                var firstKeyword = input.Keyword.ToLower();
                if (_commandFactory.Commands.Any(x => IsCommand(firstKeyword, x, userTokenFromCache)))
                {
                    var commandObject =
                        _commandFactory.Commands.FirstOrDefault(x => IsCommand(firstKeyword, x, userTokenFromCache));

                    if (userTokenFromCache != null) // enrich with UserId
                        input.AssociateUserId(userTokenFromCache.UserId.GetValueOrDefault(-1));

                    if (RequiresCaching(commandObject))
                    {
                        // cache it
                        commandOutput = CurrentHostContext.Default.Cache.Get(context.Command, () =>
                            ExecuteCommandInternal(input, commandObject));
                    }
                    else
                    {
                        commandOutput = ExecuteCommandInternal(input, commandObject);
                    }

                    AuditExecution(userTokenFromCache, input, commandObject);

                    // Execute all subcommands
                    commandOutput.SubCommands.ForEach(x => ExecuteCommand(new ServiceRequestContext
                    {
                        Command = x,
                        SessionId = context.SessionId,
                        Token = context.Token
                    }));
                }
                else
                {
                    commandOutput = _helpCommand.OnExecute(input);
                }
            }
            catch (DbEntityValidationException e)
            {
                var builder = new StringBuilder();

                foreach (var eve in e.EntityValidationErrors)
                {
                    builder.AppendFormat("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                        eve.Entry.Entity.GetType().Name, eve.Entry.State).AppendLine();
                    foreach (var ve in eve.ValidationErrors)
                    {
                        builder.AppendFormat("- Property: \"{0}\", Error: \"{1}\"",
                            ve.PropertyName, ve.ErrorMessage).AppendLine();
                    }
                }

                CurrentHostContext.Default.Log.Error(builder.ToString());
                commandOutput = new CommandOutput
                {
                    MessageType = CommandOutput.DisplayMessageType.Error,
                    DisplayMessage = "Errors: " + builder
                };
            }
            catch (Exception ex)
            {
                CurrentHostContext.Default.Log.Error(ex.GetDetails());
                commandOutput = new CommandOutput
                {
                    MessageType = CommandOutput.DisplayMessageType.Error,
                    DisplayMessage = "Errors: " + ex.GetDetails()
                };
            }

            return commandOutput;
        }
コード例 #27
0
ファイル: ServiceCore.cs プロジェクト: punitganshani/KonfDB
        private CommandOutput ExecuteCommandInternal(CommandInput input, ICommand commandObject)
        {
            CommandOutput commandOutput = null;
            bool executed = false;
            if (commandObject != null)
            {
                if (commandObject.IsValid(input))
                {
                    commandOutput = commandObject.OnExecute(input);
                    executed = true;
                }

                if (!executed)
                {
                    commandOutput = new CommandOutput
                    {
                        PostAction = CommandOutput.PostCommandAction.ShowCommandHelp,
                        DisplayMessage = "One or more parameters were not passed correctly",
                        MessageType = CommandOutput.DisplayMessageType.Error
                    };
                }

                if (commandOutput != null && commandOutput.PostAction == CommandOutput.PostCommandAction.ShowCommandHelp)
                {
                    commandOutput.DisplayMessage += Environment.NewLine
                                                    + "\tUsage:"
                                                    + String.Format("\t{0}", commandObject.Command)
                                                    + Environment.NewLine
                                                    + "\tHelp:"
                                                    + Environment.NewLine
                                                    + Environment.NewLine
                                                    + String.Format("\t{0}", commandObject.Help);
                }
            }

            return commandOutput;
        }
コード例 #28
0
ファイル: ServiceCore.cs プロジェクト: punitganshani/KonfDB
        private void AuditExecution(IAuthenticationOutput userTokenFromCache,
            CommandInput input, ICommand commandObject)
        {
            // Audit an AUTH Command
            if (CurrentHostContext.Default.Audit.Enabled)
            {
                var authCommand = commandObject as IAuditCommand;
                if (authCommand != null)
                {
                    var auditRecord = authCommand.GetAuditCommand(input);

                    if (auditRecord != null)
                    {
                        Task.Factory.StartNew(() =>
                        {
                            var auditInput = new CommandInput(new CommandArgs("AddAudit"));
                            auditInput.Add("record", auditRecord.ToJson());

                            if (userTokenFromCache != null) // enrich with UserId
                                auditInput.AssociateUserId(userTokenFromCache.UserId.GetValueOrDefault(-1));

                            ExecuteCommandInternal(auditInput, _auditCommand);
                        })
                            .ContinueWith(task =>
                                CurrentHostContext.Default.Log.ErrorFormat("Error adding audit record {0}",
                                    task.Exception.GetDetails()), TaskContinuationOptions.OnlyOnFaulted);
                    }
                }
            }
        }
コード例 #29
0
ファイル: GetServer.cs プロジェクト: punitganshani/KonfDB
 public bool IsValid(CommandInput input)
 {
     return input.HasArgument("name") || input.HasArgument("id");
 }
コード例 #30
0
ファイル: GetServer.cs プロジェクト: punitganshani/KonfDB
 public AuditRecordModel GetAuditCommand(CommandInput input)
 {
     return new AuditRecordModel
     {
         Area = AuditArea.Server,
         Reason = AuditReason.Retrieved,
         Message = input.Command,
         Key = input.HasArgument("name") ? input["name"] : input["id"],
         UserId = input.GetUserId()
     };
 }