Skip to content

Commit

Permalink
Reformat code (#14254)
Browse files Browse the repository at this point in the history
Update code to match the house style 😎

Co-authored-by: Bicep Automation <bicep@noreply.github.com>
  • Loading branch information
microsoft-github-policy-service[bot] and Bicep Automation authored Jun 10, 2024
1 parent 74502e2 commit 126cd59
Show file tree
Hide file tree
Showing 30 changed files with 148 additions and 122 deletions.
2 changes: 1 addition & 1 deletion src/Bicep.Cli/Arguments/PublishProviderArguments.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public PublishProviderArguments(string[] args) : base(Constants.Command.PublishP
i++;
break;

case {} when args[i].StartsWith("--bin-"):
case { } when args[i].StartsWith("--bin-"):
var architectureName = args[i].Substring("--bin-".Length);

if (!SupportedArchitectures.All.Any(x => x.Name == architectureName))
Expand Down
14 changes: 7 additions & 7 deletions src/Bicep.Cli/Commands/LocalDeployCommand.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using Bicep.Local.Deploy;
using Bicep.Local.Deploy.Extensibility;
using Azure.Deployments.Core.Json;
using Bicep.Cli.Arguments;
using Bicep.Cli.Helpers;
Expand All @@ -12,6 +10,8 @@
using Bicep.Core.Registry;
using Bicep.Core.Semantics;
using Bicep.Core.TypeSystem.Types;
using Bicep.Local.Deploy;
using Bicep.Local.Deploy.Extensibility;
using Bicep.Local.Extension.Rpc;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
Expand Down Expand Up @@ -53,8 +53,8 @@ public async Task<int> RunAsync(LocalDeployArguments args, CancellationToken can
var parameters = compilation.Emitter.Parameters();

if (summary.HasErrors ||
parameters.Parameters is not {} parametersString ||
parameters.Template?.Template is not {} templateString)
parameters.Parameters is not { } parametersString ||
parameters.Template?.Template is not { } templateString)
{
return 1;
}
Expand All @@ -76,15 +76,15 @@ parameters.Parameters is not {} parametersString ||

private async Task WriteSummary(LocalDeployment.Result result)
{
if (result.Deployment.Properties.Outputs is {} outputs)
if (result.Deployment.Properties.Outputs is { } outputs)
{
foreach (var output in outputs)
{
await io.Output.WriteLineAsync($"Output {output.Key}: {JsonConvert.SerializeObject(output.Value.Value, Formatting.Indented, SerializerSettings.SerializerObjectTypeSettings)}");
}
}

if (result.Deployment.Properties.Error is {} error)
if (result.Deployment.Properties.Error is { } error)
{
foreach (var subError in error.Details)
{
Expand All @@ -99,4 +99,4 @@ private async Task WriteSummary(LocalDeployment.Result result)

await io.Output.WriteLineAsync($"Result: {result.Deployment.Properties.ProvisioningState}");
}
}
}
2 changes: 1 addition & 1 deletion src/Bicep.Cli/Commands/PublishProviderCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public async Task<int> RunAsync(PublishProviderArguments args)
{
ProviderBinary? TryGetBinary(SupportedArchitecture architecture)
{
if (args.Binaries.TryGetValue(architecture.Name) is not {} binaryPath)
if (args.Binaries.TryGetValue(architecture.Name) is not { } binaryPath)
{
return null;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Bicep.Core/Emit/TemplateWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1223,10 +1223,10 @@ private void EmitModuleParameters(ExpressionEmitter emitter, DeclaredModuleExpre

private void EmitModuleForLocalDeploy(PositionTrackingJsonTextWriter jsonWriter, DeclaredModuleExpression module, ExpressionEmitter emitter)
{
emitter.EmitObject(() =>
emitter.EmitObject(() =>
{
emitter.EmitProperty("import", "az0synthesized");

var body = module.Body;
if (body is ForLoopExpression forLoop)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Bicep.Core/Registry/AzureContainerRegistryManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ private static async Task<OciArtifactResult> DownloadManifestAndLayersAsync(IOci
.Select(async layer => new OciArtifactLayer(layer.Digest, layer.MediaType, await PullLayerAsync(client, layer)));
var layers = await Task.WhenAll(layerTasks);

var config = !deserializedManifest.Config.IsEmpty() ?
var config = !deserializedManifest.Config.IsEmpty() ?
new OciArtifactLayer(deserializedManifest.Config.Digest, deserializedManifest.Config.MediaType, await PullLayerAsync(client, deserializedManifest.Config)) :
null;

Expand Down
24 changes: 12 additions & 12 deletions src/Bicep.Core/Registry/LocalModuleRegistry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
// Licensed under the MIT License.

using System.Diagnostics;
using System.IO.Abstractions;
using System.Runtime.InteropServices;
using Bicep.Core.Diagnostics;
using Bicep.Core.Features;
using Bicep.Core.FileSystem;
using Bicep.Core.Modules;
using Bicep.Core.Registry.Oci;
using Bicep.Core.Registry.Providers;
using Bicep.Core.Semantics;
using Bicep.Core.SourceCode;
using Bicep.Core.Utils;
using System.IO.Abstractions;
using Bicep.Core.Features;
using Bicep.Core.Registry.Oci;
using System.Runtime.InteropServices;

namespace Bicep.Core.Registry
{
Expand Down Expand Up @@ -80,7 +80,7 @@ public override ResultWithDiagnostic<Uri> TryGetLocalArtifactEntryPointUri(Local
{
if (reference.ArtifactType == ArtifactType.Provider)
{
if (TryReadContent(reference) is not {} binaryData)
if (TryReadContent(reference) is not { } binaryData)
{
statuses.Add(reference, x => x.ArtifactRestoreFailedWithMessage(reference.FullyQualifiedReference, $"Failed to find {reference.FullyQualifiedReference}"));
continue;
Expand Down Expand Up @@ -152,12 +152,12 @@ protected override void WriteArtifactContentToCache(LocalModuleReference referen
{
if (entity.Provider.LocalDeployEnabled)
{
if (SupportedArchitectures.TryGetCurrent() is not {} architecture)
if (SupportedArchitectures.TryGetCurrent() is not { } architecture)
{
throw new InvalidOperationException($"Unsupported architecture: {RuntimeInformation.ProcessArchitecture}");
}

if (entity.Provider.Binaries.SingleOrDefault(x => x.Architecture.Name == architecture.Name) is not {} binary)
if (entity.Provider.Binaries.SingleOrDefault(x => x.Architecture.Name == architecture.Name) is not { } binary)
{
throw new InvalidOperationException($"Unsupported architecture: {RuntimeInformation.ProcessArchitecture}");
}
Expand All @@ -176,7 +176,7 @@ protected override void WriteArtifactContentToCache(LocalModuleReference referen

protected override string GetArtifactDirectoryPath(LocalModuleReference reference)
{
if (TryReadContent(reference) is not {} binaryData)
if (TryReadContent(reference) is not { } binaryData)
{
throw new InvalidOperationException($"Failed to resolve file path for {reference.FullyQualifiedReference}");
}
Expand All @@ -193,21 +193,21 @@ protected override string GetArtifactDirectoryPath(LocalModuleReference referenc

private BinaryData? TryReadContent(LocalModuleReference reference)
{
if (FileResolver.TryResolveFilePath(reference.ParentModuleUri, reference.Path) is not {} fileUri ||
FileResolver.TryReadAsBinaryData(fileUri).TryUnwrap() is not {} binaryData)
if (FileResolver.TryResolveFilePath(reference.ParentModuleUri, reference.Path) is not { } fileUri ||
FileResolver.TryReadAsBinaryData(fileUri).TryUnwrap() is not { } binaryData)
{
return null;
}

return binaryData;
}

private Uri GetTypesTgzUri(LocalModuleReference reference) => GetFileUri(reference, "types.tgz");

private Uri GetProviderBinUri(LocalModuleReference reference) => GetFileUri(reference, "provider.bin");

protected override Uri GetArtifactLockFileUri(LocalModuleReference reference) => GetFileUri(reference, "lock");

private Uri GetFileUri(LocalModuleReference reference, string path)
=> new(FileSystem.Path.Combine(this.GetArtifactDirectoryPath(reference), path), UriKind.Absolute);
}
Expand Down
5 changes: 3 additions & 2 deletions src/Bicep.Core/Registry/Oci/OciProvidersV1Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ public static class SupportedArchitectures

public static SupportedArchitecture? TryGetCurrent()
{
return RuntimeInformation.ProcessArchitecture switch {
return RuntimeInformation.ProcessArchitecture switch
{
Architecture.X64 when RuntimeInformation.IsOSPlatform(OSPlatform.Linux) => LinuxX64,
Architecture.Arm64 when RuntimeInformation.IsOSPlatform(OSPlatform.Linux) => LinuxArm64,
Architecture.X64 when RuntimeInformation.IsOSPlatform(OSPlatform.OSX) => OsxX64,
Expand All @@ -69,4 +70,4 @@ Architecture.Arm64 when RuntimeInformation.IsOSPlatform(OSPlatform.Windows) => W
_ => null,
};
}
}
}
6 changes: 3 additions & 3 deletions src/Bicep.Core/Registry/OciArtifactRegistry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -402,20 +402,20 @@ protected override void WriteArtifactContentToCache(OciArtifactReference referen

if (result is OciProviderArtifactResult providerArtifact)
{
var config = providerArtifact.Config is {} ?
var config = providerArtifact.Config is { } ?
JsonSerializer.Deserialize(providerArtifact.Config.Data, OciProvidersV1ConfigSerializationContext.Default.OciProvidersV1Config) :
null;

// if the artifact supports local deployment, fetch the provider binary
if (config?.LocalDeployEnabled == true)
{
if (SupportedArchitectures.TryGetCurrent() is not {} architecture)
if (SupportedArchitectures.TryGetCurrent() is not { } architecture)
{
throw new InvalidOperationException($"Unsupported architecture: {RuntimeInformation.ProcessArchitecture}");
}

var layerName = BicepMediaTypes.GetProviderArtifactLayerV1Binary(architecture);
if (result.TryGetSingleLayerByMediaType(layerName) is not {} sourceData)
if (result.TryGetSingleLayerByMediaType(layerName) is not { } sourceData)
{
throw new InvalidOperationException($"Unsupported architecture: {RuntimeInformation.ProcessArchitecture}");
}
Expand Down
2 changes: 1 addition & 1 deletion src/Bicep.Core/Registry/Providers/ProviderV1Archive.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public static ProviderPackage Read(BinaryData binaryData)
binaries.Add(new(architecture, binary));
}
}

return new(
Types: dataDict["types.tgz"],
LocalDeployEnabled: binaries.Count != 0,
Expand Down
26 changes: 14 additions & 12 deletions src/Bicep.Local.Deploy.IntegrationTests/EndToEndDeploymentTests.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using System.IO.Abstractions;
using Azure.Deployments.Core.Definitions;
using Azure.Deployments.Extensibility.Messages;
using Bicep.Core.UnitTests;
using Bicep.Core.UnitTests.Assertions;
using FluentAssertions;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Bicep.Local.Deploy.Extensibility;
using Bicep.Local.Deploy;
using Bicep.Core.UnitTests.Features;
using Bicep.Core.UnitTests.Mock;
using Bicep.Core.UnitTests.Utils;
using Azure.Deployments.Core.Definitions;
using Bicep.Local.Deploy;
using Bicep.Local.Deploy.Extensibility;
using Bicep.Local.Extension;
using FluentAssertions;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
using Bicep.Core.UnitTests.Mock;
using Bicep.Core.UnitTests.Features;
using System.IO.Abstractions;
using Azure.Deployments.Extensibility.Messages;
using Newtonsoft.Json.Linq;

namespace Bicep.Local.Deploy.IntegrationTests;
Expand Down Expand Up @@ -88,7 +88,8 @@ param coords {

var providerMock = StrictMock.Of<LocalExtensibilityProvider>();
providerMock.Setup(x => x.Save(It.Is<ExtensibilityOperationRequest>(req => req.Resource.Properties["uri"]!.ToString() == "https://api.weather.gov/points/47.6363726,-122.1357068"), It.IsAny<CancellationToken>()))
.Returns<ExtensibilityOperationRequest, CancellationToken>((req, _) => {
.Returns<ExtensibilityOperationRequest, CancellationToken>((req, _) =>
{
req.Resource.Properties["body"] = """
{
"properties": {
Expand All @@ -102,7 +103,8 @@ param coords {
return Task.FromResult<ExtensibilityOperationResponse>(new(req.Resource, null, null));
});
providerMock.Setup(x => x.Save(It.Is<ExtensibilityOperationRequest>(req => req.Resource.Properties["uri"]!.ToString() == "https://api.weather.gov/gridpoints/SEW/131,68/forecast"), It.IsAny<CancellationToken>()))
.Returns<ExtensibilityOperationRequest, CancellationToken>((req, _) => {
.Returns<ExtensibilityOperationRequest, CancellationToken>((req, _) =>
{
req.Resource.Properties["body"] = """
{
"properties": {
Expand Down Expand Up @@ -144,4 +146,4 @@ param coords {
]
"""));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
// Licensed under the MIT License.

using Bicep.Local.Extension;
using Bicep.Local.Extension.Rpc;
using Bicep.Local.Extension.Protocol;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Bicep.Local.Extension.Rpc;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Server.Kestrel.Core;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Bicep.Local.Deploy.IntegrationTests;

Expand All @@ -33,4 +33,4 @@ protected override async Task RunServer(string socketPath, ResourceDispatcher di

await app.RunAsync();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@
using Bicep.Core.UnitTests.Assertions;
using Bicep.Core.UnitTests.Mock;
using Bicep.Local.Extension;
using Bicep.Local.Extension.Rpc;
using Bicep.Local.Extension.Protocol;
using Bicep.Local.Extension.Rpc;
using FluentAssertions;
using Grpc.Core;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.WindowsAzure.ResourceStack.Common.Json;
using Moq;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Serialization;
using Protocol = Bicep.Local.Extension.Protocol;
using OmniSharp.Extensions.JsonRpc;
using Grpc.Core;
using Protocol = Bicep.Local.Extension.Protocol;

namespace Bicep.Local.Deploy.IntegrationTests;

Expand Down Expand Up @@ -64,7 +64,7 @@ public async Task Save_request_works_as_expected()
handlerMock.SetupGet(x => x.ResourceType).Returns("apps/Deployment@v1");

handlerMock.Setup(x => x.Save(It.IsAny<Protocol.ExtensibilityOperationRequest>(), It.IsAny<CancellationToken>()))
.Returns<Protocol.ExtensibilityOperationRequest, CancellationToken>((req, _) =>
.Returns<Protocol.ExtensibilityOperationRequest, CancellationToken>((req, _) =>
Task.FromResult(new Protocol.ExtensibilityOperationResponse(req.Resource, null, null)));

await RunExtensionTest(
Expand All @@ -73,7 +73,8 @@ await RunExtensionTest(
{
var request = new Extension.Rpc.ExtensibilityOperationRequest
{
Import = new() {
Import = new()
{
Provider = "Kubernetes",
Version = "1.0.0",
Config = """
Expand All @@ -83,7 +84,8 @@ await RunExtensionTest(
}
"""
},
Resource = new() {
Resource = new()
{
Type = "apps/Deployment@v1",
Properties = """
{
Expand Down
Loading

0 comments on commit 126cd59

Please sign in to comment.