Skip to content

Commit a8c942b

Browse files
authored
Change settings types based on architect feedback (Azure#34859)
* Change settings types based on architect feedback Also updates the CHANGELOG dates. * Resolve PR feedback * Resolve architect feedback
1 parent faa41f8 commit a8c942b

File tree

17 files changed

+240
-166
lines changed

17 files changed

+240
-166
lines changed

sdk/keyvault/Azure.Security.KeyVault.Administration/CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
# Release History
22

3-
## 4.3.0 (2023-03-07)
3+
## 4.3.0 (2023-03-14)
44

55
### Breaking Changes
66

7+
The following changes are only breaking from the previous beta. They are not breaking since version 4.4.0 when those types and members did not exist.
8+
79
- Service version "7.4-preview.1" is not supported.
10+
- Removed `KeyVaultSetting.AsBoolean` and `AsString`, and added `AsBoolean` to new `KeyVaultSetting.Value` property type, `KeyVaultSettingValue`.
811

912
### Other Changes
1013

sdk/keyvault/Azure.Security.KeyVault.Administration/api/Azure.Security.KeyVault.Administration.netstandard2.0.cs

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ public static partial class KeyVaultAdministrationModelFactory
6363
public static Azure.Security.KeyVault.Administration.KeyVaultRoleDefinition KeyVaultRoleDefinition(string id = null, string name = null, Azure.Security.KeyVault.Administration.KeyVaultRoleDefinitionType? type = default(Azure.Security.KeyVault.Administration.KeyVaultRoleDefinitionType?), string roleName = null, string description = null, Azure.Security.KeyVault.Administration.KeyVaultRoleType? roleType = default(Azure.Security.KeyVault.Administration.KeyVaultRoleType?), System.Collections.Generic.IEnumerable<Azure.Security.KeyVault.Administration.KeyVaultPermission> permissions = null, System.Collections.Generic.IEnumerable<Azure.Security.KeyVault.Administration.KeyVaultRoleScope> assignableScopes = null) { throw null; }
6464
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
6565
public static Azure.Security.KeyVault.Administration.KeyVaultRoleDefinition KeyVaultRoleDefinition(string id, string name, Azure.Security.KeyVault.Administration.KeyVaultRoleDefinitionType? type, string roleName, string description, Azure.Security.KeyVault.Administration.KeyVaultRoleType? roleType, System.Collections.Generic.IList<Azure.Security.KeyVault.Administration.KeyVaultPermission> permissions, System.Collections.Generic.IList<Azure.Security.KeyVault.Administration.KeyVaultRoleScope> assignableScopes) { throw null; }
66+
public static Azure.Security.KeyVault.Administration.KeyVaultSetting KeyVaultSetting(string name = null, string content = null, Azure.Security.KeyVault.Administration.KeyVaultSettingType? settingType = default(Azure.Security.KeyVault.Administration.KeyVaultSettingType?)) { throw null; }
6667
public static Azure.Security.KeyVault.Administration.KeyVaultRestoreOperation RestoreOperation(Azure.Response response, Azure.Security.KeyVault.Administration.KeyVaultBackupClient client, string id, System.DateTimeOffset? startTime = default(System.DateTimeOffset?), System.DateTimeOffset? endTime = default(System.DateTimeOffset?), string errorMessage = null) { throw null; }
6768
public static Azure.Security.KeyVault.Administration.KeyVaultRestoreResult RestoreResult(System.DateTimeOffset startTime, System.DateTimeOffset endTime) { throw null; }
6869
public static Azure.Security.KeyVault.Administration.KeyVaultRoleAssignment RoleAssignment(string id, string name, string type, Azure.Security.KeyVault.Administration.KeyVaultRoleAssignmentProperties properties) { throw null; }
@@ -292,9 +293,8 @@ public partial class KeyVaultSetting
292293
{
293294
public KeyVaultSetting(string name, bool value) { }
294295
public string Name { get { throw null; } }
295-
public Azure.Security.KeyVault.Administration.SettingType? Type { get { throw null; } }
296-
public bool AsBoolean() { throw null; }
297-
public string AsString() { throw null; }
296+
public Azure.Security.KeyVault.Administration.KeyVaultSettingType? SettingType { get { throw null; } }
297+
public Azure.Security.KeyVault.Administration.KeyVaultSettingValue Value { get { throw null; } }
298298
public override string ToString() { throw null; }
299299
}
300300
public partial class KeyVaultSettingsClient
@@ -311,20 +311,28 @@ public KeyVaultSettingsClient(System.Uri vaultUri, Azure.Core.TokenCredential cr
311311
public virtual System.Threading.Tasks.Task<Azure.Response<Azure.Security.KeyVault.Administration.KeyVaultSetting>> UpdateSettingAsync(Azure.Security.KeyVault.Administration.KeyVaultSetting setting, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
312312
}
313313
[System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)]
314-
public readonly partial struct SettingType : System.IEquatable<Azure.Security.KeyVault.Administration.SettingType>
314+
public readonly partial struct KeyVaultSettingType : System.IEquatable<Azure.Security.KeyVault.Administration.KeyVaultSettingType>
315315
{
316316
private readonly object _dummy;
317317
private readonly int _dummyPrimitive;
318-
public SettingType(string value) { throw null; }
319-
public static Azure.Security.KeyVault.Administration.SettingType Boolean { get { throw null; } }
320-
public bool Equals(Azure.Security.KeyVault.Administration.SettingType other) { throw null; }
318+
public KeyVaultSettingType(string value) { throw null; }
319+
public static Azure.Security.KeyVault.Administration.KeyVaultSettingType Boolean { get { throw null; } }
320+
public bool Equals(Azure.Security.KeyVault.Administration.KeyVaultSettingType other) { throw null; }
321321
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
322322
public override bool Equals(object obj) { throw null; }
323323
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
324324
public override int GetHashCode() { throw null; }
325-
public static bool operator ==(Azure.Security.KeyVault.Administration.SettingType left, Azure.Security.KeyVault.Administration.SettingType right) { throw null; }
326-
public static implicit operator Azure.Security.KeyVault.Administration.SettingType (string value) { throw null; }
327-
public static bool operator !=(Azure.Security.KeyVault.Administration.SettingType left, Azure.Security.KeyVault.Administration.SettingType right) { throw null; }
325+
public static bool operator ==(Azure.Security.KeyVault.Administration.KeyVaultSettingType left, Azure.Security.KeyVault.Administration.KeyVaultSettingType right) { throw null; }
326+
public static implicit operator Azure.Security.KeyVault.Administration.KeyVaultSettingType (string value) { throw null; }
327+
public static bool operator !=(Azure.Security.KeyVault.Administration.KeyVaultSettingType left, Azure.Security.KeyVault.Administration.KeyVaultSettingType right) { throw null; }
328+
public override string ToString() { throw null; }
329+
}
330+
[System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)]
331+
public readonly partial struct KeyVaultSettingValue
332+
{
333+
private readonly object _dummy;
334+
private readonly int _dummyPrimitive;
335+
public bool AsBoolean() { throw null; }
328336
public override string ToString() { throw null; }
329337
}
330338
}

