private async Task HandleSingleParam(HttpContext context, ConfigurationIdentity clientIdentity) { switch (context.Request.Method) { case "GET": { var clientResourceCatalogue = await archive.GetArchiveConfigCatalogue(clientIdentity); await httpResponseFactory.BuildJsonResponse(context, clientResourceCatalogue); break; } case "DELETE": { if (context.Request.Query.TryGetValue("before", out var pram) && DateTime.TryParse(pram, out var dateParam)) { await archive.DeleteOldArchiveConfigs(dateParam, clientIdentity); httpResponseFactory.BuildNoContentResponse(context); break; } httpResponseFactory.BuildNotFoundStatusResponse(context); break; } default: { httpResponseFactory.BuildMethodNotAcceptedStatusResponse(context); break; } } }
private static ConfigurationSet CreateGenericInstance(Type type, ConfigurationIdentity identity) { var result = (ConfigurationSet)Activator.CreateInstance(type); result.Instance = identity; return(result); }
public async Task DeleteArchiveResource(string name, ConfigurationIdentity identity) { var containerRef = client.GetContainerReference(container); var location = GetArchiveResourcePath(identity, name); var entry = containerRef.GetBlockBlobReference(location); await entry.DeleteIfExistsAsync(); }
public async void CopyResources() { byte[] resource = new byte[128]; UpdateResourceRequest request = new UpdateResourceRequest() { Identity = configId, Name = "Resource 128.png", Content = new MemoryStream(resource) }; await target.UpdateResource(request); var client2 = new ConfigurationClient { ClientId = "3FEE5A18-A00F-4565-BEFE-C79E0823F6D4", Name = "Client 2", Description = "A description Client" }; var configId2 = new ConfigurationIdentity(client2, new Version(1, 0)); await target.CopyResources(configId, configId2); var result = await target.GetResourceCatalogue(configId2); Assert.Single(result); Assert.Equal(request.Name, result.First().Name); }
public LocalConfigServerClient(IConfigProvider configProvider, string applicationId) { this.configProvider = configProvider; this.applicationId = new ConfigurationIdentity { ClientId = applicationId }; }
/// <summary> /// Gets Configuration /// </summary> /// <param name="type">Type of configuration to be retrieved</param> /// <param name="id">Identity of Configuration requested i.e which client requested the configuration</param> /// <returns>ConfigInstance of the type requested</returns> public Task <ConfigInstance> GetAsync(Type type, ConfigurationIdentity id) { var tcs = new TaskCompletionSource <ConfigInstance>(); tcs.SetResult(Get(type, id)); return(tcs.Task); }
public ConfigurationSetFactoryTests() { identity = new ConfigurationIdentity("fbce468f-0950-4b5f-a7e1-8e24e746bb91"); registry = new ConfigurationSetRegistry(); registry.AddConfigurationSet(new TestConfiguationModule().BuildConfigurationSetModel()); defaultOptions = new List <ExternalOption> { new ExternalOption { Id = 1, Description = "testOne" } }; additionalOption = new List <OptionDependentOnAnotherOption> { new OptionDependentOnAnotherOption { Id = 1, ExternalOption = defaultOptions[0], Value = 23.3 } }; mockConfigProvider = new Mock <IConfigProvider>(); mockConfigProvider.Setup(test => test.GetCollectionAsync(typeof(ExternalOption), It.IsAny <ConfigurationIdentity>())) .Returns(() => Task.FromResult <IEnumerable>(defaultOptions)); mockConfigProvider.Setup(test => test.GetCollectionAsync(typeof(OptionDependentOnAnotherOption), It.IsAny <ConfigurationIdentity>())) .Returns(() => Task.FromResult <IEnumerable>(additionalOption)); defaultConfig = new SampleConfig { LlamaCapacity = 23, ExternalOption = defaultOptions[0] }; var instance = new ConfigInstance <SampleConfig>(defaultConfig, identity.ClientId); mockConfigProvider.Setup(test => test.GetAsync(typeof(SampleConfig), identity)) .Returns(() => Task.FromResult <ConfigInstance>(instance)); target = new ConfigurationSetFactory(mockConfigProvider.Object, new TestOptionSetFactory(), registry); }
/// <summary> /// Gets Configuration /// </summary> /// <typeparam name="TConfig">Type of configuration to be retrieved</typeparam> /// <param name="id">Identity of Configuration requested i.e which client requested the configuration</param> /// <returns>ConfigInstance of the type requested</returns> public Task <ConfigInstance <TConfig> > GetAsync <TConfig>(ConfigurationIdentity id) where TConfig : class, new() { var tcs = new TaskCompletionSource <ConfigInstance <TConfig> >(); tcs.SetResult(Get <TConfig>(id)); return(tcs.Task); }
public async Task <CommandResult> Handle(CreateSnapshotCommand command) { var client = await clientService.GetClientOrDefault(command.ClientId); if (client == null || string.IsNullOrWhiteSpace(client.Group)) { return(CommandResult.Failure("Could not find client with group. Can only create snapshot for client with group")); } var models = configurationModelRegistry.GetConfigurationRegistrations(true); var version = configurationModelRegistry.GetVersion(); var configurationIdentity = new ConfigurationIdentity(client, version); var snapshotInfo = new SnapshotEntryInfo { Id = Guid.NewGuid().ToString(), GroupId = client.Group, Name = command.Name, TimeStamp = DateTime.UtcNow }; var configurations = new List <ConfigInstance>(); foreach (var model in models) { var configurationInstance = await configurationService.GetAsync(model.ConfigType, configurationIdentity); configurations.Add(configurationInstance); } await snapshotRepository.SaveSnapshot(new ConfigurationSnapshotEntry { Info = snapshotInfo, Configurations = configurations }); return(CommandResult.Success()); }
public async Task <IEnumerable <ResourceEntryInfo> > GetResourceCatalogue(ConfigurationIdentity identity) { var containerRef = client.GetContainerReference(container); var entry = (await GetResources(containerRef, identity)).Select(Map).ToArray(); return(entry); }
public Task DeleteArchiveConfig(string name, ConfigurationIdentity identity) { string path = Path.Combine(GetArchiveResourceSetFolder(identity).FullName, name); File.Delete(path); return(Task.FromResult(true)); }
private async Task HandleUploadRequest(HttpContext context, string clientid, ConfigurationSetModel configSetModel) { var input = await context.GetJObjectFromJsonBodyAsync(); var mappedConfigs = configurationSetUploadMapper.MapConfigurationSetUpload(input, configSetModel).ToArray(); var identity = new ConfigurationIdentity(clientid); var validationResult = await ValidateConfigs(mappedConfigs, configSetModel, identity); if (validationResult.IsValid) { foreach (var config in mappedConfigs) { var type = config.Value.GetType(); if (configSetModel.Get(type).IsReadOnly) { continue; } var instance = await configRepository.GetAsync(type, identity); instance.SetConfiguration(config.Value); await configRepository.UpdateConfigAsync(instance); await eventService.Publish(new ConfigurationUpdatedEvent(instance)); } responseFactory.BuildNoContentResponse(context); } else { responseFactory.BuildStatusResponse(context, 422); } }
public async Task CanSaveAndRetriveCollectionAsync() { var configId = new ConfigurationIdentity("3E37AC18-A00F-47A5-B84E-C79E0823F6D4"); const int testValue = 23; const int testValue2 = 24; var values = new[] { new SimpleConfig { IntProperty = testValue }, new SimpleConfig { IntProperty = testValue2 } }; var config = new ConfigCollectionInstance <SimpleConfig>(values, configId.ClientId); await target.UpdateConfigAsync(config); var result = await target.GetCollectionAsync <SimpleConfig>(configId); Assert.Equal(2, result.Count()); Assert.True(result.Any(a => a.IntProperty == testValue)); Assert.True(result.Any(a => a.IntProperty == testValue2)); }
public async Task CanSaveAndRetriveCollectionWithTypeAsync() { var configId = new ConfigurationIdentity(new ConfigurationClient("3E37AC18-A00F-47A5-B84E-C79E0823F6D4"), new Version(1, 0)); const int testValue = 23; const int testValue2 = 24; var values = new[] { new SimpleConfig { IntProperty = testValue }, new SimpleConfig { IntProperty = testValue2 } }; var config = new ConfigCollectionInstance <SimpleConfig>(values, configId); await target.UpdateConfigAsync(config); var result = (IEnumerable <SimpleConfig>)(await target.GetCollectionAsync(typeof(SimpleConfig), configId)); Assert.Equal(2, result.Count()); Assert.Contains(result, a => a.IntProperty == testValue); Assert.Contains(result, a => a.IntProperty == testValue2); }
public IOptionSet Build(IOptionPropertyDefinition definition, ConfigurationIdentity configIdentity, IEnumerable <ConfigurationSet> configurationSets) { if (definition is ConfigurationPropertyWithOptionModelDefinition optionModelDefinition) { return(Build(optionModelDefinition, configurationSets)); } throw new InvalidOperationException($"Could not build option set for definition type of {definition.GetType()}"); }
public Task <IEnumerable <ResourceEntryInfo> > GetArchiveResourceCatalogue(ConfigurationIdentity identity) { string path = GetArchiveResourceSetFolder(identity).FullName; var result = Directory.EnumerateFiles(path) .Select(MapEntryInfo); return(Task.FromResult(result)); }
public async Task <ConfigInstance> GetAsync(Type type, ConfigurationIdentity id) { var model = registry.GetConfigDefinition(type); var configInstance = await configProvider.GetAsync(type, id); UpdateOptions(configInstance.GetConfiguration(), model.ConfigurationProperties); return(configInstance); }
private async Task <ConfigurationIdentity> GetIdentityFromPathOrDefault(string pathParam) { var client = await configClientService.GetClientOrDefault(pathParam); var clientIdentity = new ConfigurationIdentity(client, registry.GetVersion()); return(clientIdentity); }
public IOptionSet Build(ReadOnlyConfigurationOptionModel model, ConfigurationIdentity configIdentity) { var optionProvider = model.OptionProviderType != null ? serviceProvider.GetService(model.OptionProviderType) : null; return(model.BuildOptionSet(configIdentity, optionProvider)); }
public Task <ConfigurationSet> GetConfigurationSet(Type type, ConfigurationIdentity identity) { var key = GetKey(type, identity); return(memoryCache.GetOrCreateAsync(cachePrefix + key, e => { e.SetSlidingExpiration(TimeSpan.FromMinutes(5)); return GetConfigurationSetFromSource(type, identity); })); }
public Task <ConfigurationSnapshotEntry> GetSnapshot(string snapshotId, ConfigurationIdentity targetConfigurationIdentity) { var entry = source.SingleOrDefault(s => string.Equals(snapshotId, s.Key.Id)); var result = new ConfigurationSnapshotEntry { Info = entry.Key, Configurations = entry.Value }; return(Task.FromResult(result)); }
public async Task CopyResources(ConfigurationIdentity sourceIdentity, ConfigurationIdentity destinationIdentity) { var containerRef = client.GetContainerReference(container); foreach (var blob in (await GetResources(containerRef, sourceIdentity))) { await CopyResource(containerRef, blob, destinationIdentity); } }
public Task DeleteArchiveResource(string name, ConfigurationIdentity identity) { var path = GetArchiveResourceSetFolder(identity); var fileToDelete = Path.Combine(path.FullName, name); var existingFile = new FileInfo(fileToDelete); existingFile.Delete(); return(Task.FromResult(true)); }
public ConfigurationServiceTests() { var registry = new ConfigurationModelRegistry(); registry.AddConfigurationSet(new SampleConfigSet().BuildConfigurationSetModel()); configurationSetService = new Mock <IConfigurationSetService>(); identity = new ConfigurationIdentity(new ConfigurationClient(clientId), new Version(1, 0)); target = new ConfigurationService(configurationSetService.Object, registry); }
public object MapUploadToEditModel(string json, ConfigurationIdentity identity, ConfigurationModel model) { var uploadedInstance = uploadMapper.MapToConfigInstance(json, identity, model); if (uploadedInstance.GetConfiguration() == null) { uploadedInstance.SetConfiguration(uploadedInstance.ConstructNewConfiguration()); } return(configurationEditModelMapper.MapToEditConfig(uploadedInstance, model)); }
private async Task SetFileAsync(ConfigurationIdentity identity, string name, Stream value) { var containerRef = client.GetContainerReference(container); var location = GetResourcePath(identity, name); var entry = containerRef.GetBlockBlobReference(location); await ArchiveIfExists(containerRef, entry, identity, name); await entry.UploadFromStreamAsync(value); }
public async Task CopyResources(IEnumerable <string> filesToCopy, ConfigurationIdentity sourceIdentity, ConfigurationIdentity destinationIdentity) { var files = new HashSet <string>(filesToCopy); var containerRef = client.GetContainerReference(container); foreach (var blob in (await GetResources(containerRef, sourceIdentity)).Where(s => files.Contains(TrimFolderPath(s.Name)))) { await CopyResource(containerRef, blob, destinationIdentity); } }
public UploadToEditorModelMapperTests() { configurationEditModelMapper = new Mock <IConfigurationEditModelMapper>(); uploadMapper = new Mock <IConfigurationUploadMapper>(); target = new UploadToEditorModelMapper(configurationEditModelMapper.Object, uploadMapper.Object); inputedId = new ConfigurationIdentity(new ConfigurationClient { ClientId = Guid.NewGuid().ToString() }, new Version(1, 0)); model = new ConfigurationModel <SimpleConfig, SimpleConfigSet>("Test", c => c.Config, (cs, c) => cs.Config = c); }
private ConfigurationModelPayload Map(ConfigurationModel model, ConfigurationIdentity configIdentity, IEnumerable <ConfigurationSet> requiredConfigurationSets) { return(new ConfigurationModelPayload { Name = model.ConfigurationDisplayName, Description = model.ConfigurationDescription, IsOption = model is ConfigurationOptionModel, Property = BuildProperties(model.ConfigurationProperties, configIdentity, requiredConfigurationSets) }); }
public async Task DeleteOldArchiveConfigs(DateTime deletionDate, ConfigurationIdentity identity) { foreach (var entry in await GetArchivedConfigs(identity)) { if (entry.Properties.LastModified.HasValue && entry.Properties.LastModified.Value <= deletionDate) { await entry.DeleteIfExistsAsync(); } } }