Partial implementation of SecretService
This commit is contained in:
@@ -29,6 +29,7 @@ class Program
|
|||||||
var services = new ServiceCollection();
|
var services = new ServiceCollection();
|
||||||
services.AddSingleton<IPasswordStoreService, PasswordStoreService>();
|
services.AddSingleton<IPasswordStoreService, PasswordStoreService>();
|
||||||
services.AddSingleton<IRepository, JsonRepository>();
|
services.AddSingleton<IRepository, JsonRepository>();
|
||||||
|
services.AddSingleton<ISecretService, SecretService>();
|
||||||
return services.BuildServiceProvider();
|
return services.BuildServiceProvider();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
7
src/Logic/ISecretService.cs
Normal file
7
src/Logic/ISecretService.cs
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
namespace Logic;
|
||||||
|
|
||||||
|
public interface ISecretService
|
||||||
|
{
|
||||||
|
public List<Secret.Collection> GetCollections();
|
||||||
|
public void CreateCollection(string label);
|
||||||
|
}
|
||||||
@@ -11,4 +11,8 @@
|
|||||||
<ProjectReference Include="../Repository/Repository.csproj" />
|
<ProjectReference Include="../Repository/Repository.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="GirCore.Secret-1" Version="0.7.0-preview.2" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -6,14 +6,17 @@ namespace Logic;
|
|||||||
public class PasswordStoreService : IPasswordStoreService
|
public class PasswordStoreService : IPasswordStoreService
|
||||||
{
|
{
|
||||||
private readonly IRepository repository;
|
private readonly IRepository repository;
|
||||||
|
private readonly ISecretService secretService;
|
||||||
|
|
||||||
public PasswordStoreService(IRepository repository)
|
public PasswordStoreService(IRepository repository, ISecretService secretService)
|
||||||
{
|
{
|
||||||
this.repository = repository;
|
this.repository = repository;
|
||||||
|
this.secretService = secretService;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Create(PasswordStore item)
|
public void Create(PasswordStore item)
|
||||||
{
|
{
|
||||||
|
secretService.CreateCollection(item.DisplayName ?? item.Path);
|
||||||
repository.Create(item);
|
repository.Create(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
30
src/Logic/SecretService.cs
Normal file
30
src/Logic/SecretService.cs
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
namespace Logic;
|
||||||
|
|
||||||
|
public class SecretService : ISecretService
|
||||||
|
{
|
||||||
|
Secret.Service service;
|
||||||
|
|
||||||
|
public SecretService()
|
||||||
|
{
|
||||||
|
Secret.Module.Initialize();
|
||||||
|
service = Secret.Service.GetSync(Secret.ServiceFlags.LoadCollections, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Secret.Collection> GetCollections()
|
||||||
|
{
|
||||||
|
GLib.List collections = service.GetCollections() ?? throw new Exception("No collections found");
|
||||||
|
List<Secret.Collection> result = new List<Secret.Collection>();
|
||||||
|
GLib.List.Foreach(collections, data =>
|
||||||
|
{
|
||||||
|
Secret.Collection collection = (Secret.Collection)GObject.Internal.InstanceWrapper.WrapHandle<Secret.Collection>(data, false);
|
||||||
|
result.Add(collection);
|
||||||
|
Console.WriteLine($" - {collection.Label}");
|
||||||
|
});
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void CreateCollection(string label)
|
||||||
|
{
|
||||||
|
Secret.Collection.CreateSync(service, label, null, Secret.CollectionCreateFlags.None, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user