private SchemaValidation.Provider CreateSchemaProvider(ITweek tweek, IRulesRepository rulesProvider, SchemaValidation.Mode mode) { var logger = loggerFactory.CreateLogger("SchemaValidation.Provider"); SchemaValidation.Provider CreateValidationProvider() { logger.LogInformation("updateing schema"); var schemaIdenetities = tweek.Calculate(new[] { new ConfigurationPath($"@tweek/schema/_") }, EmptyIdentitySet, i => ContextHelpers.EmptyContext).ToDictionary(x => x.Key.Name, x => x.Value.Value); var customTypes = tweek.Calculate(new[] { new ConfigurationPath($"@tweek/custom_types/_") }, EmptyIdentitySet, i => ContextHelpers.EmptyContext).ToDictionary(x => x.Key.Name, x => CustomTypeDefinition.FromJsonValue(x.Value.Value)); return(SchemaValidation.Create(schemaIdenetities, customTypes, mode)); } var validationProvider = CreateValidationProvider(); rulesProvider.OnRulesChange += (_) => { validationProvider = CreateValidationProvider(); }; return((p) => validationProvider(p)); }
public KeysController(ITweek tweek, IContextDriver contextDriver, CheckReadConfigurationAccess checkAccess) { _tweek = tweek; _checkAccess = checkAccess; _contextDriver = contextDriver; }
public QueryHealthCheck(ITweek tweek, IContextDriver contextDriver) { _tweek = tweek; _contextDriver = contextDriver; }
public static CheckWriteContextAccess CreateWriteContextAccessChecker(ITweek tweek, TweekIdentityProvider identityProvider) { return((identity, tweekIdentity) => CheckAuthenticationForKey(tweek, "write_context", identity, tweekIdentity.ToAuthIdentity(identityProvider))); }
public static CheckReadConfigurationAccess CreateReadConfigurationAccessChecker(ITweek tweek, TweekIdentityProvider identityProvider) { return((identity, path, tweekIdentities) => { if (path == "@tweek/_" || path.StartsWith("@tweek/auth")) { return false; } return tweekIdentities .Select(x => x.ToAuthIdentity(identityProvider)) .Distinct() .DefaultIfEmpty(Identity.GlobalIdentity) .All(tweekIdentity => CheckAuthenticationForKey(tweek, "read_configuration", identity, tweekIdentity)); }); }
public static Dictionary <ConfigurationPath, ConfigurationValue> Calculate(this ITweek tweek, ConfigurationPath pathQuery, HashSet <Identity> identities, GetLoadedContextByIdentityType context, ConfigurationPath[] includeFixedPaths = null) { return(tweek.Calculate(new[] { pathQuery }, identities, context, includeFixedPaths)); }
public static async Task <Dictionary <ConfigurationPath, ConfigurationValue> > GetContextAndCalculate(this ITweek tweek, ICollection <ConfigurationPath> pathQuery, HashSet <Identity> identities, IContextReader contextDriver, GetLoadedContextByIdentityType externalContext = null) { var allContextData = (await Task.WhenAll(identities .Select(async identity => new { Identity = identity, Context = new Dictionary <string, JsonValue>(await contextDriver.GetContext(identity), StringComparer.OrdinalIgnoreCase) }))) .ToDictionary(x => x.Identity, x => x.Context); externalContext = externalContext ?? ContextHelpers.EmptyContextByIdentityType; var loadedContexts = ContextHelpers.GetContextRetrieverByType(ContextHelpers.LoadContexts(allContextData), identities); var context = ContextHelpers.AddSystemContext(ContextHelpers.Fallback(externalContext, loadedContexts)); var contextPaths = pathQuery.Any(x => x.IsScan) ? allContextData.Values.SelectMany(x => x.Keys) .Where(x => x.Contains("@fixed:")) .Select(x => x.Split(':')[1]) .Select(ConfigurationPath.New).ToArray() : null; return(tweek.Calculate(pathQuery, identities, context, contextPaths)); }
public static Task <Dictionary <ConfigurationPath, ConfigurationValue> > GetContextAndCalculate(this ITweek tweek, ConfigurationPath pathQuery, HashSet <Identity> identities, IContextReader contextDriver, GetLoadedContextByIdentityType externalContext = null) { return(tweek.GetContextAndCalculate(new[] { pathQuery }, identities, contextDriver, externalContext)); }