Skip to content

Commit

Permalink
Change settings types based on architect feedback (#34859)
Browse files Browse the repository at this point in the history
* Change settings types based on architect feedback

Also updates the CHANGELOG dates.

* Resolve PR feedback

* Resolve architect feedback
  • Loading branch information
heaths authored Mar 14, 2023
1 parent faa41f8 commit a8c942b
Show file tree
Hide file tree
Showing 17 changed files with 240 additions and 166 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
# Release History

## 4.3.0 (2023-03-07)
## 4.3.0 (2023-03-14)

### Breaking Changes

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.

- Service version "7.4-preview.1" is not supported.
- Removed `KeyVaultSetting.AsBoolean` and `AsString`, and added `AsBoolean` to new `KeyVaultSetting.Value` property type, `KeyVaultSettingValue`.

### Other Changes

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public static partial class KeyVaultAdministrationModelFactory
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; }
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
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; }
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; }
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; }
public static Azure.Security.KeyVault.Administration.KeyVaultRestoreResult RestoreResult(System.DateTimeOffset startTime, System.DateTimeOffset endTime) { throw null; }
public static Azure.Security.KeyVault.Administration.KeyVaultRoleAssignment RoleAssignment(string id, string name, string type, Azure.Security.KeyVault.Administration.KeyVaultRoleAssignmentProperties properties) { throw null; }
Expand Down Expand Up @@ -292,9 +293,8 @@ public partial class KeyVaultSetting
{
public KeyVaultSetting(string name, bool value) { }
public string Name { get { throw null; } }
public Azure.Security.KeyVault.Administration.SettingType? Type { get { throw null; } }
public bool AsBoolean() { throw null; }
public string AsString() { throw null; }
public Azure.Security.KeyVault.Administration.KeyVaultSettingType? SettingType { get { throw null; } }
public Azure.Security.KeyVault.Administration.KeyVaultSettingValue Value { get { throw null; } }
public override string ToString() { throw null; }
}
public partial class KeyVaultSettingsClient
Expand All @@ -311,20 +311,28 @@ public KeyVaultSettingsClient(System.Uri vaultUri, Azure.Core.TokenCredential cr
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; }
}
[System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)]
public readonly partial struct SettingType : System.IEquatable<Azure.Security.KeyVault.Administration.SettingType>
public readonly partial struct KeyVaultSettingType : System.IEquatable<Azure.Security.KeyVault.Administration.KeyVaultSettingType>
{
private readonly object _dummy;
private readonly int _dummyPrimitive;
public SettingType(string value) { throw null; }
public static Azure.Security.KeyVault.Administration.SettingType Boolean { get { throw null; } }
public bool Equals(Azure.Security.KeyVault.Administration.SettingType other) { throw null; }
public KeyVaultSettingType(string value) { throw null; }
public static Azure.Security.KeyVault.Administration.KeyVaultSettingType Boolean { get { throw null; } }
public bool Equals(Azure.Security.KeyVault.Administration.KeyVaultSettingType other) { throw null; }
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
public override bool Equals(object obj) { throw null; }
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
public override int GetHashCode() { throw null; }
public static bool operator ==(Azure.Security.KeyVault.Administration.SettingType left, Azure.Security.KeyVault.Administration.SettingType right) { throw null; }
public static implicit operator Azure.Security.KeyVault.Administration.SettingType (string value) { throw null; }
public static bool operator !=(Azure.Security.KeyVault.Administration.SettingType left, Azure.Security.KeyVault.Administration.SettingType right) { throw null; }
public static bool operator ==(Azure.Security.KeyVault.Administration.KeyVaultSettingType left, Azure.Security.KeyVault.Administration.KeyVaultSettingType right) { throw null; }
public static implicit operator Azure.Security.KeyVault.Administration.KeyVaultSettingType (string value) { throw null; }
public static bool operator !=(Azure.Security.KeyVault.Administration.KeyVaultSettingType left, Azure.Security.KeyVault.Administration.KeyVaultSettingType right) { throw null; }
public override string ToString() { throw null; }
}
[System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)]
public readonly partial struct KeyVaultSettingValue
{
private readonly object _dummy;
private readonly int _dummyPrimitive;
public bool AsBoolean() { throw null; }
public override string ToString() { throw null; }
}
}

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

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

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

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

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,14 @@

