-
Notifications
You must be signed in to change notification settings - Fork 778
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add 'localDeploy' experimental feature, base extension nuget library
- Loading branch information
1 parent
6dd8bf7
commit c6804d8
Showing
22 changed files
with
776 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<AssemblyName>Azure.Bicep.Local.Extension</AssemblyName> | ||
<RootNamespace>Bicep.Local.Extension</RootNamespace> | ||
<EnableNuget>true</EnableNuget> | ||
<PackageTags>Azure;ResourceManager;ARM;Deployments;Templates;Bicep</PackageTags> | ||
<Description> | ||
Bicep compiler extension functionality. | ||
The Bicep team has made this NuGet package publicly available on nuget.org. While it is public, it is not a supported package. Any dependency you take on this package will be done at your own risk and we reserve the right to push breaking changes to this package at any time. | ||
</Description> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<Protobuf Include="extension.proto" GrpcServices="Both" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="CommandLineParser" Version="2.9.1" /> | ||
<PackageReference Include="Grpc.AspNetCore" Version="2.62.0" /> | ||
</ItemGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
using System.Collections.Immutable; | ||
using System.Text.Json.Nodes; | ||
using System.Text.Json.Serialization.Metadata; | ||
|
||
namespace Bicep.Local.Extension.Protocol; | ||
|
||
public record ExtensibilityOperationRequest( | ||
ExtensibleImportData Import, | ||
ExtensibleResourceData Resource); | ||
|
||
public record ExtensibilityOperationResponse( | ||
ExtensibleResourceData? Resource, | ||
ExtensibleResourceMetadata? ResourceMetadata, | ||
ImmutableArray<ExtensibilityError>? Errors); | ||
|
||
public record ExtensibleImportData( | ||
string Provider, | ||
string Version, | ||
JsonObject? Config); | ||
|
||
public record ExtensibleResourceData( | ||
string Type, | ||
JsonObject? Properties); | ||
|
||
public record ExtensibleResourceMetadata( | ||
ImmutableArray<string>? ReadOnlyProperties, | ||
ImmutableArray<string>? ImmutableProperties, | ||
ImmutableArray<string>? DynamicProperties); | ||
|
||
public record ExtensibilityError( | ||
string Code, | ||
string Message, | ||
string Target); | ||
|
||
public interface IGenericResourceHandler | ||
{ | ||
Task<ExtensibilityOperationResponse> Save( | ||
ExtensibilityOperationRequest request, | ||
CancellationToken cancellationToken); | ||
|
||
Task<ExtensibilityOperationResponse> PreviewSave( | ||
ExtensibilityOperationRequest request, | ||
CancellationToken cancellationToken); | ||
|
||
Task<ExtensibilityOperationResponse> Get( | ||
ExtensibilityOperationRequest request, | ||
CancellationToken cancellationToken); | ||
|
||
Task<ExtensibilityOperationResponse> Delete( | ||
ExtensibilityOperationRequest request, | ||
CancellationToken cancellationToken); | ||
} | ||
|
||
public interface IResourceHandler : IGenericResourceHandler | ||
{ | ||
string ResourceType { get; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
using System.Collections.Immutable; | ||
|
||
namespace Bicep.Local.Extension.Protocol; | ||
|
||
public class ResourceDispatcher | ||
{ | ||
private readonly IGenericResourceHandler? genericResourceHandler; | ||
private readonly ImmutableDictionary<string, IResourceHandler> resourceHandlers; | ||
|
||
public ResourceDispatcher( | ||
IGenericResourceHandler? genericResourceHandler, | ||
ImmutableDictionary<string, IResourceHandler> resourceHandlers) | ||
{ | ||
this.genericResourceHandler = genericResourceHandler; | ||
this.resourceHandlers = resourceHandlers; | ||
} | ||
|
||
public IGenericResourceHandler GetHandler(string resourceType) | ||
{ | ||
if (this.resourceHandlers.TryGetValue(resourceType, out var handler)) | ||
{ | ||
return handler; | ||
} | ||
|
||
if (this.genericResourceHandler is {}) | ||
{ | ||
return this.genericResourceHandler; | ||
} | ||
|
||
throw new ArgumentException($"Resource type '{resourceType}' is not supported."); | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
src/Bicep.Local.Extension/Protocol/ResourceDispatcherBuilder.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
using System.Collections.Immutable; | ||
|
||
namespace Bicep.Local.Extension.Protocol; | ||
|
||
public class ResourceDispatcherBuilder | ||
{ | ||
private IGenericResourceHandler? genericResourceHandler; | ||
private readonly Dictionary<string, IResourceHandler> resourceHandlers = new(StringComparer.OrdinalIgnoreCase); | ||
|
||
public ResourceDispatcherBuilder AddHandler(IResourceHandler handler) | ||
{ | ||
if (!this.resourceHandlers.TryAdd(handler.ResourceType, handler)) | ||
{ | ||
throw new ArgumentException($"Resource type '{handler.ResourceType}' has already been registered."); | ||
} | ||
|
||
this.resourceHandlers[handler.ResourceType] = handler; | ||
return this; | ||
} | ||
|
||
public ResourceDispatcherBuilder AddGenericHandler(IGenericResourceHandler handler) | ||
{ | ||
if (this.genericResourceHandler is not null) | ||
{ | ||
throw new ArgumentException($"Generic resource handler has already been registered."); | ||
} | ||
|
||
this.genericResourceHandler = handler; | ||
return this; | ||
} | ||
|
||
public ResourceDispatcher Build() | ||
{ | ||
return new( | ||
this.genericResourceHandler, | ||
this.resourceHandlers.ToImmutableDictionary(StringComparer.OrdinalIgnoreCase)); | ||
} | ||
} |
Oops, something went wrong.