diff --git a/sdk/cloudmachine/Azure.CloudMachine/api/Azure.CloudMachine.net8.0.cs b/sdk/cloudmachine/Azure.CloudMachine/api/Azure.CloudMachine.net8.0.cs index 1e6b182bb3f11..a53334d90ff63 100644 --- a/sdk/cloudmachine/Azure.CloudMachine/api/Azure.CloudMachine.net8.0.cs +++ b/sdk/cloudmachine/Azure.CloudMachine/api/Azure.CloudMachine.net8.0.cs @@ -1,51 +1,16 @@ -namespace Azure -{ - public partial class RestCallFailedException : System.Exception - { - public RestCallFailedException(string message, System.ClientModel.Primitives.PipelineResponse response) { } - } - public partial class RestClient - { - public RestClient() { } - public RestClient(System.ClientModel.Primitives.PipelinePolicy auth) { } - public static Azure.RestClient Shared { get { throw null; } } - public System.ClientModel.Primitives.PipelineMessage Create(string method, System.Uri uri) { throw null; } - public System.ClientModel.Primitives.PipelineResponse Get(string uri, System.ClientModel.Primitives.RequestOptions options = null) { throw null; } - public System.ClientModel.Primitives.PipelineResponse Patch(string uri, System.ClientModel.BinaryContent content, System.ClientModel.Primitives.RequestOptions options = null) { throw null; } - public System.ClientModel.Primitives.PipelineResponse Post(string uri, System.ClientModel.BinaryContent content, System.ClientModel.Primitives.RequestOptions options = null) { throw null; } - public System.ClientModel.Primitives.PipelineResponse Put(string uri, System.ClientModel.BinaryContent content, System.ClientModel.Primitives.RequestOptions options = null) { throw null; } - public System.ClientModel.Primitives.PipelineResponse Send(System.ClientModel.Primitives.PipelineMessage message, System.ClientModel.Primitives.RequestOptions options = null) { throw null; } - } - public partial class RestClientOptions : System.ClientModel.Primitives.ClientPipelineOptions - { - public RestClientOptions() { } - } -} -namespace Azure.AI.OpenAI -{ - public partial class TokenCredentialAuthenticationPolicy : System.ClientModel.Primitives.PipelinePolicy - { - public TokenCredentialAuthenticationPolicy(Azure.Core.TokenCredential credential, System.Collections.Generic.IEnumerable scopes, System.TimeSpan? refreshOffset = default(System.TimeSpan?)) { } - public override void Process(System.ClientModel.Primitives.PipelineMessage message, System.Collections.Generic.IReadOnlyList pipeline, int currentIndex) { } - public override System.Threading.Tasks.ValueTask ProcessAsync(System.ClientModel.Primitives.PipelineMessage message, System.Collections.Generic.IReadOnlyList pipeline, int currentIndex) { throw null; } - } -} namespace Azure.CloudMachine { - public partial class CloudMachineClient : Azure.CloudMachine.CloudMachineWorkspace - { - protected CloudMachineClient() : base (default(Azure.Core.TokenCredential), default(Microsoft.Extensions.Configuration.IConfiguration), default(System.Collections.Generic.IEnumerable)) { } - public CloudMachineClient(Azure.Core.TokenCredential credential = null, Microsoft.Extensions.Configuration.IConfiguration configuration = null, System.Collections.Generic.IEnumerable connections = null) : base (default(Azure.Core.TokenCredential), default(Microsoft.Extensions.Configuration.IConfiguration), default(System.Collections.Generic.IEnumerable)) { } - public Azure.CloudMachine.MessagingServices Messaging { get { throw null; } } - public Azure.CloudMachine.StorageServices Storage { get { throw null; } } - } - public partial class CloudMachineWorkspace : Azure.Core.ClientWorkspace + public partial class CloudMachineClient : Azure.Core.ClientWorkspace { - public CloudMachineWorkspace(Azure.Core.TokenCredential credential = null, Microsoft.Extensions.Configuration.IConfiguration configuration = null, System.Collections.Generic.IEnumerable connections = null) : base (default(Azure.Core.TokenCredential)) { } + protected CloudMachineClient() : base (default(Azure.Core.TokenCredential)) { } + public CloudMachineClient(Azure.Core.ConnectionCollection connections = null, Azure.Core.TokenCredential credential = null) : base (default(Azure.Core.TokenCredential)) { } + public CloudMachineClient(Microsoft.Extensions.Configuration.IConfiguration configuration, Azure.Core.TokenCredential credential = null) : base (default(Azure.Core.TokenCredential)) { } [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] - public Azure.CloudMachine.ConnectionCollection Connections { get { throw null; } } + public Azure.Core.ConnectionCollection Connections { get { throw null; } } [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] public string Id { get { throw null; } } + public Azure.CloudMachine.MessagingServices Messaging { get { throw null; } } + public Azure.CloudMachine.StorageServices Storage { get { throw null; } } [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] public override bool Equals(object obj) { throw null; } [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] @@ -57,11 +22,6 @@ public CloudMachineWorkspace(Azure.Core.TokenCredential credential = null, Micro [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] public override string ToString() { throw null; } } - public partial class ConnectionCollection : System.Collections.ObjectModel.KeyedCollection - { - public ConnectionCollection() { } - protected override string GetKeyForItem(Azure.Core.ClientConnection item) { throw null; } - } [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)] public readonly partial struct MessagingServices { @@ -211,4 +171,37 @@ protected ClientWorkspace(Azure.Core.TokenCredential credential) { } public Azure.Core.ClientCache Subclients { get { throw null; } } public abstract Azure.Core.ClientConnection GetConnectionOptions(string connectionId); } + public static partial class CloudMachineClientConfiguration + { + public static Microsoft.Extensions.Configuration.IConfigurationBuilder AddCloudMachineConnections(this Microsoft.Extensions.Configuration.IConfigurationBuilder builder, Azure.Core.ConnectionCollection connections) { throw null; } + public static Microsoft.Extensions.Configuration.IConfigurationBuilder AddCloudMachineId(this Microsoft.Extensions.Configuration.IConfigurationBuilder builder, string id) { throw null; } + } + public partial class ConnectionCollection : System.Collections.ObjectModel.KeyedCollection + { + public ConnectionCollection() { } + protected override string GetKeyForItem(Azure.Core.ClientConnection item) { throw null; } + } +} +namespace Azure.Core.Rest +{ + public partial class RestCallFailedException : System.Exception + { + public RestCallFailedException(string message, System.ClientModel.Primitives.PipelineResponse response) { } + } + public partial class RestClient + { + public RestClient() { } + public RestClient(System.ClientModel.Primitives.PipelinePolicy auth) { } + public static Azure.Core.Rest.RestClient Shared { get { throw null; } } + public System.ClientModel.Primitives.PipelineMessage Create(string method, System.Uri uri) { throw null; } + public System.ClientModel.Primitives.PipelineResponse Get(string uri, System.ClientModel.Primitives.RequestOptions options = null) { throw null; } + public System.ClientModel.Primitives.PipelineResponse Patch(string uri, System.ClientModel.BinaryContent content, System.ClientModel.Primitives.RequestOptions options = null) { throw null; } + public System.ClientModel.Primitives.PipelineResponse Post(string uri, System.ClientModel.BinaryContent content, System.ClientModel.Primitives.RequestOptions options = null) { throw null; } + public System.ClientModel.Primitives.PipelineResponse Put(string uri, System.ClientModel.BinaryContent content, System.ClientModel.Primitives.RequestOptions options = null) { throw null; } + public System.ClientModel.Primitives.PipelineResponse Send(System.ClientModel.Primitives.PipelineMessage message, System.ClientModel.Primitives.RequestOptions options = null) { throw null; } + } + public partial class RestClientOptions : System.ClientModel.Primitives.ClientPipelineOptions + { + public RestClientOptions() { } + } } diff --git a/sdk/cloudmachine/Azure.CloudMachine/api/Azure.CloudMachine.netstandard2.0.cs b/sdk/cloudmachine/Azure.CloudMachine/api/Azure.CloudMachine.netstandard2.0.cs index 1e6b182bb3f11..a53334d90ff63 100644 --- a/sdk/cloudmachine/Azure.CloudMachine/api/Azure.CloudMachine.netstandard2.0.cs +++ b/sdk/cloudmachine/Azure.CloudMachine/api/Azure.CloudMachine.netstandard2.0.cs @@ -1,51 +1,16 @@ -namespace Azure -{ - public partial class RestCallFailedException : System.Exception - { - public RestCallFailedException(string message, System.ClientModel.Primitives.PipelineResponse response) { } - } - public partial class RestClient - { - public RestClient() { } - public RestClient(System.ClientModel.Primitives.PipelinePolicy auth) { } - public static Azure.RestClient Shared { get { throw null; } } - public System.ClientModel.Primitives.PipelineMessage Create(string method, System.Uri uri) { throw null; } - public System.ClientModel.Primitives.PipelineResponse Get(string uri, System.ClientModel.Primitives.RequestOptions options = null) { throw null; } - public System.ClientModel.Primitives.PipelineResponse Patch(string uri, System.ClientModel.BinaryContent content, System.ClientModel.Primitives.RequestOptions options = null) { throw null; } - public System.ClientModel.Primitives.PipelineResponse Post(string uri, System.ClientModel.BinaryContent content, System.ClientModel.Primitives.RequestOptions options = null) { throw null; } - public System.ClientModel.Primitives.PipelineResponse Put(string uri, System.ClientModel.BinaryContent content, System.ClientModel.Primitives.RequestOptions options = null) { throw null; } - public System.ClientModel.Primitives.PipelineResponse Send(System.ClientModel.Primitives.PipelineMessage message, System.ClientModel.Primitives.RequestOptions options = null) { throw null; } - } - public partial class RestClientOptions : System.ClientModel.Primitives.ClientPipelineOptions - { - public RestClientOptions() { } - } -} -namespace Azure.AI.OpenAI -{ - public partial class TokenCredentialAuthenticationPolicy : System.ClientModel.Primitives.PipelinePolicy - { - public TokenCredentialAuthenticationPolicy(Azure.Core.TokenCredential credential, System.Collections.Generic.IEnumerable scopes, System.TimeSpan? refreshOffset = default(System.TimeSpan?)) { } - public override void Process(System.ClientModel.Primitives.PipelineMessage message, System.Collections.Generic.IReadOnlyList pipeline, int currentIndex) { } - public override System.Threading.Tasks.ValueTask ProcessAsync(System.ClientModel.Primitives.PipelineMessage message, System.Collections.Generic.IReadOnlyList pipeline, int currentIndex) { throw null; } - } -} namespace Azure.CloudMachine { - public partial class CloudMachineClient : Azure.CloudMachine.CloudMachineWorkspace - { - protected CloudMachineClient() : base (default(Azure.Core.TokenCredential), default(Microsoft.Extensions.Configuration.IConfiguration), default(System.Collections.Generic.IEnumerable)) { } - public CloudMachineClient(Azure.Core.TokenCredential credential = null, Microsoft.Extensions.Configuration.IConfiguration configuration = null, System.Collections.Generic.IEnumerable connections = null) : base (default(Azure.Core.TokenCredential), default(Microsoft.Extensions.Configuration.IConfiguration), default(System.Collections.Generic.IEnumerable)) { } - public Azure.CloudMachine.MessagingServices Messaging { get { throw null; } } - public Azure.CloudMachine.StorageServices Storage { get { throw null; } } - } - public partial class CloudMachineWorkspace : Azure.Core.ClientWorkspace + public partial class CloudMachineClient : Azure.Core.ClientWorkspace { - public CloudMachineWorkspace(Azure.Core.TokenCredential credential = null, Microsoft.Extensions.Configuration.IConfiguration configuration = null, System.Collections.Generic.IEnumerable connections = null) : base (default(Azure.Core.TokenCredential)) { } + protected CloudMachineClient() : base (default(Azure.Core.TokenCredential)) { } + public CloudMachineClient(Azure.Core.ConnectionCollection connections = null, Azure.Core.TokenCredential credential = null) : base (default(Azure.Core.TokenCredential)) { } + public CloudMachineClient(Microsoft.Extensions.Configuration.IConfiguration configuration, Azure.Core.TokenCredential credential = null) : base (default(Azure.Core.TokenCredential)) { } [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] - public Azure.CloudMachine.ConnectionCollection Connections { get { throw null; } } + public Azure.Core.ConnectionCollection Connections { get { throw null; } } [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] public string Id { get { throw null; } } + public Azure.CloudMachine.MessagingServices Messaging { get { throw null; } } + public Azure.CloudMachine.StorageServices Storage { get { throw null; } } [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] public override bool Equals(object obj) { throw null; } [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] @@ -57,11 +22,6 @@ public CloudMachineWorkspace(Azure.Core.TokenCredential credential = null, Micro [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] public override string ToString() { throw null; } } - public partial class ConnectionCollection : System.Collections.ObjectModel.KeyedCollection - { - public ConnectionCollection() { } - protected override string GetKeyForItem(Azure.Core.ClientConnection item) { throw null; } - } [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)] public readonly partial struct MessagingServices { @@ -211,4 +171,37 @@ protected ClientWorkspace(Azure.Core.TokenCredential credential) { } public Azure.Core.ClientCache Subclients { get { throw null; } } public abstract Azure.Core.ClientConnection GetConnectionOptions(string connectionId); } + public static partial class CloudMachineClientConfiguration + { + public static Microsoft.Extensions.Configuration.IConfigurationBuilder AddCloudMachineConnections(this Microsoft.Extensions.Configuration.IConfigurationBuilder builder, Azure.Core.ConnectionCollection connections) { throw null; } + public static Microsoft.Extensions.Configuration.IConfigurationBuilder AddCloudMachineId(this Microsoft.Extensions.Configuration.IConfigurationBuilder builder, string id) { throw null; } + } + public partial class ConnectionCollection : System.Collections.ObjectModel.KeyedCollection + { + public ConnectionCollection() { } + protected override string GetKeyForItem(Azure.Core.ClientConnection item) { throw null; } + } +} +namespace Azure.Core.Rest +{ + public partial class RestCallFailedException : System.Exception + { + public RestCallFailedException(string message, System.ClientModel.Primitives.PipelineResponse response) { } + } + public partial class RestClient + { + public RestClient() { } + public RestClient(System.ClientModel.Primitives.PipelinePolicy auth) { } + public static Azure.Core.Rest.RestClient Shared { get { throw null; } } + public System.ClientModel.Primitives.PipelineMessage Create(string method, System.Uri uri) { throw null; } + public System.ClientModel.Primitives.PipelineResponse Get(string uri, System.ClientModel.Primitives.RequestOptions options = null) { throw null; } + public System.ClientModel.Primitives.PipelineResponse Patch(string uri, System.ClientModel.BinaryContent content, System.ClientModel.Primitives.RequestOptions options = null) { throw null; } + public System.ClientModel.Primitives.PipelineResponse Post(string uri, System.ClientModel.BinaryContent content, System.ClientModel.Primitives.RequestOptions options = null) { throw null; } + public System.ClientModel.Primitives.PipelineResponse Put(string uri, System.ClientModel.BinaryContent content, System.ClientModel.Primitives.RequestOptions options = null) { throw null; } + public System.ClientModel.Primitives.PipelineResponse Send(System.ClientModel.Primitives.PipelineMessage message, System.ClientModel.Primitives.RequestOptions options = null) { throw null; } + } + public partial class RestClientOptions : System.ClientModel.Primitives.ClientPipelineOptions + { + public RestClientOptions() { } + } } diff --git a/sdk/cloudmachine/Azure.CloudMachine/src/CloudMachineClient.cs b/sdk/cloudmachine/Azure.CloudMachine/src/CloudMachineClient.cs index 2d31947889926..30da8dcdffa5a 100644 --- a/sdk/cloudmachine/Azure.CloudMachine/src/CloudMachineClient.cs +++ b/sdk/cloudmachine/Azure.CloudMachine/src/CloudMachineClient.cs @@ -1,8 +1,10 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -using System.Collections.Generic; +using System; +using System.ComponentModel; using Azure.Core; +using Azure.Identity; using Microsoft.Extensions.Configuration; namespace Azure.CloudMachine; @@ -10,27 +12,79 @@ namespace Azure.CloudMachine; /// /// The cloud machine client. /// -public partial class CloudMachineClient : CloudMachineWorkspace +public partial class CloudMachineClient : ClientWorkspace { + /// + /// The cloud machine ID. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public string Id { get; } + + /// + /// subclient connections. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public ConnectionCollection Connections { get; } = []; + /// /// Initializes a new instance of the class for mocking purposes.. /// - protected CloudMachineClient() + protected CloudMachineClient() : + this(credential: BuildCredential(default)) { + Id = AppConfigHelpers.ReadOrCreateCloudMachineId(); Messaging = new MessagingServices(this); Storage = new StorageServices(this); } + #pragma warning disable AZC0007 // DO provide a minimal constructor that takes only the parameters required to connect to the service. /// /// Initializes a new instance of the class. /// - /// The token credential. /// The configuration settings. + /// The token credential. + public CloudMachineClient(IConfiguration configuration, TokenCredential credential = default) +#pragma warning restore AZC0007 // DO provide a minimal constructor that takes only the parameters required to connect to the service. + : base(BuildCredential(credential)) + { + Id = configuration["CloudMachine:ID"]; + if (Id == null) + { + Id = AppConfigHelpers.ReadOrCreateCloudMachineId(); + } + + IConfigurationSection connectionsSection = configuration.GetSection("CloudMachine:Connections"); + + foreach (IConfigurationSection connection in connectionsSection.GetChildren()) + { + string id = connection["Id"]; + if (id == null) continue; + string locator = connection["Locator"]; + + Connections.Add(new ClientConnection(id, locator, ClientAuthenticationMethod.EntraId)); + } + + Messaging = new MessagingServices(this); + Storage = new StorageServices(this); + } + +#pragma warning disable AZC0007 // DO provide a minimal constructor that takes only the parameters required to connect to the service. + /// + /// Initializes a new instance of the class. + /// /// - public CloudMachineClient(TokenCredential credential = default, IConfiguration configuration = default, IEnumerable connections = default) + /// The token credential. + // TODO: we need to combine the configuration and the connections into a single parameter. + public CloudMachineClient(ConnectionCollection connections = default, TokenCredential credential = default) #pragma warning restore AZC0007 // DO provide a minimal constructor that takes only the parameters required to connect to the service. - : base(credential, configuration, connections) + : base(BuildCredential(credential)) { + if (connections != default) + { + Connections.AddRange(connections); + } + + Id = AppConfigHelpers.ReadOrCreateCloudMachineId(); Messaging = new MessagingServices(this); Storage = new StorageServices(this); } @@ -44,4 +98,50 @@ public CloudMachineClient(TokenCredential credential = default, IConfiguration c /// Gets the storage services. /// public StorageServices Storage { get; } + + /// + /// Retrieves the connection options for a specified client type and instance ID. + /// + /// + /// + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override ClientConnection GetConnectionOptions(string connectionId) + { + return Connections[connectionId]; + } + + private static TokenCredential BuildCredential(TokenCredential credential) + { + if (credential == default) + { + // This environment variable is set by the CloudMachine App Service feature during provisioning. + credential = Environment.GetEnvironmentVariable("CLOUDMACHINE_MANAGED_IDENTITY_CLIENT_ID") switch + { + string clientId when !string.IsNullOrEmpty(clientId) => new ManagedIdentityCredential(clientId), + _ => new ChainedTokenCredential(new AzureCliCredential(), new AzureDeveloperCliCredential()) + }; + } + + return credential; + } + + /// + /// Reads or creates the cloud machine ID. + /// + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public static string ReadOrCreateCloudMachineId() => AppConfigHelpers.ReadOrCreateCloudMachineId(); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool Equals(object obj) => base.Equals(obj); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override int GetHashCode() => base.GetHashCode(); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override string ToString() => Id; } diff --git a/sdk/cloudmachine/Azure.CloudMachine/src/CloudMachineClientConfiguration.cs b/sdk/cloudmachine/Azure.CloudMachine/src/CloudMachineClientConfiguration.cs new file mode 100644 index 0000000000000..7055da3b61708 --- /dev/null +++ b/sdk/cloudmachine/Azure.CloudMachine/src/CloudMachineClientConfiguration.cs @@ -0,0 +1,143 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System.Collections.Generic; +using System; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Primitives; +using System.Linq; + +namespace Azure.Core; + +/// +/// extensions. +/// +public static class CloudMachineClientConfiguration +{ + /// + /// Adds a connection to the collection. + /// + /// + /// + /// + public static IConfigurationBuilder AddCloudMachineConnections(this IConfigurationBuilder builder, ConnectionCollection connections) + { + var source = new ConnectionCollectionConfigurationSource(connections); + builder.Add(source); + return builder; + } + /// + /// Adds a connection to the collection. + /// + /// + /// + /// + public static IConfigurationBuilder AddCloudMachineId(this IConfigurationBuilder builder, string id) + { + var source = new CmidConfigurationSource(id); + builder.Add(source); + return builder; + } +} + +internal class ConnectionCollectionConfigurationProvider : IConfigurationProvider +{ + private readonly ConnectionCollection _connections; + public ConnectionCollectionConfigurationProvider(ConnectionCollection connections) + => _connections = connections; + + public IEnumerable GetChildKeys(IEnumerable earlierKeys, string parentPath) + { + foreach (string earlierKey in earlierKeys) + { + yield return earlierKey; + } + foreach (ClientConnection connection in _connections) + { + yield return connection.Id; + } + } + + public IChangeToken GetReloadToken() => null; + public void Load() { } + public void Set(string key, string value) => throw new NotImplementedException(); + public bool TryGet(string key, out string value) + { + string[] path = key.Split(':'); + + if (path.Length != 4 || + !path[0].Equals("CloudMachine", StringComparison.InvariantCultureIgnoreCase) || + !path[1].Equals("Connections", StringComparison.InvariantCultureIgnoreCase)) + { + value = null; + return false; + } + + if (!_connections.Contains(path[2])) + { + value = null; + return false; + } + + string id = path[2]; + ClientConnection connection = _connections[id]; + var property = path[3].ToLowerInvariant(); + + switch (property) + { + case "id": + value = connection.Id; + return true; + case "locator": + value = connection.Locator; + return true; + case "authentication": + value = connection.Authentication.ToString(); + return true; + default: + value = null; + return false; + } + } +} +internal class ConnectionCollectionConfigurationSource : IConfigurationSource +{ + private readonly ConnectionCollection _connections; + public ConnectionCollectionConfigurationSource(ConnectionCollection connections) + => _connections = connections; + + public IConfigurationProvider Build(IConfigurationBuilder builder) + => new ConnectionCollectionConfigurationProvider(_connections); +} + +internal class CmidConfigurationProvider(string cmid) : IConfigurationProvider +{ + public IEnumerable GetChildKeys(IEnumerable earlierKeys, string parentPath) + { + if (parentPath.Equals("CloudMachine", StringComparison.InvariantCultureIgnoreCase)) + return earlierKeys.Append("ID"); // todo: should this check if ID is not already in earlier keys + else + return earlierKeys; + } + + public IChangeToken GetReloadToken() => null; + public void Load() {} + public void Set(string key, string value) + => new NotSupportedException(); + + public bool TryGet(string key, out string value) + { + if (!key.Equals("CloudMachine:ID", StringComparison.InvariantCultureIgnoreCase)) + { + value = null; + return false; + } + value = cmid; + return true; + } +} +internal class CmidConfigurationSource(string cmid) : IConfigurationSource +{ + public IConfigurationProvider Build(IConfigurationBuilder builder) + => new CmidConfigurationProvider(cmid); +} diff --git a/sdk/cloudmachine/Azure.CloudMachine/src/CloudMachineWorkspace.cs b/sdk/cloudmachine/Azure.CloudMachine/src/CloudMachineWorkspace.cs deleted file mode 100644 index 500365b346fcd..0000000000000 --- a/sdk/cloudmachine/Azure.CloudMachine/src/CloudMachineWorkspace.cs +++ /dev/null @@ -1,104 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -using System; -using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.ComponentModel; -using System.Diagnostics.CodeAnalysis; -using System.IO; -using System.Text.Json; -using System.Text.Json.Nodes; -using Azure.Core; -using Azure.Identity; -using Azure.Messaging.EventGrid.SystemEvents; -using Microsoft.Extensions.Configuration; - -namespace Azure.CloudMachine; - -/// -/// The cloud machine workspace. -/// -public class CloudMachineWorkspace : ClientWorkspace -{ - /// - /// subclient connections. - /// - [EditorBrowsable(EditorBrowsableState.Never)] - public ConnectionCollection Connections { get; } = []; - - /// - /// The cloud machine ID. - /// - [EditorBrowsable(EditorBrowsableState.Never)] - public string Id { get; } - - /// - /// Initializes a new instance of the class. - /// - /// - /// - /// - /// - [SuppressMessage("Usage", "AZC0007:DO provide a minimal constructor that takes only the parameters required to connect to the service.", Justification = "")] - public CloudMachineWorkspace(TokenCredential credential = default, IConfiguration configuration = default, IEnumerable connections = default) - : base(BuildCredentail(credential)) - { - if (connections != default) - { - Connections.AddRange(connections); - } - - Id = configuration switch - { - null => AppConfigHelpers.ReadOrCreateCloudMachineId(), - _ => configuration["CloudMachine:ID"] ?? throw new Exception("CloudMachine:ID configuration value missing") - }; - } - - private static TokenCredential BuildCredentail(TokenCredential credential) - { - if (credential == default) - { - // This environment variable is set by the CloudMachine App Service feature during provisioning. - credential = Environment.GetEnvironmentVariable("CLOUDMACHINE_MANAGED_IDENTITY_CLIENT_ID") switch - { - string clientId when !string.IsNullOrEmpty(clientId) => new ManagedIdentityCredential(clientId), - _ => new ChainedTokenCredential(new AzureCliCredential(), new AzureDeveloperCliCredential()) - }; - } - - return credential; - } - - /// - /// Retrieves the connection options for a specified client type and instance ID. - /// - /// - /// - /// - [EditorBrowsable(EditorBrowsableState.Never)] - public override ClientConnection GetConnectionOptions(string connectionId) - { - return Connections[connectionId]; - } - - /// - /// Reads or creates the cloud machine ID. - /// - /// - [EditorBrowsable(EditorBrowsableState.Never)] - public static string ReadOrCreateCloudMachineId() => AppConfigHelpers.ReadOrCreateCloudMachineId(); - - /// - [EditorBrowsable(EditorBrowsableState.Never)] - public override bool Equals(object obj) => base.Equals(obj); - - /// - [EditorBrowsable(EditorBrowsableState.Never)] - public override int GetHashCode() => base.GetHashCode(); - - /// - [EditorBrowsable(EditorBrowsableState.Never)] - public override string ToString() => Id; -} diff --git a/sdk/cloudmachine/Azure.CloudMachine/src/ConnectionCollection.cs b/sdk/cloudmachine/Azure.CloudMachine/src/ConnectionCollection.cs index 1a5087da74e34..3bdac3b4749e4 100644 --- a/sdk/cloudmachine/Azure.CloudMachine/src/ConnectionCollection.cs +++ b/sdk/cloudmachine/Azure.CloudMachine/src/ConnectionCollection.cs @@ -4,16 +4,17 @@ using System; using System.Collections.Generic; using System.Collections.ObjectModel; +using System.Diagnostics; using System.Text.Json; using System.Text.Json.Serialization; -using Azure.Core; -namespace Azure.CloudMachine; +namespace Azure.Core; /// /// Represents the connection options for a client. /// [JsonConverter(typeof(ConnectionCollectionConverter))] +[DebuggerTypeProxy(typeof(ConnectionCollectionViewer))] public class ConnectionCollection : KeyedCollection { /// @@ -30,6 +31,20 @@ internal void AddRange(IEnumerable connections) } } +internal class ConnectionCollectionViewer(ConnectionCollection connections) +{ + [DebuggerBrowsable(DebuggerBrowsableState.RootHidden)] + public ClientConnection[] Items + { + get + { + ClientConnection[] items = new ClientConnection[connections.Count]; + connections.CopyTo(items, 0); + return items; + } + } +} + internal class ConnectionCollectionConverter : JsonConverter { public override ConnectionCollection Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) diff --git a/sdk/cloudmachine/Azure.CloudMachine/src/Core/RestCLient/RestCallFailedException.cs b/sdk/cloudmachine/Azure.CloudMachine/src/Core/RestCLient/RestCallFailedException.cs index 22d7a0c98243c..91ebad31292f2 100644 --- a/sdk/cloudmachine/Azure.CloudMachine/src/Core/RestCLient/RestCallFailedException.cs +++ b/sdk/cloudmachine/Azure.CloudMachine/src/Core/RestCLient/RestCallFailedException.cs @@ -4,7 +4,7 @@ using System; using System.ClientModel.Primitives; -namespace Azure +namespace Azure.Core.Rest { /// /// Exception thrown when a REST call fails. diff --git a/sdk/cloudmachine/Azure.CloudMachine/src/Core/RestCLient/RestClient.cs b/sdk/cloudmachine/Azure.CloudMachine/src/Core/RestCLient/RestClient.cs index 648044c383817..6ecbb64c72ca1 100644 --- a/sdk/cloudmachine/Azure.CloudMachine/src/Core/RestCLient/RestClient.cs +++ b/sdk/cloudmachine/Azure.CloudMachine/src/Core/RestCLient/RestClient.cs @@ -5,7 +5,7 @@ using System.ClientModel.Primitives; using System.ClientModel; -namespace Azure +namespace Azure.Core.Rest { /// /// A simple REST client that sends HTTP requests and receives responses. diff --git a/sdk/cloudmachine/Azure.CloudMachine/src/Core/RestCLient/RestClientOptions.cs b/sdk/cloudmachine/Azure.CloudMachine/src/Core/RestCLient/RestClientOptions.cs index daa6df9758e40..d44bb2dea92fe 100644 --- a/sdk/cloudmachine/Azure.CloudMachine/src/Core/RestCLient/RestClientOptions.cs +++ b/sdk/cloudmachine/Azure.CloudMachine/src/Core/RestCLient/RestClientOptions.cs @@ -3,7 +3,7 @@ using System.ClientModel.Primitives; -namespace Azure +namespace Azure.Core.Rest { /// /// Options for the REST client. diff --git a/sdk/cloudmachine/Azure.CloudMachine/src/GlobalSuppressions.cs b/sdk/cloudmachine/Azure.CloudMachine/src/GlobalSuppressions.cs index 57ea0ca077129..8bb710807d489 100644 --- a/sdk/cloudmachine/Azure.CloudMachine/src/GlobalSuppressions.cs +++ b/sdk/cloudmachine/Azure.CloudMachine/src/GlobalSuppressions.cs @@ -2,6 +2,5 @@ // Licensed under the MIT License. using System.Diagnostics.CodeAnalysis; - -[assembly: SuppressMessage("Usage", "AZC0007:DO provide a minimal constructor that takes only the parameters required to connect to the service.", Justification = "", Scope = "member", Target = "~M:Azure.RestClient.#ctor")] -[assembly: SuppressMessage("Usage", "AZC0007:DO provide a minimal constructor that takes only the parameters required to connect to the service.", Justification = "", Scope = "member", Target = "~M:Azure.RestClient.#ctor(System.ClientModel.Primitives.PipelinePolicy)")] +[assembly: SuppressMessage("Usage", "AZC0007:DO provide a minimal constructor that takes only the parameters required to connect to the service.", Justification = "", Scope = "member", Target = "~M:Azure.Core.Rest.RestClient.#ctor")] +[assembly: SuppressMessage("Usage", "AZC0007:DO provide a minimal constructor that takes only the parameters required to connect to the service.", Justification = "", Scope = "member", Target = "~M:Azure.Core.Rest.RestClient.#ctor(System.ClientModel.Primitives.PipelinePolicy)")] diff --git a/sdk/cloudmachine/Azure.CloudMachine/tests/Azure.CloudMachine.Tests.csproj b/sdk/cloudmachine/Azure.CloudMachine/tests/Azure.CloudMachine.Tests.csproj index 72514fb231b79..62bbcd8d0e934 100644 --- a/sdk/cloudmachine/Azure.CloudMachine/tests/Azure.CloudMachine.Tests.csproj +++ b/sdk/cloudmachine/Azure.CloudMachine/tests/Azure.CloudMachine.Tests.csproj @@ -3,6 +3,7 @@ 12 + diff --git a/sdk/cloudmachine/Azure.CloudMachine/tests/CloudMachineTests_rag.cs b/sdk/cloudmachine/Azure.CloudMachine/tests/CloudMachineTests_rag.cs index c4061f87c55ff..13a77362ff81a 100644 --- a/sdk/cloudmachine/Azure.CloudMachine/tests/CloudMachineTests_rag.cs +++ b/sdk/cloudmachine/Azure.CloudMachine/tests/CloudMachineTests_rag.cs @@ -34,7 +34,7 @@ public void RagDemo() "Do you think I would like the weather there?", ]; - CloudMachineClient cm = new(default, new MockConfiguration("cmec4615e3fdfa44e")); + CloudMachineClient cm = new(new MockConfiguration("cmec4615e3fdfa44e"), default); var chat = cm.GetOpenAIChatClient(); var embeddings = cm.GetOpenAIEmbeddingsClient(); diff --git a/sdk/cloudmachine/Azure.CloudMachine/tests/ConnectionTests.cs b/sdk/cloudmachine/Azure.CloudMachine/tests/ConnectionTests.cs index 33e28a6dbde7c..6f90fcf8a7697 100644 --- a/sdk/cloudmachine/Azure.CloudMachine/tests/ConnectionTests.cs +++ b/sdk/cloudmachine/Azure.CloudMachine/tests/ConnectionTests.cs @@ -6,9 +6,10 @@ using System; using System.Linq; using System.Text.Json; -using Azure.CloudMachine.KeyVault; using Azure.CloudMachine.OpenAI; +using Azure.Core; using Azure.Storage.Blobs; +using Microsoft.Extensions.Configuration; using NUnit.Framework; using OpenAI.Chat; @@ -44,7 +45,7 @@ public void TwoApps() // app 2 (no dependency on the CDK) ConnectionCollection deserializedConnections = JsonSerializer.Deserialize(serializedConnections)!; - CloudMachineClient client = new(connections: deserializedConnections); + CloudMachineClient client = new(deserializedConnections); ValidateClient(client); } @@ -63,17 +64,44 @@ public void SingleClientAdd(string[] args) } [Test] - public void SingleClientConfigure() + public void ConfigurationDemo() { - CloudMachineClient client = new(); - client.Configure((infrastructure) => - { - infrastructure.AddFeature(new KeyVaultFeature()); - infrastructure.AddFeature(new OpenAIModelFeature("gpt-35-turbo", "0125")); - infrastructure.AddFeature(new OpenAIModelFeature("text-embedding-ada-002", "2", AIModelKind.Embedding)); - }); - ValidateClient(client); - var embeddings = client.GetOpenAIEmbeddingsClient(); + CloudMachineInfrastructure infra = new(); + infra.AddFeature(new OpenAIModelFeature("gpt-35-turbo", "0125")); + + IConfiguration configuration = new ConfigurationBuilder() + .AddCloudMachineInfrastructure(infra) + .Build(); + + CloudMachineClient client = new(configuration); + ChatClient chat = client.GetOpenAIChatClient(); + } + + [Test] + public void ConfigurationLowLevel() + { + ConnectionCollection connections = new(); + connections.Add(new ClientConnection( + id: "Azure.AI.OpenAI.AzureOpenAIClient", + locator: "https://cm2c54b6e4637f4b1.openai.azure.com", + auth: ClientAuthenticationMethod.EntraId)); + + IConfiguration configuration = new ConfigurationBuilder() + .AddCloudMachineConnections(connections) + .AddCloudMachineId("aaaa-bbbb-cccc-dddd") + .Build(); + + var locator = configuration["CloudMachine:Connections:Azure.AI.OpenAI.AzureOpenAIClient:Locator"]; + Assert.AreEqual("https://cm2c54b6e4637f4b1.openai.azure.com", locator); + var id = configuration["CloudMachine:Id"]; + Assert.AreEqual("aaaa-bbbb-cccc-dddd", id); + + CloudMachineClient client = new(configuration); + Assert.AreEqual("aaaa-bbbb-cccc-dddd", client.Id); + + ClientConnection connection = client.Connections["Azure.AI.OpenAI.AzureOpenAIClient"]; + Assert.AreEqual("https://cm2c54b6e4637f4b1.openai.azure.com", connection.Locator); + Assert.AreEqual("aaaa-bbbb-cccc-dddd", client.Id); } private static void ValidateClient(CloudMachineClient client) diff --git a/sdk/cloudmachine/Azure.CloudMachine/tests/GettingStarted.cs b/sdk/cloudmachine/Azure.CloudMachine/tests/GettingStarted.cs index ee097e04ba377..2e78760aec04f 100644 --- a/sdk/cloudmachine/Azure.CloudMachine/tests/GettingStarted.cs +++ b/sdk/cloudmachine/Azure.CloudMachine/tests/GettingStarted.cs @@ -13,20 +13,14 @@ namespace Azure.CloudMachine.Tests; public partial class CloudMachineTests { - [Test] - [TestCase([new string[] { "-azd" }])] + [TestCase([new string[] { "-bicep" }])] public void GettingStarted(string[] args) { - CloudMachineInfrastructure infra = new(); - infra.AddFeature(new OpenAIModelFeature("gpt-35-turbo", "0125")); + CloudMachineInfrastructure cm = new(); + cm.AddFeature(new OpenAIModelFeature("gpt-35-turbo", "0125")); + if (cm.TryExecuteCommand(args)) return; - if (args.Contains("-azd")) { - Azd.Init(infra); - return; - } - - // TODO: we need to allow newing up the client. - CloudMachineClient client = infra.GetClient(); + CloudMachineClient client = cm.GetClient(); ChatClient chat = client.GetOpenAIChatClient(); string completion = chat.CompleteChat("List all noble gases.").AsText(); diff --git a/sdk/cloudmachine/Azure.Provisioning.CloudMachine/api/Azure.Provisioning.CloudMachine.net8.0.cs b/sdk/cloudmachine/Azure.Provisioning.CloudMachine/api/Azure.Provisioning.CloudMachine.net8.0.cs index 3e3c5e0fb6113..6b1ae5a6fb4a4 100644 --- a/sdk/cloudmachine/Azure.Provisioning.CloudMachine/api/Azure.Provisioning.CloudMachine.net8.0.cs +++ b/sdk/cloudmachine/Azure.Provisioning.CloudMachine/api/Azure.Provisioning.CloudMachine.net8.0.cs @@ -8,28 +8,27 @@ public static void InitDeployment(Azure.CloudMachine.CloudMachineInfrastructure } public static partial class CloudMachineClientExtensions { - public static T AddFeature(this Azure.CloudMachine.CloudMachineClient client, T feature) where T : Azure.Provisioning.CloudMachine.CloudMachineFeature { throw null; } - public static void Configure(this Azure.CloudMachine.CloudMachineClient client, System.Action? configure = null) { } + public static T AddFeature(this Azure.CloudMachine.CloudMachineClient client, T feature) where T : Azure.CloudMachine.Core.CloudMachineFeature { throw null; } [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] public static Azure.CloudMachine.CloudMachineInfrastructure GetInfrastructure(this Azure.CloudMachine.CloudMachineClient client) { throw null; } } public static partial class CloudMachineCommands { - public static bool Execute(string[] args, System.Action? configure = null, bool exitProcessIfHandled = true) { throw null; } + public static bool TryExecuteCommand(this Azure.CloudMachine.CloudMachineInfrastructure cmi, string[] args) { throw null; } } public partial class CloudMachineInfrastructure { public CloudMachineInfrastructure(string? cmId = null) { } [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] - public Azure.CloudMachine.ConnectionCollection Connections { get { throw null; } } - public Azure.CloudMachine.FeatureCollection Features { get { throw null; } } + public Azure.Core.ConnectionCollection Connections { get { throw null; } } + public Azure.CloudMachine.Core.FeatureCollection Features { get { throw null; } } public string Id { get { throw null; } } [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] public Azure.Provisioning.Roles.UserAssignedIdentity Identity { get { throw null; } } [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] public Azure.Provisioning.ProvisioningParameter PrincipalIdParameter { get { throw null; } } public void AddEndpoints() { } - public T AddFeature(T feature) where T : Azure.Provisioning.CloudMachine.CloudMachineFeature { throw null; } + public T AddFeature(T feature) where T : Azure.CloudMachine.Core.CloudMachineFeature { throw null; } [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] public void AddResource(Azure.Provisioning.Primitives.NamedProvisionableConstruct resource) { } [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] @@ -42,49 +41,54 @@ public void AddResource(Azure.Provisioning.Primitives.NamedProvisionableConstruc [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] public override string ToString() { throw null; } } - public partial class FeatureCollection : System.Collections.Generic.IEnumerable, System.Collections.IEnumerable + public static partial class CloudMachineInfrastructureConfiguration { - internal FeatureCollection() { } - public System.Collections.Generic.IEnumerable FindAll() where T : Azure.Provisioning.CloudMachine.CloudMachineFeature { throw null; } - public System.Collections.Generic.IEnumerator GetEnumerator() { throw null; } - System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { throw null; } - } - public partial class ServiceBusNamespaceFeature : Azure.Provisioning.CloudMachine.CloudMachineFeature - { - public ServiceBusNamespaceFeature(string name, Azure.Provisioning.ServiceBus.ServiceBusSkuName sku = Azure.Provisioning.ServiceBus.ServiceBusSkuName.Standard, Azure.Provisioning.ServiceBus.ServiceBusSkuTier tier = Azure.Provisioning.ServiceBus.ServiceBusSkuTier.Standard) { } - protected internal override void EmitConnections(Azure.CloudMachine.ConnectionCollection connections, string cmId) { } - protected override Azure.Provisioning.Primitives.ProvisionableResource EmitResources(Azure.CloudMachine.CloudMachineInfrastructure infrastructure) { throw null; } - } - public partial class ServiceBusSubscriptionFeature : Azure.Provisioning.CloudMachine.CloudMachineFeature - { - public ServiceBusSubscriptionFeature(string name, Azure.CloudMachine.ServiceBusTopicFeature parent) { } - protected internal override void EmitConnections(Azure.CloudMachine.ConnectionCollection connections, string cmId) { } - protected override Azure.Provisioning.Primitives.ProvisionableResource EmitResources(Azure.CloudMachine.CloudMachineInfrastructure infrastructure) { throw null; } - } - public partial class ServiceBusTopicFeature : Azure.Provisioning.CloudMachine.CloudMachineFeature - { - public ServiceBusTopicFeature(string name, Azure.CloudMachine.ServiceBusNamespaceFeature parent) { } - public string Name { get { throw null; } } - protected internal override void EmitConnections(Azure.CloudMachine.ConnectionCollection connections, string cmId) { } - protected override Azure.Provisioning.Primitives.ProvisionableResource EmitResources(Azure.CloudMachine.CloudMachineInfrastructure infrastructure) { throw null; } + public static Microsoft.Extensions.Configuration.IConfigurationBuilder AddCloudMachineInfrastructure(this Microsoft.Extensions.Configuration.IConfigurationBuilder builder, Azure.CloudMachine.CloudMachineInfrastructure cm) { throw null; } } } namespace Azure.CloudMachine.AppService { - public partial class AppServiceFeature : Azure.Provisioning.CloudMachine.CloudMachineFeature + public partial class AppServiceFeature : Azure.CloudMachine.Core.CloudMachineFeature { public AppServiceFeature() { } public Azure.Provisioning.AppService.AppServiceSkuDescription Sku { get { throw null; } set { } } protected override Azure.Provisioning.Primitives.ProvisionableResource EmitResources(Azure.CloudMachine.CloudMachineInfrastructure infrastructure) { throw null; } } } +namespace Azure.CloudMachine.Core +{ + public abstract partial class CloudMachineFeature + { + protected CloudMachineFeature() { } + protected internal System.Collections.Generic.Dictionary RequiredSystemRoles { get { throw null; } } + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] + public Azure.Provisioning.Primitives.ProvisionableResource Resource { get { throw null; } } + protected internal virtual void EmitConnections(Azure.Core.ConnectionCollection connections, string cmId) { } + protected internal virtual void EmitFeatures(Azure.CloudMachine.Core.FeatureCollection features, string cmId) { } + protected abstract Azure.Provisioning.Primitives.ProvisionableResource EmitResources(Azure.CloudMachine.CloudMachineInfrastructure cm); + protected static T EnsureEmits(Azure.CloudMachine.Core.CloudMachineFeature feature) { 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; } + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] + public override string ToString() { throw null; } + } + public partial class FeatureCollection : System.Collections.Generic.IEnumerable, System.Collections.IEnumerable + { + internal FeatureCollection() { } + public System.Collections.Generic.IEnumerable FindAll() where T : Azure.CloudMachine.Core.CloudMachineFeature { throw null; } + public System.Collections.Generic.IEnumerator GetEnumerator() { throw null; } + System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { throw null; } + } +} namespace Azure.CloudMachine.KeyVault { - public partial class KeyVaultFeature : Azure.Provisioning.CloudMachine.CloudMachineFeature + public partial class KeyVaultFeature : Azure.CloudMachine.Core.CloudMachineFeature { public KeyVaultFeature(Azure.Provisioning.KeyVault.KeyVaultSku? sku = null) { } public Azure.Provisioning.KeyVault.KeyVaultSku Sku { get { throw null; } set { } } - protected internal override void EmitConnections(Azure.CloudMachine.ConnectionCollection connections, string cmId) { } + protected internal override void EmitConnections(Azure.Core.ConnectionCollection connections, string cmId) { } protected override Azure.Provisioning.Primitives.ProvisionableResource EmitResources(Azure.CloudMachine.CloudMachineInfrastructure infrastructure) { throw null; } } } @@ -95,36 +99,16 @@ public enum AIModelKind Chat = 0, Embedding = 1, } - public partial class OpenAIModelFeature : Azure.Provisioning.CloudMachine.CloudMachineFeature + public partial class OpenAIModelFeature : Azure.CloudMachine.Core.CloudMachineFeature { public OpenAIModelFeature(string model, string modelVersion, Azure.CloudMachine.OpenAI.AIModelKind kind = Azure.CloudMachine.OpenAI.AIModelKind.Chat) { } public string Model { get { throw null; } } public string ModelVersion { get { throw null; } } - protected internal override void EmitConnections(Azure.CloudMachine.ConnectionCollection connections, string cmId) { } - protected internal override void EmitFeatures(Azure.CloudMachine.FeatureCollection features, string cmId) { } + protected internal override void EmitConnections(Azure.Core.ConnectionCollection connections, string cmId) { } + protected internal override void EmitFeatures(Azure.CloudMachine.Core.FeatureCollection features, string cmId) { } protected override Azure.Provisioning.Primitives.ProvisionableResource EmitResources(Azure.CloudMachine.CloudMachineInfrastructure cm) { throw null; } } } -namespace Azure.Provisioning.CloudMachine -{ - public abstract partial class CloudMachineFeature - { - protected CloudMachineFeature() { } - protected internal System.Collections.Generic.Dictionary RequiredSystemRoles { get { throw null; } } - [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] - public Azure.Provisioning.Primitives.ProvisionableResource Resource { get { throw null; } } - protected internal virtual void EmitConnections(Azure.CloudMachine.ConnectionCollection connections, string cmId) { } - protected internal virtual void EmitFeatures(Azure.CloudMachine.FeatureCollection features, string cmId) { } - protected abstract Azure.Provisioning.Primitives.ProvisionableResource EmitResources(Azure.CloudMachine.CloudMachineInfrastructure cm); - protected static T EnsureEmits(Azure.Provisioning.CloudMachine.CloudMachineFeature feature) { 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; } - [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] - public override string ToString() { throw null; } - } -} namespace System.ClientModel.TypeSpec { public static partial class TypeSpecWriter diff --git a/sdk/cloudmachine/Azure.Provisioning.CloudMachine/api/Azure.Provisioning.CloudMachine.netstandard2.0.cs b/sdk/cloudmachine/Azure.Provisioning.CloudMachine/api/Azure.Provisioning.CloudMachine.netstandard2.0.cs index 3e3c5e0fb6113..6b1ae5a6fb4a4 100644 --- a/sdk/cloudmachine/Azure.Provisioning.CloudMachine/api/Azure.Provisioning.CloudMachine.netstandard2.0.cs +++ b/sdk/cloudmachine/Azure.Provisioning.CloudMachine/api/Azure.Provisioning.CloudMachine.netstandard2.0.cs @@ -8,28 +8,27 @@ public static void InitDeployment(Azure.CloudMachine.CloudMachineInfrastructure } public static partial class CloudMachineClientExtensions { - public static T AddFeature(this Azure.CloudMachine.CloudMachineClient client, T feature) where T : Azure.Provisioning.CloudMachine.CloudMachineFeature { throw null; } - public static void Configure(this Azure.CloudMachine.CloudMachineClient client, System.Action? configure = null) { } + public static T AddFeature(this Azure.CloudMachine.CloudMachineClient client, T feature) where T : Azure.CloudMachine.Core.CloudMachineFeature { throw null; } [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] public static Azure.CloudMachine.CloudMachineInfrastructure GetInfrastructure(this Azure.CloudMachine.CloudMachineClient client) { throw null; } } public static partial class CloudMachineCommands { - public static bool Execute(string[] args, System.Action? configure = null, bool exitProcessIfHandled = true) { throw null; } + public static bool TryExecuteCommand(this Azure.CloudMachine.CloudMachineInfrastructure cmi, string[] args) { throw null; } } public partial class CloudMachineInfrastructure { public CloudMachineInfrastructure(string? cmId = null) { } [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] - public Azure.CloudMachine.ConnectionCollection Connections { get { throw null; } } - public Azure.CloudMachine.FeatureCollection Features { get { throw null; } } + public Azure.Core.ConnectionCollection Connections { get { throw null; } } + public Azure.CloudMachine.Core.FeatureCollection Features { get { throw null; } } public string Id { get { throw null; } } [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] public Azure.Provisioning.Roles.UserAssignedIdentity Identity { get { throw null; } } [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] public Azure.Provisioning.ProvisioningParameter PrincipalIdParameter { get { throw null; } } public void AddEndpoints() { } - public T AddFeature(T feature) where T : Azure.Provisioning.CloudMachine.CloudMachineFeature { throw null; } + public T AddFeature(T feature) where T : Azure.CloudMachine.Core.CloudMachineFeature { throw null; } [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] public void AddResource(Azure.Provisioning.Primitives.NamedProvisionableConstruct resource) { } [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] @@ -42,49 +41,54 @@ public void AddResource(Azure.Provisioning.Primitives.NamedProvisionableConstruc [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] public override string ToString() { throw null; } } - public partial class FeatureCollection : System.Collections.Generic.IEnumerable, System.Collections.IEnumerable + public static partial class CloudMachineInfrastructureConfiguration { - internal FeatureCollection() { } - public System.Collections.Generic.IEnumerable FindAll() where T : Azure.Provisioning.CloudMachine.CloudMachineFeature { throw null; } - public System.Collections.Generic.IEnumerator GetEnumerator() { throw null; } - System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { throw null; } - } - public partial class ServiceBusNamespaceFeature : Azure.Provisioning.CloudMachine.CloudMachineFeature - { - public ServiceBusNamespaceFeature(string name, Azure.Provisioning.ServiceBus.ServiceBusSkuName sku = Azure.Provisioning.ServiceBus.ServiceBusSkuName.Standard, Azure.Provisioning.ServiceBus.ServiceBusSkuTier tier = Azure.Provisioning.ServiceBus.ServiceBusSkuTier.Standard) { } - protected internal override void EmitConnections(Azure.CloudMachine.ConnectionCollection connections, string cmId) { } - protected override Azure.Provisioning.Primitives.ProvisionableResource EmitResources(Azure.CloudMachine.CloudMachineInfrastructure infrastructure) { throw null; } - } - public partial class ServiceBusSubscriptionFeature : Azure.Provisioning.CloudMachine.CloudMachineFeature - { - public ServiceBusSubscriptionFeature(string name, Azure.CloudMachine.ServiceBusTopicFeature parent) { } - protected internal override void EmitConnections(Azure.CloudMachine.ConnectionCollection connections, string cmId) { } - protected override Azure.Provisioning.Primitives.ProvisionableResource EmitResources(Azure.CloudMachine.CloudMachineInfrastructure infrastructure) { throw null; } - } - public partial class ServiceBusTopicFeature : Azure.Provisioning.CloudMachine.CloudMachineFeature - { - public ServiceBusTopicFeature(string name, Azure.CloudMachine.ServiceBusNamespaceFeature parent) { } - public string Name { get { throw null; } } - protected internal override void EmitConnections(Azure.CloudMachine.ConnectionCollection connections, string cmId) { } - protected override Azure.Provisioning.Primitives.ProvisionableResource EmitResources(Azure.CloudMachine.CloudMachineInfrastructure infrastructure) { throw null; } + public static Microsoft.Extensions.Configuration.IConfigurationBuilder AddCloudMachineInfrastructure(this Microsoft.Extensions.Configuration.IConfigurationBuilder builder, Azure.CloudMachine.CloudMachineInfrastructure cm) { throw null; } } } namespace Azure.CloudMachine.AppService { - public partial class AppServiceFeature : Azure.Provisioning.CloudMachine.CloudMachineFeature + public partial class AppServiceFeature : Azure.CloudMachine.Core.CloudMachineFeature { public AppServiceFeature() { } public Azure.Provisioning.AppService.AppServiceSkuDescription Sku { get { throw null; } set { } } protected override Azure.Provisioning.Primitives.ProvisionableResource EmitResources(Azure.CloudMachine.CloudMachineInfrastructure infrastructure) { throw null; } } } +namespace Azure.CloudMachine.Core +{ + public abstract partial class CloudMachineFeature + { + protected CloudMachineFeature() { } + protected internal System.Collections.Generic.Dictionary RequiredSystemRoles { get { throw null; } } + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] + public Azure.Provisioning.Primitives.ProvisionableResource Resource { get { throw null; } } + protected internal virtual void EmitConnections(Azure.Core.ConnectionCollection connections, string cmId) { } + protected internal virtual void EmitFeatures(Azure.CloudMachine.Core.FeatureCollection features, string cmId) { } + protected abstract Azure.Provisioning.Primitives.ProvisionableResource EmitResources(Azure.CloudMachine.CloudMachineInfrastructure cm); + protected static T EnsureEmits(Azure.CloudMachine.Core.CloudMachineFeature feature) { 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; } + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] + public override string ToString() { throw null; } + } + public partial class FeatureCollection : System.Collections.Generic.IEnumerable, System.Collections.IEnumerable + { + internal FeatureCollection() { } + public System.Collections.Generic.IEnumerable FindAll() where T : Azure.CloudMachine.Core.CloudMachineFeature { throw null; } + public System.Collections.Generic.IEnumerator GetEnumerator() { throw null; } + System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { throw null; } + } +} namespace Azure.CloudMachine.KeyVault { - public partial class KeyVaultFeature : Azure.Provisioning.CloudMachine.CloudMachineFeature + public partial class KeyVaultFeature : Azure.CloudMachine.Core.CloudMachineFeature { public KeyVaultFeature(Azure.Provisioning.KeyVault.KeyVaultSku? sku = null) { } public Azure.Provisioning.KeyVault.KeyVaultSku Sku { get { throw null; } set { } } - protected internal override void EmitConnections(Azure.CloudMachine.ConnectionCollection connections, string cmId) { } + protected internal override void EmitConnections(Azure.Core.ConnectionCollection connections, string cmId) { } protected override Azure.Provisioning.Primitives.ProvisionableResource EmitResources(Azure.CloudMachine.CloudMachineInfrastructure infrastructure) { throw null; } } } @@ -95,36 +99,16 @@ public enum AIModelKind Chat = 0, Embedding = 1, } - public partial class OpenAIModelFeature : Azure.Provisioning.CloudMachine.CloudMachineFeature + public partial class OpenAIModelFeature : Azure.CloudMachine.Core.CloudMachineFeature { public OpenAIModelFeature(string model, string modelVersion, Azure.CloudMachine.OpenAI.AIModelKind kind = Azure.CloudMachine.OpenAI.AIModelKind.Chat) { } public string Model { get { throw null; } } public string ModelVersion { get { throw null; } } - protected internal override void EmitConnections(Azure.CloudMachine.ConnectionCollection connections, string cmId) { } - protected internal override void EmitFeatures(Azure.CloudMachine.FeatureCollection features, string cmId) { } + protected internal override void EmitConnections(Azure.Core.ConnectionCollection connections, string cmId) { } + protected internal override void EmitFeatures(Azure.CloudMachine.Core.FeatureCollection features, string cmId) { } protected override Azure.Provisioning.Primitives.ProvisionableResource EmitResources(Azure.CloudMachine.CloudMachineInfrastructure cm) { throw null; } } } -namespace Azure.Provisioning.CloudMachine -{ - public abstract partial class CloudMachineFeature - { - protected CloudMachineFeature() { } - protected internal System.Collections.Generic.Dictionary RequiredSystemRoles { get { throw null; } } - [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] - public Azure.Provisioning.Primitives.ProvisionableResource Resource { get { throw null; } } - protected internal virtual void EmitConnections(Azure.CloudMachine.ConnectionCollection connections, string cmId) { } - protected internal virtual void EmitFeatures(Azure.CloudMachine.FeatureCollection features, string cmId) { } - protected abstract Azure.Provisioning.Primitives.ProvisionableResource EmitResources(Azure.CloudMachine.CloudMachineInfrastructure cm); - protected static T EnsureEmits(Azure.Provisioning.CloudMachine.CloudMachineFeature feature) { 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; } - [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] - public override string ToString() { throw null; } - } -} namespace System.ClientModel.TypeSpec { public static partial class TypeSpecWriter diff --git a/sdk/cloudmachine/Azure.Provisioning.CloudMachine/src/CloudMachineClientExtensions.cs b/sdk/cloudmachine/Azure.Provisioning.CloudMachine/src/CloudMachineClientExtensions.cs index 7559dd4437623..c735cc00e4258 100644 --- a/sdk/cloudmachine/Azure.Provisioning.CloudMachine/src/CloudMachineClientExtensions.cs +++ b/sdk/cloudmachine/Azure.Provisioning.CloudMachine/src/CloudMachineClientExtensions.cs @@ -3,14 +3,14 @@ using System; using System.ComponentModel; +using Azure.CloudMachine.Core; using Azure.Core; -using Azure.Provisioning.CloudMachine; namespace Azure.CloudMachine; public static class CloudMachineClientExtensions { - public static void Configure(this CloudMachineClient client, Action? configure = default) + private static void Configure(this CloudMachineClient client, Action? configure = default) { CloudMachineInfrastructure cmi = new(client.Id); if (configure != default) diff --git a/sdk/cloudmachine/Azure.Provisioning.CloudMachine/src/CloudMachineInfrastructure/CloudMachineFeature.cs b/sdk/cloudmachine/Azure.Provisioning.CloudMachine/src/CloudMachineInfrastructure/CloudMachineFeature.cs index a43077e5db0b2..ef8f00503640b 100644 --- a/sdk/cloudmachine/Azure.Provisioning.CloudMachine/src/CloudMachineInfrastructure/CloudMachineFeature.cs +++ b/sdk/cloudmachine/Azure.Provisioning.CloudMachine/src/CloudMachineInfrastructure/CloudMachineFeature.cs @@ -4,10 +4,10 @@ using System; using System.Collections.Generic; using System.ComponentModel; -using Azure.CloudMachine; +using Azure.Core; using Azure.Provisioning.Primitives; -namespace Azure.Provisioning.CloudMachine; +namespace Azure.CloudMachine.Core; public abstract class CloudMachineFeature { diff --git a/sdk/cloudmachine/Azure.Provisioning.CloudMachine/src/CloudMachineInfrastructure/CloudMachineInfrastructure.cs b/sdk/cloudmachine/Azure.Provisioning.CloudMachine/src/CloudMachineInfrastructure/CloudMachineInfrastructure.cs index e61889cdc4787..2e3a18146f988 100644 --- a/sdk/cloudmachine/Azure.Provisioning.CloudMachine/src/CloudMachineInfrastructure/CloudMachineInfrastructure.cs +++ b/sdk/cloudmachine/Azure.Provisioning.CloudMachine/src/CloudMachineInfrastructure/CloudMachineInfrastructure.cs @@ -4,11 +4,16 @@ using System; using System.Collections.Generic; using System.ComponentModel; +using Azure.CloudMachine.Core; +using Azure.CloudMachine.EventGrid; +using Azure.CloudMachine.ServiceBus; +using Azure.CloudMachine.Storage; +using Azure.Core; using Azure.Provisioning; -using Azure.Provisioning.CloudMachine; using Azure.Provisioning.Expressions; using Azure.Provisioning.Primitives; using Azure.Provisioning.Roles; +using Microsoft.Extensions.Configuration; namespace Azure.CloudMachine; @@ -43,7 +48,7 @@ public CloudMachineInfrastructure(string? cmId = default) { if (cmId == default) { - cmId = CloudMachineWorkspace.ReadOrCreateCloudMachineId(); + cmId = CloudMachineClient.ReadOrCreateCloudMachineId(); } Id = cmId; @@ -128,3 +133,19 @@ public ProvisioningPlan Build(ProvisioningBuildOptions? context = default) [EditorBrowsable(EditorBrowsableState.Never)] public override bool Equals(object? obj) => base.Equals(obj); } + +public static class CloudMachineInfrastructureConfiguration +{ + /// + /// Adds a connection to the collection. + /// + /// + /// + /// + public static IConfigurationBuilder AddCloudMachineInfrastructure(this IConfigurationBuilder builder, CloudMachineInfrastructure cm) + { + builder.AddCloudMachineConnections(cm.Connections); + builder.AddCloudMachineId(cm.Id); + return builder; + } +} diff --git a/sdk/cloudmachine/Azure.Provisioning.CloudMachine/src/CloudMachineInfrastructure/FeatureCollection.cs b/sdk/cloudmachine/Azure.Provisioning.CloudMachine/src/CloudMachineInfrastructure/FeatureCollection.cs index 07e24da9bd102..3780ed615f758 100644 --- a/sdk/cloudmachine/Azure.Provisioning.CloudMachine/src/CloudMachineInfrastructure/FeatureCollection.cs +++ b/sdk/cloudmachine/Azure.Provisioning.CloudMachine/src/CloudMachineInfrastructure/FeatureCollection.cs @@ -5,10 +5,9 @@ using System.Collections; using System.Collections.Generic; using System.Linq; -using Azure.Provisioning.CloudMachine; using Azure.Provisioning.Primitives; -namespace Azure.CloudMachine; +namespace Azure.CloudMachine.Core; public class FeatureCollection : IEnumerable { diff --git a/sdk/cloudmachine/Azure.Provisioning.CloudMachine/src/FeaturesBuiltIn/EventGridSystemTopicFeature.cs b/sdk/cloudmachine/Azure.Provisioning.CloudMachine/src/FeaturesBuiltIn/EventGridSystemTopicFeature.cs index 5f331be310e44..14723c51c54d0 100644 --- a/sdk/cloudmachine/Azure.Provisioning.CloudMachine/src/FeaturesBuiltIn/EventGridSystemTopicFeature.cs +++ b/sdk/cloudmachine/Azure.Provisioning.CloudMachine/src/FeaturesBuiltIn/EventGridSystemTopicFeature.cs @@ -2,20 +2,21 @@ // Licensed under the MIT License. using Azure.CloudMachine.Core; -using Azure.Provisioning.CloudMachine; using Azure.Provisioning.EventGrid; using Azure.Provisioning.Expressions; using Azure.Provisioning.Primitives; using Azure.Provisioning.Resources; using Azure.Provisioning.Storage; -namespace Azure.CloudMachine; +namespace Azure.CloudMachine.EventGrid; internal class EventGridSystemTopicFeature(string topicName, CloudMachineFeature source, string topicType) : CloudMachineFeature { + internal const string EventGridTopicVersion = "2022-06-15"; + protected override ProvisionableResource EmitResources(CloudMachineInfrastructure infrastructure) { - var topic = new SystemTopic("cm_eventgrid_topic", InternalConstants.EventGridTopicVersion) + var topic = new SystemTopic("cm_eventgrid_topic", EventGridTopicVersion) { TopicType = topicType, Source = EnsureEmits(source).Id, diff --git a/sdk/cloudmachine/Azure.Provisioning.CloudMachine/src/FeaturesBuiltIn/InternalConstants.cs b/sdk/cloudmachine/Azure.Provisioning.CloudMachine/src/FeaturesBuiltIn/InternalConstants.cs deleted file mode 100644 index 6387aa81b0015..0000000000000 --- a/sdk/cloudmachine/Azure.Provisioning.CloudMachine/src/FeaturesBuiltIn/InternalConstants.cs +++ /dev/null @@ -1,10 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -namespace Azure.CloudMachine.Core -{ - internal static class InternalConstants - { - internal const string EventGridTopicVersion = "2022-06-15"; - } -} diff --git a/sdk/cloudmachine/Azure.Provisioning.CloudMachine/src/FeaturesBuiltIn/ServiceBusNamespaceFeature.cs b/sdk/cloudmachine/Azure.Provisioning.CloudMachine/src/FeaturesBuiltIn/ServiceBusNamespaceFeature.cs index 749b82feadb4a..9df3f86fa3bc6 100644 --- a/sdk/cloudmachine/Azure.Provisioning.CloudMachine/src/FeaturesBuiltIn/ServiceBusNamespaceFeature.cs +++ b/sdk/cloudmachine/Azure.Provisioning.CloudMachine/src/FeaturesBuiltIn/ServiceBusNamespaceFeature.cs @@ -3,13 +3,12 @@ using Azure.CloudMachine.Core; using Azure.Core; -using Azure.Provisioning.CloudMachine; using Azure.Provisioning.Primitives; using Azure.Provisioning.ServiceBus; -namespace Azure.CloudMachine; +namespace Azure.CloudMachine.ServiceBus; -public class ServiceBusNamespaceFeature(string name, ServiceBusSkuName sku = ServiceBusSkuName.Standard, ServiceBusSkuTier tier = ServiceBusSkuTier.Standard) : CloudMachineFeature +internal class ServiceBusNamespaceFeature(string name, ServiceBusSkuName sku = ServiceBusSkuName.Standard, ServiceBusSkuTier tier = ServiceBusSkuTier.Standard) : CloudMachineFeature { protected override ProvisionableResource EmitResources(CloudMachineInfrastructure infrastructure) { diff --git a/sdk/cloudmachine/Azure.Provisioning.CloudMachine/src/FeaturesBuiltIn/ServiceBusSubscriptionFeature.cs b/sdk/cloudmachine/Azure.Provisioning.CloudMachine/src/FeaturesBuiltIn/ServiceBusSubscriptionFeature.cs index dd757020c1844..72bacde5671fa 100644 --- a/sdk/cloudmachine/Azure.Provisioning.CloudMachine/src/FeaturesBuiltIn/ServiceBusSubscriptionFeature.cs +++ b/sdk/cloudmachine/Azure.Provisioning.CloudMachine/src/FeaturesBuiltIn/ServiceBusSubscriptionFeature.cs @@ -2,14 +2,14 @@ // Licensed under the MIT License. using System; +using Azure.CloudMachine.Core; using Azure.Core; -using Azure.Provisioning.CloudMachine; using Azure.Provisioning.Primitives; using Azure.Provisioning.ServiceBus; -namespace Azure.CloudMachine; +namespace Azure.CloudMachine.ServiceBus; -public class ServiceBusSubscriptionFeature(string name, ServiceBusTopicFeature parent) : CloudMachineFeature +internal class ServiceBusSubscriptionFeature(string name, ServiceBusTopicFeature parent) : CloudMachineFeature { protected override ProvisionableResource EmitResources(CloudMachineInfrastructure infrastructure) { diff --git a/sdk/cloudmachine/Azure.Provisioning.CloudMachine/src/FeaturesBuiltIn/ServiceBusTopicFeature.cs b/sdk/cloudmachine/Azure.Provisioning.CloudMachine/src/FeaturesBuiltIn/ServiceBusTopicFeature.cs index e547085e41375..77a72f98b5005 100644 --- a/sdk/cloudmachine/Azure.Provisioning.CloudMachine/src/FeaturesBuiltIn/ServiceBusTopicFeature.cs +++ b/sdk/cloudmachine/Azure.Provisioning.CloudMachine/src/FeaturesBuiltIn/ServiceBusTopicFeature.cs @@ -2,14 +2,14 @@ // Licensed under the MIT License. using System; +using Azure.CloudMachine.Core; using Azure.Core; -using Azure.Provisioning.CloudMachine; using Azure.Provisioning.Primitives; using Azure.Provisioning.ServiceBus; -namespace Azure.CloudMachine; +namespace Azure.CloudMachine.ServiceBus; -public class ServiceBusTopicFeature : CloudMachineFeature +internal class ServiceBusTopicFeature : CloudMachineFeature { public ServiceBusTopicFeature(string name, ServiceBusNamespaceFeature parent) { diff --git a/sdk/cloudmachine/Azure.Provisioning.CloudMachine/src/FeaturesBuiltIn/StorageAccountFeature.cs b/sdk/cloudmachine/Azure.Provisioning.CloudMachine/src/FeaturesBuiltIn/StorageAccountFeature.cs index 772ba9c7eaeb5..86c6714dfd3b7 100644 --- a/sdk/cloudmachine/Azure.Provisioning.CloudMachine/src/FeaturesBuiltIn/StorageAccountFeature.cs +++ b/sdk/cloudmachine/Azure.Provisioning.CloudMachine/src/FeaturesBuiltIn/StorageAccountFeature.cs @@ -1,18 +1,14 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -using System.Collections.Generic; -using System.Linq; using Azure.CloudMachine.Core; using Azure.Core; -using Azure.Provisioning; -using Azure.Provisioning.CloudMachine; using Azure.Provisioning.Expressions; using Azure.Provisioning.Primitives; using Azure.Provisioning.Resources; using Azure.Provisioning.Storage; -namespace Azure.CloudMachine; +namespace Azure.CloudMachine.Storage; internal class StorageAccountFeature : CloudMachineFeature { diff --git a/sdk/cloudmachine/Azure.Provisioning.CloudMachine/src/FeaturesBuiltIn/SystemTopicEventSubscriptionFeature.cs b/sdk/cloudmachine/Azure.Provisioning.CloudMachine/src/FeaturesBuiltIn/SystemTopicEventSubscriptionFeature.cs index ffc8fe92c4ee0..3a5d158980e5f 100644 --- a/sdk/cloudmachine/Azure.Provisioning.CloudMachine/src/FeaturesBuiltIn/SystemTopicEventSubscriptionFeature.cs +++ b/sdk/cloudmachine/Azure.Provisioning.CloudMachine/src/FeaturesBuiltIn/SystemTopicEventSubscriptionFeature.cs @@ -1,14 +1,15 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +using Azure.CloudMachine.Core; +using Azure.CloudMachine.ServiceBus; using Azure.Provisioning.Authorization; -using Azure.Provisioning.CloudMachine; using Azure.Provisioning.EventGrid; using Azure.Provisioning.Expressions; using Azure.Provisioning.Primitives; using Azure.Provisioning.ServiceBus; -namespace Azure.CloudMachine; +namespace Azure.CloudMachine.EventGrid; internal class SystemTopicEventSubscriptionFeature(string name, EventGridSystemTopicFeature parent, ServiceBusTopicFeature destination, ServiceBusNamespaceFeature parentNamespace) : CloudMachineFeature { diff --git a/sdk/cloudmachine/Azure.Provisioning.CloudMachine/src/FeaturesExtensions/AppServiceFeature.cs b/sdk/cloudmachine/Azure.Provisioning.CloudMachine/src/FeaturesExtensions/AppServiceFeature.cs index 83d771f27482c..4f9a308b1b6ee 100644 --- a/sdk/cloudmachine/Azure.Provisioning.CloudMachine/src/FeaturesExtensions/AppServiceFeature.cs +++ b/sdk/cloudmachine/Azure.Provisioning.CloudMachine/src/FeaturesExtensions/AppServiceFeature.cs @@ -1,11 +1,11 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -using Azure.Provisioning.CloudMachine; using Azure.Provisioning.Expressions; using Azure.Provisioning.AppService; using Azure.Provisioning.Primitives; using Azure.Provisioning.Resources; +using Azure.CloudMachine.Core; namespace Azure.CloudMachine.AppService; diff --git a/sdk/cloudmachine/Azure.Provisioning.CloudMachine/src/FeaturesExtensions/KeyVaultFeature.cs b/sdk/cloudmachine/Azure.Provisioning.CloudMachine/src/FeaturesExtensions/KeyVaultFeature.cs index 1e52c9d79ce2a..6b366260ec53c 100644 --- a/sdk/cloudmachine/Azure.Provisioning.CloudMachine/src/FeaturesExtensions/KeyVaultFeature.cs +++ b/sdk/cloudmachine/Azure.Provisioning.CloudMachine/src/FeaturesExtensions/KeyVaultFeature.cs @@ -1,9 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -using System; +using Azure.CloudMachine.Core; using Azure.Core; -using Azure.Provisioning.CloudMachine; using Azure.Provisioning.Expressions; using Azure.Provisioning.KeyVault; using Azure.Provisioning.Primitives; diff --git a/sdk/cloudmachine/Azure.Provisioning.CloudMachine/src/FeaturesExtensions/OpenAIFeature.cs b/sdk/cloudmachine/Azure.Provisioning.CloudMachine/src/FeaturesExtensions/OpenAIFeature.cs index 8ce12b0bf57a5..0e2a32898aa36 100644 --- a/sdk/cloudmachine/Azure.Provisioning.CloudMachine/src/FeaturesExtensions/OpenAIFeature.cs +++ b/sdk/cloudmachine/Azure.Provisioning.CloudMachine/src/FeaturesExtensions/OpenAIFeature.cs @@ -1,9 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -using System; -using System.Collections.Generic; + +using Azure.CloudMachine.Core; using Azure.Core; -using Azure.Provisioning.CloudMachine; using Azure.Provisioning.CognitiveServices; using Azure.Provisioning.Primitives; diff --git a/sdk/cloudmachine/Azure.Provisioning.CloudMachine/src/FeaturesExtensions/OpenAIModelFeature.cs b/sdk/cloudmachine/Azure.Provisioning.CloudMachine/src/FeaturesExtensions/OpenAIModelFeature.cs index 6efcbd3b98924..01f6e33cdcb5d 100644 --- a/sdk/cloudmachine/Azure.Provisioning.CloudMachine/src/FeaturesExtensions/OpenAIModelFeature.cs +++ b/sdk/cloudmachine/Azure.Provisioning.CloudMachine/src/FeaturesExtensions/OpenAIModelFeature.cs @@ -2,10 +2,9 @@ // Licensed under the MIT License. using System; -using System.Diagnostics; using System.Linq; +using Azure.CloudMachine.Core; using Azure.Core; -using Azure.Provisioning.CloudMachine; using Azure.Provisioning.CognitiveServices; using Azure.Provisioning.Primitives; diff --git a/sdk/cloudmachine/Azure.Provisioning.CloudMachine/src/GlobalSuppressions.cs b/sdk/cloudmachine/Azure.Provisioning.CloudMachine/src/GlobalSuppressions.cs index 4416e7cc32abf..af70f99778e7c 100644 --- a/sdk/cloudmachine/Azure.Provisioning.CloudMachine/src/GlobalSuppressions.cs +++ b/sdk/cloudmachine/Azure.Provisioning.CloudMachine/src/GlobalSuppressions.cs @@ -5,4 +5,4 @@ [assembly: SuppressMessage("Usage", "AZC0005:DO provide protected parameterless constructor for mocking.", Justification = "", Scope = "type", Target = "~T:Azure.CloudMachine.CloudMachineClient")] [assembly: SuppressMessage("Usage", "AZC0007:DO provide a minimal constructor that takes only the parameters required to connect to the service.", Justification = "", Scope = "member", Target = "~M:Azure.CloudMachine.CloudMachineClient.#ctor(Azure.Identity.DefaultAzureCredential,Microsoft.Extensions.Configuration.IConfiguration)")] -[assembly: SuppressMessage("Usage", "AZC0007:DO provide a minimal constructor that takes only the parameters required to connect to the service.", Justification = "", Scope = "member", Target = "~M:Azure.CloudMachine.CloudMachineClient.#ctor(Azure.Core.TokenCredential,Microsoft.Extensions.Configuration.IConfiguration)")] +[assembly: SuppressMessage("AZC0007:DO provide a minimal constructor that takes only the parameters required to connect to the service.", "Usage", Justification = "", Scope = "member", Target = "~M:Azure.CloudMachine.CloudMachineClient.#ctor(Azure.Core.TokenCredential,Microsoft.Extensions.Configuration.IConfiguration)")] diff --git a/sdk/cloudmachine/Azure.CloudMachine/src/Core/RestCLient/TokenCredentialAuthenticationPolicy.cs b/sdk/cloudmachine/Azure.Provisioning.CloudMachine/src/TokenCredentialAuthenticationPolicy.cs similarity index 96% rename from sdk/cloudmachine/Azure.CloudMachine/src/Core/RestCLient/TokenCredentialAuthenticationPolicy.cs rename to sdk/cloudmachine/Azure.Provisioning.CloudMachine/src/TokenCredentialAuthenticationPolicy.cs index 3cb1ae80ccd14..a2d4811fc8104 100644 --- a/sdk/cloudmachine/Azure.CloudMachine/src/Core/RestCLient/TokenCredentialAuthenticationPolicy.cs +++ b/sdk/cloudmachine/Azure.Provisioning.CloudMachine/src/TokenCredentialAuthenticationPolicy.cs @@ -1,7 +1,6 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -using Azure.Core; using System; using System.ClientModel.Primitives; using System.Collections.Generic; @@ -9,12 +8,12 @@ using System.Net; using System.Threading.Tasks; -namespace Azure.AI.OpenAI; +namespace Azure.Core; /// /// TokenCredentialAuthenticationPolicy is a pipeline policy that authenticates requests using a TokenCredential. /// -public partial class TokenCredentialAuthenticationPolicy : PipelinePolicy +internal partial class TokenCredentialAuthenticationPolicy : PipelinePolicy { private readonly TokenCredential _credential; private readonly string[] _scopes; @@ -99,7 +98,7 @@ private bool IsTokenFresh() private TokenRequestContext CreateRequestContext(PipelineRequest request) { - if (request.Headers.TryGetValue("x-ms-client-request-id", out string messageClientId)) + if (request.Headers.TryGetValue("x-ms-client-request-id", out string? messageClientId)) { return new TokenRequestContext(_scopes, messageClientId); } diff --git a/sdk/cloudmachine/Azure.Provisioning.CloudMachine/src/Tooling/Azd.cs b/sdk/cloudmachine/Azure.Provisioning.CloudMachine/src/Tooling/Azd.cs index 31c49bd3c1950..ce5ce5675935b 100644 --- a/sdk/cloudmachine/Azure.Provisioning.CloudMachine/src/Tooling/Azd.cs +++ b/sdk/cloudmachine/Azure.Provisioning.CloudMachine/src/Tooling/Azd.cs @@ -34,7 +34,7 @@ public static void Init(CloudMachineInfrastructure infra, string? infraDirectory Directory.CreateDirectory(infraDirectory); infra.Build().Save(infraDirectory); - var cmid = CloudMachineWorkspace.ReadOrCreateCloudMachineId(); + var cmid = CloudMachineClient.ReadOrCreateCloudMachineId(); // main.bicep var location = new ProvisioningParameter("location", typeof(string)); diff --git a/sdk/cloudmachine/Azure.Provisioning.CloudMachine/src/Tooling/CloudMachineCommands.cs b/sdk/cloudmachine/Azure.Provisioning.CloudMachine/src/Tooling/CloudMachineCommands.cs index 5d84fc3d91eb0..9419d1d65a6fb 100644 --- a/sdk/cloudmachine/Azure.Provisioning.CloudMachine/src/Tooling/CloudMachineCommands.cs +++ b/sdk/cloudmachine/Azure.Provisioning.CloudMachine/src/Tooling/CloudMachineCommands.cs @@ -7,30 +7,25 @@ using System.Collections.Generic; using System.IO; using System.Text.Json; -using Azure.AI.OpenAI; using Azure.Core; +using Azure.Core.Rest; using Azure.Identity; namespace Azure.CloudMachine; public static class CloudMachineCommands { - public static bool Execute(string[] args, Action? configure = default, bool exitProcessIfHandled = true) + public static bool TryExecuteCommand(this CloudMachineInfrastructure cmi, string[] args) { if (args.Length < 1) return false; - string cmid = CloudMachineWorkspace.ReadOrCreateCloudMachineId(); - CloudMachineInfrastructure cmi = new(cmid); - if (configure != default) - { - configure(cmi); - } + string cmid = CloudMachineClient.ReadOrCreateCloudMachineId(); if (args[0] == "-bicep") { Azd.Init(cmi); - return Handled(exitProcessIfHandled); + return true; } if (args[0] == "-init") @@ -43,30 +38,23 @@ public static bool Execute(string[] args, Action? co projName = args[1]; } Azd.InitDeployment(cmi, projName); - return Handled(exitProcessIfHandled); + return true; } if (args[0] == "-tsp") { GenerateTsp(cmi.Endpoints); - return Handled(exitProcessIfHandled); + return true; } if (args[0] == "-ai") { string? option = (args.Length > 1) ? args[1] : default; ListAzureOpenaAIModels(cmid, option); - return Handled(exitProcessIfHandled); + return true; } return false; - - static bool Handled(bool exitProcessIfHandled) - { - if (exitProcessIfHandled) - Environment.Exit(0); - return true; - } } // this implements: https://learn.microsoft.com/en-us/rest/api/azureopenai/models/list diff --git a/sdk/cloudmachine/Azure.Provisioning.CloudMachine/src/Tsp/TypeSpecWriter.cs b/sdk/cloudmachine/Azure.Provisioning.CloudMachine/src/Tsp/TypeSpecWriter.cs index 2b1c6af5713b5..5aa90be3907c4 100644 --- a/sdk/cloudmachine/Azure.Provisioning.CloudMachine/src/Tsp/TypeSpecWriter.cs +++ b/sdk/cloudmachine/Azure.Provisioning.CloudMachine/src/Tsp/TypeSpecWriter.cs @@ -240,8 +240,7 @@ private static string ToTspType(this Type type) if (type == typeof(double)) return "float64"; - // TODO: - // return "safeint" if long is attributed with [SafeInt] + // TODO: return "safeint" if long is attributed with [SafeInt] // arrays if (type.IsClass) diff --git a/sdk/cloudmachine/Azure.Provisioning.CloudMachine/tests/CommandsTests.cs b/sdk/cloudmachine/Azure.Provisioning.CloudMachine/tests/CommandsTests.cs index abf2c219752ef..c0bd9d479a060 100644 --- a/sdk/cloudmachine/Azure.Provisioning.CloudMachine/tests/CommandsTests.cs +++ b/sdk/cloudmachine/Azure.Provisioning.CloudMachine/tests/CommandsTests.cs @@ -1,6 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +using Azure.CloudMachine.KeyVault; using NUnit.Framework; namespace Azure.CloudMachine.Tests; @@ -11,12 +12,22 @@ public class CommandsTests [Test] public void ListModels() { - CloudMachineCommands.Execute(["-ai", "chat"], exitProcessIfHandled: false); + CloudMachineInfrastructure cm = new(); + cm.TryExecuteCommand(["-ai", "chat"]); + } + + [Test] + public void GenerateBicep() + { + CloudMachineInfrastructure cm = new(); + cm.AddFeature(new KeyVaultFeature()); + cm.TryExecuteCommand(["-bicep"]); } [Test] public void DoInit() { - CloudMachineCommands.Execute(["-init", "demo.csproj"], exitProcessIfHandled: false); + CloudMachineInfrastructure cm = new(); + cm.TryExecuteCommand(["-init", "demo.csproj"]); } }