public ServerShadow(ServerRecord record, SystemLog stdLog) { if (record.LogPath != null) { if (record.LogPath == ":std:") { log = stdLog; } else { log = new FileLog(record.LogPath); } } pseudoAddress = record.Mask; if (record.Address == null) { destination = null; } else { destination = new IPEndPoint(ServerHub.GetIPAddress(record.Address), record.Port); } this.record = record; setsGroup = new SetsGroup(record.Sets); }
public void Save(IParameterGroup group) { var props = group .GetType() .GetProperties() .Where(x => x.CustomAttributes.Where(y => y.AttributeType == typeof(ParameterAttribute)).Any()); foreach (var prop in props) { var dv = (ParameterAttribute)prop.GetCustomAttributes(false).ToList().Single(x => x is ParameterAttribute); if (!dv.CreateAutomatically) { continue; } var mp = new MongoParameter { Key = prop.Name, Value = prop.GetValue(group).ToString() }; var filter = Builders <MongoParameter> .Filter.Eq(x => x.Key, mp.Key); if (Mongo.Exists(filter)) { var updateFilter = Builders <MongoParameter> .Update.Set(x => x.Value, mp.Value); if (Mongo.UpdateField(filter, updateFilter)) { Console.WriteLine($"{mp.Key} updated value to \"{mp.Value}\""); } } } }
public void Load(IParameterGroup group) { var props = group .GetType() .GetProperties() .Where(x => x.CustomAttributes.Where(y => y.AttributeType == typeof(ParameterAttribute)).Any()); foreach (var prop in props) { var dv = (ParameterAttribute)prop.GetCustomAttributes(false).ToList().Single(x => x is ParameterAttribute); if (!dv.CreateAutomatically) { continue; } var filterKey = Builders <MongoParameter> .Filter.Eq(x => x.Key, prop.Name); var filterComputer = Builders <MongoParameter> .Filter.Eq(x => x.SpecificComputer, Environment.MachineName); var filterComplex = Builders <MongoParameter> .Filter.And(filterKey, filterComputer); MongoParameter mp = null; if (dv.Range == ParameterRange.Local) { mp = Mongo.GetOne(filterComplex); } else { mp = Mongo.GetOne(filterKey); } if (mp == null) { if (!dv.CreateAutomatically) { continue; } mp = new MongoParameter { Key = prop.Name, Value = dv.DefaultValue.ToString(), SpecificComputer = dv.Range == ParameterRange.Global ? null : Environment.MachineName }; Console.WriteLine($"Creating {mp.Key} with default value of {mp.Value}"); Mongo.InsertOne(mp); } TypeConverter typeConverter = TypeDescriptor.GetConverter(dv.DefaultValue); object propValue = typeConverter.ConvertFromString(mp.Value); prop.SetValue(group, propValue); Console.WriteLine($"{prop.Name} loaded with value: {propValue}"); } }
public IDatabaseInstance CreateDatabase(DeputyBase databaseEngineVersion, string identification, string databaseName, double?port, string userName, ISecret passwordSecret, StorageType storageType, InstanceClass instanceClass, InstanceSize instanceSize, IVpc vpc, ISecurityGroup securityGroup, ISubnetGroup subnetGroup, IParameterGroup parameterGroup = null, double?allocatedStorageGb = 5, RemovalPolicy removalPolicy = RemovalPolicy.DESTROY, bool deleteAutomatedBackups = false, int backupRetentionDays = 1, bool deletionProtection = false, string[] logTypes = null, bool?storageEncrypted = null, bool?enableIamAuthentication = false, Duration enhancedMonitoringInterval = null, bool multiAZEnabled = true, bool autoMinorVersionUpgrade = false) { BasicDatabaseInfra(vpc); var engine = GetInstanceEngine(databaseEngineVersion); return(new DatabaseInstance(Scope, identification, new DatabaseInstanceProps { Engine = engine, RemovalPolicy = removalPolicy, DeletionProtection = deletionProtection, Credentials = Credentials.FromPassword(userName, passwordSecret.SecretValue), StorageType = storageType, DatabaseName = databaseName, Port = port, SubnetGroup = subnetGroup, Vpc = vpc, SecurityGroups = new[] { securityGroup }, DeleteAutomatedBackups = deleteAutomatedBackups, BackupRetention = Duration.Days(backupRetentionDays), AllocatedStorage = allocatedStorageGb, InstanceType = InstanceType.Of(instanceClass, instanceSize), ParameterGroup = parameterGroup, CloudwatchLogsExports = logTypes, StorageEncrypted = storageEncrypted, IamAuthentication = enableIamAuthentication, MonitoringInterval = enhancedMonitoringInterval, MultiAz = multiAZEnabled, AutoMinorVersionUpgrade = autoMinorVersionUpgrade })); }
private void GetDatabaseResources(DatabaseOptions databaseOption, out double?databasePort, out IVpc vpc, out ISecurityGroup securityGroup, out ISubnetGroup subnetGroup, out bool deletionProtection, out Duration enchancedMonitoringInterval, out ISecret passwordSecret, out IParameterGroup parameterGroup) //NOSONAR number of params { // Parse database port databasePort = ParseDatabasePort(databaseOption); // Locate vpc vpc = LocateVPC(databaseOption); // Locate security group securityGroup = LocateSecurityGroup(databaseOption); // Locate subnet group subnetGroup = LocateSubnetGroup(databaseOption); // Locate parameter group parameterGroup = LocateParameterGroup(databaseOption); deletionProtection = databaseOption.DeletionProtection ?? false; enchancedMonitoringInterval = databaseOption.EnhancedMonitoringIntervalSeconds.HasValue ? Duration.Seconds(databaseOption.EnhancedMonitoringIntervalSeconds.Value) : null; passwordSecret = SetDatabasePassword(databaseOption); }
public IDatabaseInstance AddDatabase(MysqlEngineVersion databaseEngineVersion, string identification, string databaseName, double?port, string userName, ISecret passwordSecret, StorageType storageType, InstanceClass instanceClass, InstanceSize instanceSize, IVpc vpc, ISecurityGroup securityGroup, ISubnetGroup subnetGroup, IParameterGroup parameterGroup = null, double?allocatedStorageGb = 5, RemovalPolicy removalPolicy = RemovalPolicy.DESTROY, bool deleteAutomatedBackups = false, int backupRetentionDays = 1, bool deletionProtection = false, string[] logTypes = null, bool?storageEncrypted = null, bool?enableIamAuthentication = null, Duration enhancedMonitoringInterval = null, bool multiAZEnabled = true, bool autoMinorVersionUpgrade = false) //NOSONAR number of params { return(HandlerResources.AwsCdkDatabaseHandler.CreateDatabase(databaseEngineVersion, identification, databaseName, port, userName, passwordSecret, storageType, instanceClass, instanceSize, vpc, securityGroup, subnetGroup, parameterGroup, allocatedStorageGb, removalPolicy, deleteAutomatedBackups, backupRetentionDays, deletionProtection, logTypes, storageEncrypted, enableIamAuthentication, enhancedMonitoringInterval, multiAZEnabled, autoMinorVersionUpgrade)); }