Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
cricketthomas committed Jul 24, 2024
1 parent 8d132b5 commit 7afc9f1
Show file tree
Hide file tree
Showing 26 changed files with 392 additions and 191 deletions.
1 change: 1 addition & 0 deletions .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ on:
pull_request:
branches:
- "*"
workflow_dispatch:

permissions:
contents: write
Expand Down
2 changes: 1 addition & 1 deletion Desktop/Desktop.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@


<ItemGroup>
<PackageReference Include="Avalonia.Desktop" Version="11.1.0-rc2" />
<PackageReference Include="Avalonia.Desktop" Version="11.1.0" />
</ItemGroup>


Expand Down
19 changes: 1 addition & 18 deletions KeyVaultExplorer/App.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,7 @@ public App()
DataContext = new AppViewModel();
}

public static void ConfigureDesktopServices()
{
IServiceCollection serviceCollection = new ServiceCollection();
serviceCollection.AddMemoryCache();
serviceCollection.AddSingleton<AuthService>();
serviceCollection.AddSingleton<VaultService>();
serviceCollection.AddSingleton<TabViewPageViewModel>();
serviceCollection.AddSingleton<ToolBarViewModel>();
serviceCollection.AddSingleton<KeyVaultTreeListViewModel>();
serviceCollection.AddSingleton<SettingsPageViewModel>();
serviceCollection.AddSingleton<MainViewModel>();
serviceCollection.AddSingleton<NotificationViewModel>();
serviceCollection.AddSingleton<KvExplorerDb>();
serviceCollection.AddTransient<AppSettingReader>();
serviceCollection.AddSingleton<IClipboard, ClipboardService>();
serviceCollection.AddSingleton<IStorageProvider, StorageProviderService>();
}