namespace Azure.Security.KeyVault.Administration
{
/// <summary>
/// An account setting.
/// </summary>
[CodeGenModel("Setting")]
[CodeGenSuppress(nameof(KeyVaultSetting), typeof(string), typeof(string))]
#pragma warning disable CA1825 // Avoid zero-length array allocations
[CodeGenSuppress("Content")]
#pragma warning restore CA1825 // Avoid zero-length array allocations
public partial class KeyVaultSetting
{
/// <summary>
Expand All @@ -21,59 +28,40 @@ public KeyVaultSetting(string name, bool value)
Argument.AssertNotNullOrEmpty(name, nameof(name));

Name = name;
Type = SettingType.Boolean;

// bool.ToString() returns "True" or "False", but the service wants "true" or "false".
Value = value ? "true" : "false";
Value = new KeyVaultSettingValue(value);
}

// TODO: Consider using Azure.Value and making this class mutable: https://github.com/Azure/azure-sdk-for-net/issues/32174
// 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.

/// <summary>
/// Gets the boolean value of this account setting if <see cref="Type"/> is <see cref="SettingType.Boolean"/>.
/// Creates a new instance of the <see cref="KeyVaultSetting"/> class.
/// </summary>
/// <returns>A boolean value if <see cref="Type"/> is <see cref="SettingType.Boolean"/>.</returns>
/// <exception cref="InvalidOperationException">The <see cref="Type"/> is not <see cref="SettingType.Boolean"/>, or the value cannot be normalized as a Boolean.</exception>
public bool AsBoolean() => CheckType(SettingType.Boolean, () => (bool.TryParse(Value, out bool parsedValue), parsedValue));
/// <param name="name">The name of the account setting.</param>
/// <param name="value">The string value of the account setting.</param>
/// <param name="settingType">The type specifier of the value.</param>
internal KeyVaultSetting(string name, string value, KeyVaultSettingType? settingType)
{
Argument.AssertNotNull(name, nameof(name));
Argument.AssertNotNull(value, nameof(value));

Name = name;
Value = new KeyVaultSettingValue(value, settingType);
}

/// <summary>
/// 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.
/// Gets the type specifier of the value.
/// </summary>
/// <returns>The string value of this account setting.</returns>
public string AsString() => Value;
public KeyVaultSettingType? SettingType => Value.SettingType;

/// <summary>
/// Gets the raw string value of this account setting.
/// Gets the value of the account setting.
/// </summary>
/// <returns></returns>
public override string ToString()
{
string method = nameof(AsString);
if (Type == SettingType.Boolean)
{
method = nameof(AsBoolean);
}

return $"{Name}: {method}()=>{Value}";
}

[CodeGenMember("Value")]
internal string Value { get; }

private T CheckType<T>(SettingType expectedType, Func<(bool IsValid, T ParsedValue)> converter)
{
if (Type != expectedType)
{
throw new InvalidOperationException($"Cannot get setting as {SettingType.Boolean}. Setting type is {Type}.");
}

(bool isValid, T parsedValue) = converter();
if (isValid)
{
return parsedValue;
}
public KeyVaultSettingValue Value { get; }

throw new InvalidOperationException($"Cannot normalize the setting as {expectedType}. Use {nameof(AsString)}() for a textual representation of the setting.");
}
/// <summary>
/// Returns the setting name, value, and type.
/// </summary>
/// <returns></returns>
public override string ToString() => $"{Name}={Value} ({SettingType ?? string.Empty})";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
namespace Azure.Security.KeyVault.Administration
{
[CodeGenModel("SettingTypeEnum")]
public readonly partial struct SettingType
public readonly partial struct KeyVaultSettingType
{
}
}
Loading

0 comments on commit a8c942b

Please sign in to comment.