public bool IsValid(CommandInput input) { EnvironmentType envType; return(input.HasArgument("name") && input.HasArgument("type") && input.HasArgument("sid") && Enum.TryParse(input["type"], out environmentType)); }
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); }
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 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); }
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 }; 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(); 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); }
public bool IsValid(CommandInput input) { return(input.HasArgument("sid")); }
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 bool IsValid(CommandInput input) { return(input.HasArgument("name") && input.HasArgument("pwd")); }
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); }