public static void CreateDesktopResources()
{
Directory.CreateDirectory(Constants.LocalAppDataFolder);
Expand Down
Binary file added KeyVaultExplorer/Assets/Certificate.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions KeyVaultExplorer/Assets/Certificate.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added KeyVaultExplorer/Assets/Key.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions KeyVaultExplorer/Assets/Key.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added KeyVaultExplorer/Assets/Lock.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions KeyVaultExplorer/Assets/Lock.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion KeyVaultExplorer/Database/KvExplorerDb.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public KvExplorerDb()

public static async void OpenSqlConnection()
{
string DataSource = Path.Combine(Constants.LocalAppDataFolder, "KeyVaultExplorer.db");
string DataSource = Path.Combine(Constants.DatabaseFilePath);
var pass = await DatabaseEncryptedPasswordManager.GetSecret();
var connection = new SqliteConnection($"Filename={DataSource}; Password={pass}");
connection.Open();
Expand Down
22 changes: 14 additions & 8 deletions KeyVaultExplorer/KeyVaultExplorer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,21 @@

<ItemGroup>
<None Remove="Assets\AppIcon.ico" />
<None Remove="Assets\Certificate.png" />
<None Remove="Assets\Certificate.svg" />
<None Remove="Assets\Close.svg" />
<None Remove="Assets\Cloud.png" />
<None Remove="Assets\Cloud.svg" />
<None Remove="Assets\CollapseAll.svg" />
<None Remove="Assets\folder.png" />
<None Remove="Assets\FolderClosed.svg" />
<None Remove="Assets\ForeignKey.svg" />
<None Remove="Assets\Key.png" />
<None Remove="Assets\Key.svg" />
<None Remove="Assets\KeyVault.svg" />
<None Remove="Assets\kv-gray.png" />
<None Remove="Assets\Lock.png" />
<None Remove="Assets\Lock.svg" />
<None Remove="Assets\Pin.png" />
<None Remove="Assets\Pin.svg" />
<None Remove="Assets\Refresh.svg" />
Expand All @@ -42,17 +48,17 @@


<ItemGroup>
<PackageReference Include="Avalonia.Controls.ItemsRepeater" Version="11.1.0-rc2" />
<PackageReference Include="Avalonia.Svg.Skia" Version="11.1.0-rc1" />
<PackageReference Include="DeviceId" Version="6.6.0" />
<PackageReference Include="Avalonia.Controls.ItemsRepeater" Version="11.1.0" />
<PackageReference Include="Avalonia.Svg.Skia" Version="11.1.0" />
<PackageReference Include="DeviceId" Version="6.7.0" />
<PackageReference Include="FluentAvaloniaUI" Version="2.1.0-preview6" />
<!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.-->
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="11.1.0-rc2" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.0-preview.5.24306.7" />
<PackageReference Include="Microsoft.Data.Sqlite.Core" Version="9.0.0-preview.5.24306.3" />
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="11.1.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.0-preview.6.24327.7" />
<PackageReference Include="Microsoft.Data.Sqlite.Core" Version="9.0.0-preview.6.24327.4" />
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.2" />
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="9.0.0-preview.5.24306.7" />
<PackageReference Include="Microsoft.Identity.Client.Extensions.Msal" Version="4.61.3" />
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="9.0.0-preview.6.24327.7" />
<PackageReference Include="Microsoft.Identity.Client.Extensions.Msal" Version="4.62.0" />
<PackageReference Include="Azure.ResourceManager.KeyVault" Version="1.3.0" />
<PackageReference Include="Azure.Security.KeyVault.Certificates" Version="4.6.0" />
<PackageReference Include="Azure.Security.KeyVault.Keys" Version="4.6.0" />
Expand Down
20 changes: 10 additions & 10 deletions KeyVaultExplorer/Models/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ namespace KeyVaultExplorer.Models;
public static class Constants
{
// database password file name
public const string EncryptedSecretFileName = "keyvaultexplorer_database_password.txt";
public const string KeychainSecretName = "keyvaultexplorer_database_password";
public const string KeychainServiceName = "keyvaultexplorer";
public const string ProtectedKeyFileName = "keyvaultexplorer_database_key.bin";
public const string DeviceFileTokenName = "keyvaultexplorer_database_device-token.txt";
public const string EncryptedSecretFileName = "azurekeyvaultexplorer_database_password.txt";
public const string KeychainSecretName = "azurekeyvaultexplorer_database_password";
public const string KeychainServiceName = "azurekeyvaultexplorer";
public const string ProtectedKeyFileName = "azurekeyvaultexplorer_database_key.bin";
public const string DeviceFileTokenName = "azurekeyvaultexplorer_database_device-token.txt";

//The Application or Client ID will be generated while registering the app in the Azure portal. Copy and paste the GUID.
public static readonly string ClientId = "fdc1e6da-d735-4627-af3e-d40377f55713";
Expand All @@ -29,16 +29,16 @@ public static class Constants
// Cache settings
public const string CacheFileName = "keyvaultexplorer_msal_cache.txt";

public static readonly string LocalAppDataFolder = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\KeyVaultExplorer";
public static readonly string LocalAppDataFolder = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\AzureKeyVaultExplorer";

public static readonly string DatabaseFilePath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\KeyVaultExplorer\\KeyVaultExplorer.db";
public static readonly string DatabaseFilePath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\AzureKeyVaultExplorer\\AzureKeyVaultExplorer.db";

public const string KeyChainServiceName = "keyvaultexplorer_msal_service";
public const string KeyChainAccountName = "keyvaultexplorer_msal_account";
public const string KeyChainServiceName = "azurekeyvaultexplorer_msal_service";
public const string KeyChainAccountName = "azurekeyvaultexplorer_msal_account";

public const string LinuxKeyRingSchema = "us.sidesteplabs.keyvaultexplorer.tokencache";
public const string LinuxKeyRingCollection = MsalCacheHelper.LinuxKeyRingDefaultCollection;
public const string LinuxKeyRingLabel = "MSAL token cache for key vault explorer.";
public const string LinuxKeyRingLabel = "MSAL token cache for azure key vault explorer.";
public static readonly KeyValuePair<string, string> LinuxKeyRingAttr1 = new KeyValuePair<string, string>("Version", "1");
public static readonly KeyValuePair<string, string> LinuxKeyRingAttr2 = new KeyValuePair<string, string>("ProductGroup", "MyApps");
}
1 change: 1 addition & 0 deletions KeyVaultExplorer/Services/ServiceCollectionExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public static void AddCommonServices(this IServiceCollection collection) {
collection.AddSingleton<KeyVaultTreeListViewModel>();
collection.AddSingleton<SettingsPageViewModel>();
collection.AddSingleton<MainViewModel>();
collection.AddSingleton<SubscriptionsPageViewModel>();
collection.AddSingleton<NotificationViewModel>();
collection.AddSingleton<KvExplorerDb>();
collection.AddTransient<AppSettingReader>();
Expand Down
28 changes: 21 additions & 7 deletions KeyVaultExplorer/Services/VaultService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -318,18 +318,32 @@ public async IAsyncEnumerable<KeyVaultResource> GetWithKeyVaultsBySubscriptionAs

public async Task<KeyVaultSecret> CreateSecret(KeyVaultSecret keyVaultSecret, Uri KeyVaultUri)
{
var token = new CustomTokenCredential(await _authService.GetAzureKeyVaultTokenSilent());
SecretClient client = new SecretClient(KeyVaultUri, token);
return await client.SetSecretAsync(keyVaultSecret);

var token = new CustomTokenCredential(await _authService.GetAzureKeyVaultTokenSilent());
SecretClient client = new SecretClient(KeyVaultUri, token);
return await client.SetSecretAsync(keyVaultSecret);
}

public async Task<SecretProperties> UpdateSecret(SecretProperties secretProperties, Uri KeyVaultUri)
public async Task<SecretProperties> UpdateSecret(SecretProperties properties, Uri KeyVaultUri)
{
var token = new CustomTokenCredential(await _authService.GetAzureKeyVaultTokenSilent());
SecretClient client = new SecretClient(KeyVaultUri, token);
return await client.UpdateSecretPropertiesAsync(properties);
}

SecretClient client = new SecretClient(KeyVaultUri, token);

return await client.UpdateSecretPropertiesAsync(secretProperties);

public async Task<KeyVaultKey> CreateKey(KeyVaultKey key, Uri KeyVaultUri)
{
var token = new CustomTokenCredential(await _authService.GetAzureKeyVaultTokenSilent());
var client = new KeyClient(KeyVaultUri, token);
return await client.CreateKeyAsync(key.Name, key.KeyType);
}

public async Task<KeyVaultKey> UpdateKey(KeyProperties properties, Uri KeyVaultUri)
{
var token = new CustomTokenCredential(await _authService.GetAzureKeyVaultTokenSilent());
var client = new KeyClient(KeyVaultUri, token);
return await client.UpdateKeyPropertiesAsync(properties);
}

}
51 changes: 41 additions & 10 deletions KeyVaultExplorer/ViewModels/CreateNewSecretVersionViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,49 +9,80 @@
using System.Linq;
using Azure.Security.KeyVault.Secrets;
using System;
using System.Collections.Generic;
using KeyVaultExplorer.Models;
using System.Collections.ObjectModel;
using Avalonia.Threading;

namespace KeyVaultExplorer.ViewModels;

public partial class CreateNewSecretVersionViewModel : ViewModelBase
{
[ObservableProperty]
public List<KvResourceGroupModel> resourceGroupItems;

private readonly AuthService _authService;

private readonly VaultService _vaultService;

private NotificationViewModel _notificationViewModel;

private SubscriptionsPageViewModel _subscriptionsPageViewModel;

[ObservableProperty]
private TimeSpan? expiresOnTimespan;

[ObservableProperty]
private bool isBusy = false;

[ObservableProperty]
private bool isEdit = false;

public bool HasActivationDate => KeyVaultSecretModel is not null && KeyVaultSecretModel.NotBefore.HasValue;
public bool HasExpirationDate => KeyVaultSecretModel is not null && KeyVaultSecretModel.ExpiresOn.HasValue;
[ObservableProperty]
private bool isNew = false;


[ObservableProperty]
private string secretValue;
private ObservableCollection<SubscriptionDataItem> subscriptions;

[ObservableProperty]
[NotifyPropertyChangedFor(nameof(Location))]
[NotifyPropertyChangedFor(nameof(HasActivationDate))]
[NotifyPropertyChangedFor(nameof(HasExpirationDate))]
private SecretProperties keyVaultSecretModel;


[ObservableProperty]
private TimeSpan? expiresOnTimespan;

private ObservableCollection<string> testItems;


[ObservableProperty]
private TimeSpan? notBeforeTimespan;

public string? Location => KeyVaultSecretModel?.VaultUri.ToString();
public string? Identifier => KeyVaultSecretModel?.Id.ToString();

private readonly AuthService _authService;
private readonly VaultService _vaultService;
private NotificationViewModel _notificationViewModel;
[ObservableProperty]
private string secretValue;

public CreateNewSecretVersionViewModel()
{
_authService = Defaults.Locator.GetRequiredService<AuthService>();
_vaultService = Defaults.Locator.GetRequiredService<VaultService>();
_notificationViewModel = Defaults.Locator.GetRequiredService<NotificationViewModel>();
_subscriptionsPageViewModel = Defaults.Locator.GetRequiredService<SubscriptionsPageViewModel>();
if (Subscriptions is null || Subscriptions.Count == 0)
{
Dispatcher.UIThread.InvokeAsync(async() => await _subscriptionsPageViewModel.GetSubscriptions(), DispatcherPriority.MaxValue);
Subscriptions = _subscriptionsPageViewModel.Subscriptions;
}
}

public bool HasActivationDate => KeyVaultSecretModel is not null && KeyVaultSecretModel.NotBefore.HasValue;
public bool HasExpirationDate => KeyVaultSecretModel is not null && KeyVaultSecretModel.ExpiresOn.HasValue;
public string? Identifier => KeyVaultSecretModel?.Id?.ToString();
public string? Location => KeyVaultSecretModel?.VaultUri.ToString();



[RelayCommand]
public async Task EditDetails()
{
Expand Down
Loading

0 comments on commit 7afc9f1

Please sign in to comment.