-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* add ability to create and update secret versions. [skip ci] add error message if user does not have rights this closes #64 * chore: cleanup [skip ci]
- Loading branch information
1 parent
87c4f74
commit 4c4c44a
Showing
18 changed files
with
556 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
KeyVaultExplorer/ViewModels/CreateNewSecretVersionViewModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
using Avalonia.Controls; | ||
using Avalonia.Controls.ApplicationLifetimes; | ||
using CommunityToolkit.Mvvm.ComponentModel; | ||
using CommunityToolkit.Mvvm.Input; | ||
using KeyVaultExplorer.Views; | ||
using KeyVaultExplorer.Services; | ||
using System.Threading.Tasks; | ||
using System.Threading; | ||
using System.Linq; | ||
using Azure.Security.KeyVault.Secrets; | ||
using System; | ||
|
||
namespace KeyVaultExplorer.ViewModels; | ||
|
||
public partial class CreateNewSecretVersionViewModel : ViewModelBase | ||
{ | ||
[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 string secretValue; | ||
|
||
[ObservableProperty] | ||
[NotifyPropertyChangedFor(nameof(Location))] | ||
[NotifyPropertyChangedFor(nameof(HasActivationDate))] | ||
[NotifyPropertyChangedFor(nameof(HasExpirationDate))] | ||
private SecretProperties keyVaultSecretModel; | ||
|
||
[ObservableProperty] | ||
private TimeSpan? expiresOnTimespan; | ||
|
||
[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; | ||
|
||
public CreateNewSecretVersionViewModel() | ||
{ | ||
_authService = Defaults.Locator.GetRequiredService<AuthService>(); | ||
_vaultService = Defaults.Locator.GetRequiredService<VaultService>(); | ||
_notificationViewModel = Defaults.Locator.GetRequiredService<NotificationViewModel>(); | ||
} | ||
|
||
[RelayCommand] | ||
public async Task EditDetails() | ||
{ | ||
if (KeyVaultSecretModel.NotBefore.HasValue) | ||
KeyVaultSecretModel.NotBefore = KeyVaultSecretModel.NotBefore.Value.Date + (NotBeforeTimespan.HasValue ? NotBeforeTimespan.Value : TimeSpan.Zero); | ||
|
||
if (KeyVaultSecretModel.ExpiresOn.HasValue) | ||
KeyVaultSecretModel.ExpiresOn = KeyVaultSecretModel.ExpiresOn.Value.Date + (ExpiresOnTimespan.HasValue ? ExpiresOnTimespan.Value : TimeSpan.Zero); | ||
|
||
var updatedProps = await _vaultService.UpdateSecret(KeyVaultSecretModel, KeyVaultSecretModel.VaultUri); | ||
KeyVaultSecretModel = updatedProps; | ||
} | ||
|
||
[RelayCommand] | ||
public async Task NewVersion() | ||
{ | ||
var newSecret = new KeyVaultSecret(KeyVaultSecretModel.Name, SecretValue); | ||
if (KeyVaultSecretModel.NotBefore.HasValue) | ||
newSecret.Properties.NotBefore = KeyVaultSecretModel.NotBefore.Value.Date + (NotBeforeTimespan.HasValue ? NotBeforeTimespan.Value : TimeSpan.Zero); | ||
|
||
if (KeyVaultSecretModel.ExpiresOn.HasValue) | ||
newSecret.Properties.ExpiresOn = KeyVaultSecretModel.ExpiresOn.Value.Date + (ExpiresOnTimespan.HasValue ? ExpiresOnTimespan.Value : TimeSpan.Zero); | ||
|
||
newSecret.Properties.ContentType = KeyVaultSecretModel.ContentType; | ||
|
||
var newVersion = await _vaultService.CreateSecret(newSecret, KeyVaultSecretModel.VaultUri); | ||
var properties = (await _vaultService.GetSecretProperties(newVersion.Properties.VaultUri, newVersion.Name)).First(); | ||
KeyVaultSecretModel = properties; | ||
} | ||
|
||
partial void OnKeyVaultSecretModelChanging(SecretProperties model) | ||
{ | ||
ExpiresOnTimespan = model is not null && model.ExpiresOn.HasValue ? model?.ExpiresOn.Value.LocalDateTime.TimeOfDay : null; | ||
NotBeforeTimespan = model is not null && model.NotBefore.HasValue ? model?.NotBefore.Value.LocalDateTime.TimeOfDay : null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.