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); }
public AuditRecordModel GetAuditCommand(CommandInput input) { return(new AuditRecordModel { Area = AuditArea.Mapping, Reason = AuditReason.Added, Message = input.Command, Key = input["pid"] + "-" + input["sid"], UserId = input.GetUserId() }); }
public AuditRecordModel GetAuditCommand(CommandInput input) { return(new AuditRecordModel { Area = AuditArea.User, Reason = AuditReason.Changed, Message = input.Command, Key = input["user"], UserId = input.GetUserId() }); }
public AuditRecordModel GetAuditCommand(CommandInput input) { return(new AuditRecordModel { Area = AuditArea.Suite, Reason = AuditReason.Added, Message = input.Command, Key = input["name"], UserId = input.GetUserId() }); }
public AuditRecordModel GetAuditCommand(CommandInput input) { return(new AuditRecordModel { Area = AuditArea.Suite, Reason = AuditReason.Retrieved, Message = input.Command, Key = input.HasArgument("name") ? input["name"] : input["id"], UserId = input.GetUserId() }); }
public AuditRecordModel GetAuditCommand(CommandInput input) { return(new AuditRecordModel { Area = AuditArea.Environment, Reason = AuditReason.Removed, Message = input.Command, Key = input["eid"], UserId = input.GetUserId() }); }
public AuditRecordModel GetAuditCommand(CommandInput input) { return(new AuditRecordModel { Area = AuditArea.Mapping, Reason = AuditReason.Executed, Message = input.Command, Key = input["app"], UserId = input.GetUserId() }); }
public AuditRecordModel GetAuditCommand(CommandInput input) { return(new AuditRecordModel { Area = AuditArea.Server, Reason = AuditReason.Retrieved, Message = input.Command, Key = input["sid"], UserId = input.GetUserId() }); }
public CommandOutput OnExecute(CommandInput arguments) { var output = new CommandOutput { PostAction = CommandOutput.PostCommandAction.None }; var envId = long.Parse(arguments["eid"]); long userId = arguments.GetUserId(); var success = CurrentHostContext.Default.Provider.ConfigurationStore.DeleteEnvironment(userId, envId); output.DisplayMessage = success ? "Environment deleted successfully!" : "Could not delete Environment"; return(output); }
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 }); }
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.GetServers(userId, suiteId); output.Data = model; output.DisplayMessage = "Success"; return(output); }
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); }
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); }
public CommandOutput OnExecute(CommandInput arguments) { var output = new CommandOutput { PostAction = CommandOutput.PostCommandAction.None }; bool completed = false; SuiteModel model = default(SuiteModel); long userId = arguments.GetUserId(); if (arguments["name"] != null) { model = CurrentHostContext.Default.Provider.ConfigurationStore.GetSuite(userId, arguments["name"]); completed = true; } else if (arguments["id"] != null) { long suiteId = -1; long.TryParse(arguments["id"], out suiteId); if (suiteId != -1) { model = CurrentHostContext.Default.Provider.ConfigurationStore.GetSuite(userId, suiteId); 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); }
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); }
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); }
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); }
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 application = CurrentHostContext.Default.Provider.ConfigurationStore.AddApplication(new ApplicationModel { ApplicationName = name, IsActive = true, SuiteId = suiteId, UserId = userId }); output.Data = application; output.DisplayMessage = "Application Created"; return(output); }
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 environment = CurrentHostContext.Default.Provider.ConfigurationStore.AddEnvironment(new EnvironmentModel { EnvironmentName = name, EnvironmentType = environmentType, IsActive = true, SuiteId = suiteId, UserId = userId }); output.Data = environment; output.DisplayMessage = "Success"; return(output); }
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); }
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); }
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); }
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); }
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); }
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); }