Skip to content

Commit

Permalink
#66 wip adding key regeneration
Browse files Browse the repository at this point in the history
  • Loading branch information
cricketthomas committed Jul 13, 2024
1 parent 8c64fa8 commit 6ed13c1
Show file tree
Hide file tree
Showing 5 changed files with 122 additions and 16 deletions.
21 changes: 19 additions & 2 deletions KeyVaultExplorer/Services/VaultService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -323,10 +323,27 @@ public async Task<KeyVaultSecret> CreateSecret(KeyVaultSecret keyVaultSecret, Ur
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(secretProperties);
return await client.UpdateSecretPropertiesAsync(properties);
}



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.
}

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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ public async Task NewVersion()
if (KeyVaultKeyModel.ExpiresOn.HasValue)
newSecret.Properties.ExpiresOn = KeyVaultKeyModel.ExpiresOn.Value.Date + (ExpiresOnTimespan.HasValue ? ExpiresOnTimespan.Value : TimeSpan.Zero);

newSecret.Properties.ContentType = KeyVaultKeyModel.;

var newVersion = await _vaultService.CreateSecret(newSecret, KeyVaultKeyModel.VaultUri);
var properties = (await _vaultService.GetSecretProperties(newVersion.Properties.VaultUri, newVersion.Name)).First();
Expand Down
72 changes: 59 additions & 13 deletions KeyVaultExplorer/ViewModels/PropertiesPageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -190,23 +190,69 @@ private async Task NewVersion()
IsPrimaryButtonEnabled = true,
CloseButtonText = "Cancel",
};
var currentItem = SecretPropertiesList.OrderByDescending(x => x.CreatedOn).First();
var newVersion = new SecretProperties(currentItem.Id)

if (IsSecret)
{
Enabled = true,
};

var viewModel = new CreateNewSecretVersionViewModel();
viewModel.KeyVaultSecretModel = newVersion;
var currentItem = SecretPropertiesList.OrderByDescending(x => x.CreatedOn).First();
var newVersion = new SecretProperties(currentItem.Id)
{
Enabled = true,
};
var viewModel = new CreateNewSecretVersionViewModel();
viewModel.KeyVaultSecretModel = newVersion;

dialog.PrimaryButtonClick += async (sender, args) =>
dialog.PrimaryButtonClick += async (sender, args) =>
{
var def = args.GetDeferral();
await viewModel.NewVersionCommand.ExecuteAsync(null);
def.Complete();
};

dialog.Content = new CreateNewSecretVersion() { DataContext = viewModel };
}

if (IsKey)
{
var def = args.GetDeferral();
await viewModel.NewVersionCommand.ExecuteAsync(null);
def.Complete();
};
var currentItem = KeyPropertiesList.OrderByDescending(x => x.CreatedOn).First();
var newVersion = new KeyProperties(currentItem.Id)
{
Enabled = true,
};
var viewModel = new CreateNewKeyVersionViewModel();
viewModel.KeyVaultKeyModel = newVersion;

dialog.PrimaryButtonClick += async (sender, args) =>
{
var def = args.GetDeferral();
await viewModel.NewVersionCommand.ExecuteAsync(null);
def.Complete();
};

dialog.Content = new CreateNewSecretVersion() { DataContext = viewModel };
}



if (IsCertificate)
{
var currentItem = KeyPropertiesList.OrderByDescending(x => x.CreatedOn).First();
var newVersion = new KeyProperties(currentItem.Id)
{
Enabled = true,
};
var viewModel = new CreateNewKeyVersionViewModel();
viewModel.KeyVaultKeyModel = newVersion;

dialog.PrimaryButtonClick += async (sender, args) =>
{
var def = args.GetDeferral();
await viewModel.NewVersionCommand.ExecuteAsync(null);
def.Complete();
};

dialog.Content = new CreateNewSecretVersion() { DataContext = viewModel };
}

dialog.Content = new CreateNewSecretVersion() { DataContext = viewModel };

var result = await dialog.ShowAsync();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<UserControl
x:Class="KeyVaultExplorer.CreateNewKeyVersion"
xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:vm="clr-namespace:KeyVaultExplorer.ViewModels"
d:DesignHeight="450"
d:DesignWidth="800"
x:DataType="vm:CreateNewKeyVersionViewModel"
mc:Ignorable="d">
Welcome to Avalonia!
</UserControl>
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Input;
using Avalonia.Markup.Xaml;
using Avalonia.Threading;


using KeyVaultExplorer.ViewModels;

namespace KeyVaultExplorer;

public partial class CreateNewKeyVersion : UserControl
{
public CreateNewKeyVersion()
{
InitializeComponent();
DataContext = new CreateNewKeyVersionViewModel();
}

private void InputField_OnAttachedToVisualTree(object sender, VisualTreeAttachmentEventArgs e)
{
// We will set the focus into our input field just after it got attached to the visual tree.
if (sender is InputElement inputElement)
{
Dispatcher.UIThread.InvokeAsync(() =>
{
inputElement.Focus(NavigationMethod.Unspecified, KeyModifiers.None);
});
}
}
}

0 comments on commit 6ed13c1

Please sign in to comment.