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

loresoft / EntityFrameworkCore.Generator / 9036122521

10 May 2024 05:55PM UTC coverage: 57.012% (+2.3%) from 54.745%
9036122521

push

github

pwelter34
update packages

563 of 1111 branches covered (50.68%)

Branch coverage included in aggregate %.

1811 of 3053 relevant lines covered (59.32%)

83.77 hits per line

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

0.0
/src/EntityFrameworkCore.Generator.Core/SecretsStore.cs
1
using System;
2
using System.Collections.Generic;
3
using System.IO;
4
using System.Linq;
5
using System.Text.Json;
6

7
using Microsoft.Extensions.Configuration;
8
using Microsoft.Extensions.Configuration.UserSecrets;
9

10
namespace EntityFrameworkCore.Generator;
11

12
public class SecretsStore
13
{
14
    private readonly string _secretsFilePath;
15
    private readonly IDictionary<string, string> _secrets;
16

17
    public SecretsStore(string userSecretsId)
×
18
    {
19
        if (string.IsNullOrEmpty(userSecretsId))
×
20
            throw new ArgumentException("Value cannot be null or empty.", nameof(userSecretsId));
×
21

22
        _secretsFilePath = PathHelper.GetSecretsPathFromSecretsId(userSecretsId);
×
23

24
        // workaround bug in configuration
25
        var secretDir = Path.GetDirectoryName(_secretsFilePath);
×
26
        Directory.CreateDirectory(secretDir);
×
27

28
        _secrets = Load(userSecretsId);
×
29
    }
×
30

31
    public string this[string key] => _secrets[key];
×
32

33
    public int Count => _secrets.Count;
×
34

35
    public bool ContainsKey(string key) => _secrets.ContainsKey(key);
×
36

37
    public IEnumerable<KeyValuePair<string, string>> AsEnumerable() => _secrets;
×
38

39
    public void Clear() => _secrets.Clear();
×
40

41
    public void Set(string key, string value) => _secrets[key] = value;
×
42

43
    public void Remove(string key)
44
    {
45
        if (_secrets.ContainsKey(key))
×
46
        {
47
            _secrets.Remove(key);
×
48
        }
49
    }
×
50

51
    public virtual void Save()
52
    {
53
        var secretDir = Path.GetDirectoryName(_secretsFilePath);
×
54
        Directory.CreateDirectory(secretDir);
×
55

56
        var options = new JsonWriterOptions
×
57
        {
×
58
            Indented = true
×
59
        };
×
60

61
        using var stream = File.Create(_secretsFilePath);
×
62
        using var writer = new Utf8JsonWriter(stream, options);
×
63

64
        writer.WriteStartObject();
×
65

66
        foreach (var secret in _secrets.AsEnumerable())
×
67
            writer.WriteString(secret.Key, secret.Value);
×
68

69
        writer.WriteEndObject();
×
70
        writer.Flush();
×
71
    }
×
72

73
    protected virtual IDictionary<string, string> Load(string userSecretsId)
74
    {
75
        return new ConfigurationBuilder()
×
76
            .AddJsonFile(_secretsFilePath, optional: true)
×
77
            .Build()
×
78
            .AsEnumerable()
×
79
            .Where(i => i.Value != null)
×
80
            .ToDictionary(i => i.Key, i => i.Value, StringComparer.OrdinalIgnoreCase);
×
81
    }
82
}
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

© 2025 Coveralls, Inc