Skip to content

Commit

Permalink
Add Resolve Variables option on Publish
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxhy committed Mar 11, 2024
1 parent 362f266 commit b7c43b5
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 19 deletions.
9 changes: 9 additions & 0 deletions KeyManager.Library.UI/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions KeyManager.Library.UI/Properties/Resources.fr.resx
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,9 @@
<data name="ResolveKeyLinks" xml:space="preserve">
<value>Résoudre la liaison des clés</value>
</data>
<data name="ResolveVariables" xml:space="preserve">
<value>Résoudre les variables</value>
</data>
<data name="Salt" xml:space="preserve">
<value>Sel</value>
</data>
Expand Down
3 changes: 3 additions & 0 deletions KeyManager.Library.UI/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,9 @@
<data name="ResolveKeyLinks" xml:space="preserve">
<value>Resolve Key links</value>
</data>
<data name="ResolveVariables" xml:space="preserve">
<value>Resolve Variables</value>
</data>
<data name="Salt" xml:space="preserve">
<value>Salt</value>
</data>
Expand Down
7 changes: 6 additions & 1 deletion KeyManager.Library.UI/PublishKeyStoreDialog.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,18 @@
<ToggleButton IsChecked="{Binding Options.ResolveKeyLinks}" Style="{StaticResource MaterialDesignSwitchLightToggleButton}" />
<TextBlock Text="{x:Static properties:Resources.ResolveKeyLinks}" Padding="3" />
</StackPanel>
<StackPanel Orientation="Horizontal" VerticalAlignment="Center" Margin="5">
<ToggleButton IsChecked="{Binding Options.ResolveVariables}" Style="{StaticResource MaterialDesignSwitchLightToggleButton}" />
<TextBlock Text="{x:Static properties:Resources.ResolveVariables}" Padding="3" />
</StackPanel>
<StackPanel Orientation="Horizontal" VerticalAlignment="Center" Margin="5">
<ToggleButton IsChecked="{Binding Options.DryRun}" Style="{StaticResource MaterialDesignSwitchLightToggleButton}" />
<TextBlock Text="{x:Static properties:Resources.DryRun}" Padding="3" />
</StackPanel>
<TextBox Text="{Binding Options.PublishVariable, UpdateSourceTrigger=PropertyChanged}" Margin="5,5,5,15"
materialDesign:HintAssist.HelperText="{x:Static properties:Resources.PublishVariableHelper}"
materialDesign:HintAssist.Hint="{x:Static properties:Resources.PublishVariable}"/>
materialDesign:HintAssist.Hint="{x:Static properties:Resources.PublishVariable}"
Visibility="{Binding Options.ResolveVariables, Converter={StaticResource BooleanToVisibilityConverter}}"/>
<Expander HorizontalAlignment="Stretch" Header="{x:Static properties:Resources.WrappingKey}" Margin="5">
<StackPanel Orientation="Vertical" TextBlock.Foreground="{DynamicResource MaterialDesignBody}" Margin="24,8,24,16">
<local:KeyEntryIdControl KeyEntryId="{Binding Options.WrappingKey.KeyId, Mode=TwoWay}" />
Expand Down
52 changes: 34 additions & 18 deletions KeyManager.Library/KeyStore/KeyStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -272,10 +272,12 @@ public virtual async Task Publish(KeyStore store, Func<string, KeyStore?> getFav
var entry = await Get(id, keClass);
if (entry != null)
{
entry.Identifier = entry.Identifier.Clone(Attributes);
var resolveKeyLinks = (Options?.ResolveKeyLinks).GetValueOrDefault(true);
var resolveVariables = (Options?.ResolveVariables).GetValueOrDefault(true);
entry.Identifier = entry.Identifier.Clone(resolveVariables ? Attributes : null);
if (entry.Link != null && entry.Link.KeyIdentifier.IsConfigured() && !string.IsNullOrEmpty(entry.Link.KeyStoreFavorite))
{
if ((Options?.ResolveKeyLinks).GetValueOrDefault(true))
if (resolveKeyLinks)
{
var cryptogram = new KeyEntryCryptogram
{
Expand All @@ -294,7 +296,7 @@ public virtual async Task Publish(KeyStore store, Func<string, KeyStore?> getFav
KeyStore = ks,
KeyEntry = entry
};
cryptogram.Value = await ks.ResolveKeyEntryLink(entry.Link.KeyIdentifier.Clone(Attributes), keClass, ComputeDivInput(divContext, entry.Link.DivInput), entry.Link.WrappingKey);
cryptogram.Value = await ks.ResolveKeyEntryLink(entry.Link.KeyIdentifier.Clone(resolveVariables ? Attributes : null), keClass, ComputeDivInput(divContext, entry.Link.DivInput), entry.Link.WrappingKey);
}
finally
{
Expand All @@ -305,38 +307,52 @@ public virtual async Task Publish(KeyStore store, Func<string, KeyStore?> getFav
}
else
{
if (resolveVariables)
{
entry.Link.KeyIdentifier = entry.Link.KeyIdentifier.Clone(Attributes);
}
changes.Add(entry);
}
}
else
{
if ((Options?.ResolveKeyLinks).GetValueOrDefault(true) && entry.Variant != null)
if (entry.Variant != null)
{
foreach (var kv in entry.Variant.KeyContainers)
{
if (kv.Key.Link != null && kv.Key.Link.KeyIdentifier.IsConfigured() && !string.IsNullOrEmpty(kv.Key.Link.KeyStoreFavorite))
{
var ks = getFavoriteKeyStore(kv.Key.Link.KeyStoreFavorite);
if (ks != null)
if (resolveKeyLinks)
{
await ks.Open();
try
var ks = getFavoriteKeyStore(kv.Key.Link.KeyStoreFavorite);
if (ks != null)
{
var divContext = new DivInput.DivInputContext
await ks.Open();
try
{
var divContext = new DivInput.DivInputContext
{
KeyStore = ks,
KeyEntry = entry,
KeyContainer = kv
};
kv.Key.SetAggregatedValueAsString(await ks.ResolveKeyLink(kv.Key.Link.KeyIdentifier.Clone(resolveVariables ? Attributes : null), keClass, kv.Key.Link.ContainerSelector, ComputeDivInput(divContext, kv.Key.Link.DivInput)));
}
finally
{
KeyStore = ks,
KeyEntry = entry,
KeyContainer = kv
};
kv.Key.SetAggregatedValueAsString(await ks.ResolveKeyLink(kv.Key.Link.KeyIdentifier.Clone(Attributes), keClass, kv.Key.Link.ContainerSelector, ComputeDivInput(divContext, kv.Key.Link.DivInput)));
await ks.Close();
}
}
finally
// We remove link information from the being pushed key entry
kv.Key.Link = new KeyLink();
}
else
{
if (resolveVariables)
{
await ks.Close();
kv.Key.Link.KeyIdentifier = kv.Key.Link.KeyIdentifier.Clone(Attributes);
}
}
// We remove link information from the being pushed key entry
kv.Key.Link = new KeyLink();
}
}
}
Expand Down
8 changes: 8 additions & 0 deletions KeyManager.Library/KeyStore/StoreOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public StoreOptions()
{
_wrappingKey = new WrappingKey();
_resolveKeyLinks = true;
_resolveVariables = true;
}

private WrappingKey _wrappingKey;
Expand All @@ -31,6 +32,13 @@ public bool ResolveKeyLinks
set => SetProperty(ref _resolveKeyLinks, value);
}

private bool _resolveVariables;
public bool ResolveVariables
{
get => _resolveVariables;
set => SetProperty(ref _resolveVariables, value);
}

private bool _dryRun;
public bool DryRun
{
Expand Down

0 comments on commit b7c43b5

Please sign in to comment.