• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

me-viper / OpaDotNet.Extensions / 6945658615

21 Nov 2023 03:01PM UTC coverage: 86.565% (+0.1%) from 86.431%
6945658615

push

github

me-viper
feat: Close #4. Support precompiled bundles

92 of 120 branches covered (0.0%)

Branch coverage included in aggregate %.

78 of 92 new or added lines in 3 files covered. (84.78%)

533 of 602 relevant lines covered (88.54%)

4489.43 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

93.75
/src/OpaDotNet.Extensions.AspNetCore/CompiledBundlePolicySource.cs
1
using Microsoft.Extensions.FileProviders;
2
using Microsoft.Extensions.FileProviders.Physical;
3
using Microsoft.Extensions.Options;
4
using Microsoft.Extensions.Primitives;
5

6
using OpaDotNet.Compilation.Abstractions;
7

8
namespace OpaDotNet.Extensions.AspNetCore;
9

10
public sealed class CompiledBundlePolicySource : PathPolicySource
11
{
12
    public CompiledBundlePolicySource(
13
        IRegoCompiler compiler,
14
        IOptions<OpaAuthorizationOptions> options,
15
        IOpaImportsAbiFactory importsAbiFactory,
16
        ILoggerFactory loggerFactory) : base(compiler, options, importsAbiFactory, loggerFactory)
8✔
17
    {
8✔
18
        var path = Options.Value.PolicyBundlePath!;
8✔
19

20
        if (!Path.IsPathRooted(Options.Value.PolicyBundlePath!))
8✔
21
            path = Path.GetFullPath(Options.Value.PolicyBundlePath!);
8✔
22

23
        if (!File.Exists(path))
8!
NEW
24
            throw new FileNotFoundException("Policy bundle file was not found", path);
×
25

26
        var fileProvider = new PhysicalFileProvider(
8✔
27
            Path.GetDirectoryName(path)!,
8✔
28
            ExclusionFilters.Sensitive
8✔
29
            );
8✔
30

31
        var file = Path.GetFileName(path);
8✔
32

33
        if (MonitoringEnabled)
8✔
34
        {
4✔
35
            CompositeChangeToken MakePolicyChangeToken() => new( new[] { fileProvider.Watch(file), } );
19✔
36

37
            void OnPolicyChange()
38
            {
15✔
39
                Logger.LogDebug("Detected changes in policy");
15✔
40
                NeedsRecompilation = true;
15✔
41
            }
15✔
42

43
            PolicyWatcher = ChangeToken.OnChange(MakePolicyChangeToken, OnPolicyChange);
4✔
44
        }
4✔
45
    }
8✔
46

47
    protected override Task<Stream?> CompileBundleFromSource(bool recompiling, CancellationToken cancellationToken = default)
48
    {
20✔
49
        var stream = new FileStream(Options.Value.PolicyBundlePath!, FileMode.Open);
20✔
50
        return Task.FromResult<Stream?>(stream);
20✔
51
    }
20✔
52
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc