public async Task <ActionResult> DeleteGet(string ns, string name) { if (string.IsNullOrEmpty(name)) { name = "(default)"; } if (!ModuleIdentifier.TryParse(ns, out var module)) { logger.LogDebug("invalid module"); return(BadRequest()); } logger.LogDebug($"Delete {ns}:{name}"); var found = await context.ModuleInstances.FirstOrDefaultAsync( m => m.Module == ns.ToLower() && m.Name == name.ToLower() ); if (found == null) { return(NotFound($"No such module: {ns}/{name}")); } context.Remove(found); await context.SaveChangesAsync(); return(Ok()); }
public IList <ModuleIdentifier> GetAvailableModules() { var dir = optionsMonitor.CurrentValue.Source; if (!Directory.Exists(dir)) { logger.LogError("Config catalog directory not found: " + dir); throw new ApplicationException("Config catalog directory not found"); } var list = new List <ModuleIdentifier>(); foreach (var file in Directory.GetFiles(dir)) { if (Path.GetExtension(file).ToLower() != ".json") { continue; } var name = Path.GetFileNameWithoutExtension(file); if (ModuleIdentifier.TryParse(name, out var identifier)) { list.Add(identifier); } } foreach (var file in Directory.GetDirectories(dir)) { var name = Path.GetFileName(file); if (ModuleIdentifier.TryParse(name, out var identifier)) { list.Add(identifier); } } return(list); }
public async Task <ActionResult <ConfigCatalog> > GetCompatibleCatalog(string ns) { if (!ModuleIdentifier.TryParse(ns, out var module)) { logger.LogDebug("invalid module"); return(BadRequest()); } await moduleCatalogManager.LoadModuleCatalogCache(); var catalog = moduleCatalogManager.GetCompatibleCatalog(module); if (catalog == null) { return(NotFound()); } return(catalog); }
public async Task <ActionResult> CreateGet(string ns, string name, string ver) { if (string.IsNullOrEmpty(name)) { name = "(default)"; } if (!ModuleIdentifier.TryParse(ns, out var module)) { logger.LogDebug("invalid module"); return(BadRequest()); } await moduleCatalogManager.LoadModuleCatalogCache(); if (!moduleCatalogManager.HasCompatibleCatalog(module)) { return(NotFound("No such module catalog.")); } var exist = await context.ModuleInstances .AnyAsync(m => m.Module == ns.ToLower() && m.Name == name.ToLower()); if (exist) { return(Conflict($"Already exists: {ns}/{name}")); } logger.LogDebug($"Create for {ns}:{name}"); await context.ModuleInstances.AddAsync(new ModuleInstance { Module = ns.ToLower(), Name = name.ToLower(), }); await context.SaveChangesAsync(); return(Ok()); }