Example #1
0
        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;
        }
Example #2
0
        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;
        }
Example #3
0
        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;
        }
Example #4
0
        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;
        }
Example #5
0
 public CommandOutput OnExecute(CommandInput arguments)
 {
     var authOutput = CurrentHostContext.Default.GetUsers();
     var output = new CommandOutput
     {
         PostAction = CommandOutput.PostCommandAction.None,
         Data = authOutput,
         DisplayMessage = "Success"
     };
     return output;
 }
Example #6
0
        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;
        }
Example #7
0
        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;
        }
Example #8
0
        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;
        }
Example #9
0
        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;
        }
Example #10
0
        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;
        }
Example #11
0
        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;
        }
Example #12
0
        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;
        }
Example #13
0
        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;
        }
Example #14
0
        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;
        }
Example #15
0
        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;
        }
Example #16
0
        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;
        }
Example #17
0
        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;
        }
Example #18
0
        public CommandOutput OnExecute(CommandInput arguments)
        {
            var output = new CommandOutput {PostAction = CommandOutput.PostCommandAction.None};

            var sid = long.Parse(arguments["sid"]);
            var fromId = long.Parse(arguments["from"]);
            var toId = long.Parse(arguments["to"]);
            var clone = arguments.HasArgument("clone-param") &&
                        arguments["clone-param"].Equals("y", StringComparison.InvariantCultureIgnoreCase);

            var mappingsForSuite =
                CurrentHostContext.Default.Provider.ConfigurationStore.GetMapping(arguments.GetUserId(), sid);
            var sourceEnvironmentsMapping = mappingsForSuite.Where(x => x.EnvironmentId == fromId);
            var environmentsMapping = sourceEnvironmentsMapping as MappingModel[] ?? sourceEnvironmentsMapping.ToArray();
            if (!environmentsMapping.Any())
            {
                output.MessageType = CommandOutput.DisplayMessageType.Error;
                output.DisplayMessage = "No Mappings found";
                return output;
            }

            var targetMapping = new List<MappingModel>();
            if (clone)
            {
                var suiteParameters = CurrentHostContext.Default.Provider.ConfigurationStore.GetParameters(
                    arguments.GetUserId(), sid);
                foreach (var mapping in environmentsMapping)
                {
                    var param = suiteParameters.FirstOrDefault(x => x.ParameterId == mapping.ParameterId);
                    if (param != null)
                    {
                        var newParam = CurrentHostContext.Default.Provider.ConfigurationStore.AddParameter(param);
                        if (newParam != null)
                        {
                            mapping.ParameterId = newParam.AutoIncrementId;
                            mapping.EnvironmentId = toId;
                            targetMapping.Add(mapping);
                        }
                    }
                }
            }
            else
            {
                foreach (var mapping in environmentsMapping)
                {
                    mapping.EnvironmentId = toId;
                    targetMapping.Add(mapping);
                }
            }

            bool success = true;

            targetMapping.ForEach(
                mapping => success &= CurrentHostContext.Default.Provider.ConfigurationStore.AddMapping(mapping) != null);

            output.DisplayMessage = success
                ? String.Format("Mappings{0} from environment {1} to {2}",
                    clone ? "/Parameters Cloned" : " Promoted", fromId, toId)
                : "Some error occured while promoting pamareters/mapping";

            return output;
        }
Example #19
0
        public CommandOutput OnExecute(CommandInput arguments)
        {
            var output = new CommandOutput {PostAction = CommandOutput.PostCommandAction.None};
            long appId = -1, serverId = -1, envId = -1, regionId = -1;
            long userId = arguments.GetUserId();
            string server, env, region;

            server = !arguments.HasArgument("server") ? "*" : arguments["server"];
            env = !arguments.HasArgument("env") ? "*" : arguments["env"];
            region = !arguments.HasArgument("region") ? "*" : arguments["region"];

            if (!long.TryParse(arguments["app"], out appId))
                appId =
                    CurrentHostContext.Default.Provider.ConfigurationStore.GetApplication(userId, arguments["app"])
                        .ApplicationId.GetValueOrDefault();

            if (!long.TryParse(server, out serverId))
                serverId =
                    CurrentHostContext.Default.Provider.ConfigurationStore.GetServer(userId, server)
                        .ServerId.GetValueOrDefault(-1);

            if (!long.TryParse(env, out envId))
                envId =
                    CurrentHostContext.Default.Provider.ConfigurationStore.GetEnvironment(userId, env)
                        .EnvironmentId.GetValueOrDefault(-1);

            if (!long.TryParse(region, out regionId))
                regionId =
                    CurrentHostContext.Default.Provider.ConfigurationStore.GetRegion(userId, region)
                        .RegionId.GetValueOrDefault(-1);

            List<ConfigurationModel> model =
                CurrentHostContext.Default.Provider.ConfigurationStore.GetConfigurations(userId,
                    appId,
                    serverId, envId, regionId, string.Empty);

            model.ForEach(config =>
            {
                if (config.IsEncrypted)
                {
                    var pk = arguments["unprotect"];
                    if (pk != null)
                    {
                        var suite =
                            CurrentHostContext.Default.Provider.ConfigurationStore.GetSuite(arguments.GetUserId(),
                                config.SuiteId);

                        if (suite.PublicKey.Equals(pk, StringComparison.InvariantCulture))
                        {
                            config.ParameterValue = EncryptionEngine.Default.Decrypt(config.ParameterValue,
                                suite.PrivateKey, null);
                        }
                    }
                }
            });

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

            return output;
        }
Example #20
0
        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;
        }
Example #21
0
        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;
        }
Example #22
0
        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;
        }
Example #23
0
        public CommandOutput OnExecute(CommandInput arguments)
        {
            var output = new CommandOutput {PostAction = CommandOutput.PostCommandAction.None};
            bool completed = false;
            long userId = arguments.GetUserId();
            ParameterModel model = default(ParameterModel);

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

                if (paramId != -1)
                {
                    model = CurrentHostContext.Default.Provider.ConfigurationStore.GetParameter(userId, paramId);
                    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)
            {
                var pk = arguments["pk"];
                if (pk != null && model.IsEncrypted)
                {
                    var suite = CurrentHostContext.Default.Provider.ConfigurationStore.GetSuite(arguments.GetUserId(),
                        model.SuiteId);

                    if (suite.PublicKey.Equals(pk, StringComparison.InvariantCulture))
                    {
                        model.ParameterValue = EncryptionEngine.Default.Decrypt(model.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 = model;
                output.DisplayMessage = "Success";
            }
            else
            {
                output.DisplayMessage = DoesNotExist;
                output.MessageType = CommandOutput.DisplayMessageType.Error;
            }

            return output;
        }