sdk/keyvault/Azure.Security.KeyVault.Administration/src/Generated/KeyVaultAdministrationModelFactory.cs

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sdk/keyvault/Azure.Security.KeyVault.Administration/src/Generated/Models/KeyVaultSetting.Serialization.cs

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sdk/keyvault/Azure.Security.KeyVault.Administration/src/Generated/Models/KeyVaultSetting.cs

Lines changed: 0 additions & 25 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sdk/keyvault/Azure.Security.KeyVault.Administration/src/Generated/Models/KeyVaultSettingType.cs

Lines changed: 48 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sdk/keyvault/Azure.Security.KeyVault.Administration/src/Generated/Models/SettingType.cs

Lines changed: 0 additions & 48 deletions
This file was deleted.

sdk/keyvault/Azure.Security.KeyVault.Administration/src/KeyVaultSetting.cs

Lines changed: 30 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,14 @@
66

77
namespace Azure.Security.KeyVault.Administration
88
{
9+
/// <summary>
10+
/// An account setting.
11+
/// </summary>
912
[CodeGenModel("Setting")]
13+
[CodeGenSuppress(nameof(KeyVaultSetting), typeof(string), typeof(string))]
14+
#pragma warning disable CA1825 // Avoid zero-length array allocations
15+
[CodeGenSuppress("Content")]
16+
#pragma warning restore CA1825 // Avoid zero-length array allocations
1017
public partial class KeyVaultSetting
1118
{
1219
/// <summary>
@@ -21,59 +28,40 @@ public KeyVaultSetting(string name, bool value)
2128
Argument.AssertNotNullOrEmpty(name, nameof(name));
2229

2330
Name = name;
24-
Type = SettingType.Boolean;
25-
26-
// bool.ToString() returns "True" or "False", but the service wants "true" or "false".
27-
Value = value ? "true" : "false";
31+
Value = new KeyVaultSettingValue(value);
2832
}
2933

30-
// TODO: Consider using Azure.Value and making this class mutable: https://github.com/Azure/azure-sdk-for-net/issues/32174
34+
// TODO: Move construction to KeyVaultSettingValue and hide constructors here when the number of supported value types warrants it e.g., more than 3 intrinsic types.
3135

3236
/// <summary>
33-
/// Gets the boolean value of this account setting if <see cref="Type"/> is <see cref="SettingType.Boolean"/>.
37+
/// Creates a new instance of the <see cref="KeyVaultSetting"/> class.
3438
/// </summary>
35-
/// <returns>A boolean value if <see cref="Type"/> is <see cref="SettingType.Boolean"/>.</returns>
36-
/// <exception cref="InvalidOperationException">The <see cref="Type"/> is not <see cref="SettingType.Boolean"/>, or the value cannot be normalized as a Boolean.</exception>
37-
public bool AsBoolean() => CheckType(SettingType.Boolean, () => (bool.TryParse(Value, out bool parsedValue), parsedValue));
39+
/// <param name="name">The name of the account setting.</param>
40+
/// <param name="value">The string value of the account setting.</param>
41+
/// <param name="settingType">The type specifier of the value.</param>
42+
internal KeyVaultSetting(string name, string value, KeyVaultSettingType? settingType)
43+
{
44+
Argument.AssertNotNull(name, nameof(name));
45+
Argument.AssertNotNull(value, nameof(value));
46+
47+
Name = name;
48+
Value = new KeyVaultSettingValue(value, settingType);
49+
}
3850

3951
/// <summary>
40-
/// Gets the string value of this account setting. Use <see cref="Type"/> to determine if a more appropriate method like <see cref="AsBoolean"/> should be used instead.
52+
/// Gets the type specifier of the value.
4153
/// </summary>
42-
/// <returns>The string value of this account setting.</returns>
43-
public string AsString() => Value;
54+
public KeyVaultSettingType? SettingType => Value.SettingType;
4455

4556
/// <summary>
46-
/// Gets the raw string value of this account setting.
57+
/// Gets the value of the account setting.
4758
/// </summary>
48-
/// <returns></returns>
49-
public override string ToString()
50-
{
51-
string method = nameof(AsString);
52-
if (Type == SettingType.Boolean)
53-
{
54-
method = nameof(AsBoolean);
55-
}
56-
57-
return $"{Name}: {method}()=>{Value}";
58-
}
59-
60-
[CodeGenMember("Value")]
61-
internal string Value { get; }
62-
63-
private T CheckType<T>(SettingType expectedType, Func<(bool IsValid, T ParsedValue)> converter)
64-
{
65-
if (Type != expectedType)
66-
{
67-
throw new InvalidOperationException($"Cannot get setting as {SettingType.Boolean}. Setting type is {Type}.");
68-
}
69-
70-
(bool isValid, T parsedValue) = converter();
71-
if (isValid)
72-
{
73-
return parsedValue;
74-
}
59+
public KeyVaultSettingValue Value { get; }
7560

76-
throw new InvalidOperationException($"Cannot normalize the setting as {expectedType}. Use {nameof(AsString)}() for a textual representation of the setting.");
77-
}
61+
/// <summary>
62+
/// Returns the setting name, value, and type.
63+
/// </summary>
64+
/// <returns></returns>
65+
public override string ToString() => $"{Name}={Value} ({SettingType ?? string.Empty})";
7866
}
7967
}

sdk/keyvault/Azure.Security.KeyVault.Administration/src/SettingType.cs renamed to sdk/keyvault/Azure.Security.KeyVault.Administration/src/KeyVaultSettingType.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
namespace Azure.Security.KeyVault.Administration
77
{
88
[CodeGenModel("SettingTypeEnum")]
9-
public readonly partial struct SettingType
9+
public readonly partial struct KeyVaultSettingType
1010
{
1111
}
1212
}

0 commit comments

Comments
 (0)