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

me-viper / OpaDotNet / 13672275573

05 Mar 2025 09:05AM UTC coverage: 82.091%. Remained the same
13672275573

push

github

me-viper
chore: Update dependencies

2056 of 2662 branches covered (77.24%)

Branch coverage included in aggregate %.

3999 of 4714 relevant lines covered (84.83%)

8033.0 hits per line

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

94.12
/src/Extensions.AspNetCore/src/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.Extensions.AspNetCore.Telemetry;
7

8
namespace OpaDotNet.Extensions.AspNetCore;
9

10
[PublicAPI]
11
public sealed class CompiledBundlePolicySource : PathPolicySource
12
{
13
    private readonly PhysicalFileProvider? _fileProvider;
14

15
    public CompiledBundlePolicySource(
16
        IOptionsMonitor<OpaAuthorizationOptions> options,
17
        IMutableOpaEvaluatorFactory evaluatorFactory,
18
        ILoggerFactory loggerFactory) : base(options, evaluatorFactory, loggerFactory)
3✔
19
    {
20
        var path = Options.PolicyBundlePath!;
3✔
21

22
        if (!Path.IsPathRooted(Options.PolicyBundlePath!))
3✔
23
            path = Path.GetFullPath(Options.PolicyBundlePath!);
3✔
24

25
        if (!File.Exists(path))
3!
26
            throw new FileNotFoundException("Policy bundle file was not found", path);
×
27

28
        if (MonitoringEnabled)
3✔
29
        {
30
            _fileProvider = new PhysicalFileProvider(
1✔
31
                Path.GetDirectoryName(path)!,
1✔
32
                ExclusionFilters.Sensitive
1✔
33
                );
1✔
34

35
            var file = Path.GetFileName(path);
1✔
36

37
            CompositeChangeToken MakePolicyChangeToken() => new([_fileProvider.Watch(file)]);
4✔
38

39
            void OnPolicyChange()
40
            {
41
                Logger.BundleCompilationHasChanges();
3✔
42
                NeedsRecompilation = true;
3✔
43
            }
3✔
44

45
            PolicyWatcher = ChangeToken.OnChange(MakePolicyChangeToken, OnPolicyChange);
1✔
46
        }
47
    }
3✔
48

49
    protected override void Dispose(bool disposing)
50
    {
51
        if (disposing)
3✔
52
            _fileProvider?.Dispose();
3✔
53

54
        base.Dispose(disposing);
3✔
55
    }
3✔
56

57
    protected override Task<Stream?> CompileBundleFromSource(bool recompiling, CancellationToken cancellationToken = default)
58
    {
59
        var stream = new FileStream(Options.PolicyBundlePath!, FileMode.Open, FileAccess.Read);
6✔
60
        return Task.FromResult<Stream?>(stream);
6✔
61
    }
62
}
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