Skip to content

Commit

Permalink
Merge pull request #1 from aws/master
Browse files Browse the repository at this point in the history
Catch up
  • Loading branch information
jeastham1993 committed Sep 15, 2022
2 parents e39962d + c12bba8 commit 23abd2d
Show file tree
Hide file tree
Showing 28 changed files with 647 additions and 115 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<AssemblyVersion>0.7.0.0</AssemblyVersion>
<AssemblyVersion>0.8.0.0</AssemblyVersion>
<TargetFramework>netstandard2.0</TargetFramework>

<!-- This is required to allow copying all the dependencies to bin directory which can be copied after to nuget package based on nuspec -->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;
using Amazon.Lambda.Annotations.APIGateway;
using Amazon.Lambda.Annotations.SourceGenerator.Diagnostics;
Expand All @@ -20,6 +21,9 @@ namespace Amazon.Lambda.Annotations.SourceGenerator.Writers
public class CloudFormationWriter : IAnnotationReportWriter
{
private const string CREATION_TOOL = "Amazon.Lambda.Annotations";
private const string PARAMETERS = "Parameters";
private const string GET_ATTRIBUTE = "Fn::GetAtt";
private const string REF = "Ref";

private readonly IFileManager _fileManager;
private readonly IDirectoryManager _directoryManager;
Expand Down Expand Up @@ -113,7 +117,7 @@ private void ProcessLambdaFunctionProperties(ILambdaFunctionSerializable lambdaF

if (!string.IsNullOrEmpty(lambdaFunction.Role))
{
_templateWriter.SetToken($"{propertiesPath}.Role", _templateWriter.GetValueOrRef(lambdaFunction.Role));
ProcessLambdaFunctionRole(lambdaFunction, $"{propertiesPath}.Role");
_templateWriter.RemoveToken($"{propertiesPath}.Policies");
}

Expand Down Expand Up @@ -292,5 +296,33 @@ private void RemoveOrphanedLambdaFunctions(HashSet<string> processedLambdaFuncti
_templateWriter.RemoveToken($"Resources.{resourceName}");
}
}

/// <summary>
/// Write the IAM role associated with the Lambda function.
/// The IAM role is specified under 'Resources.FUNCTION_NAME.Properties.Role' path.
/// </summary>
private void ProcessLambdaFunctionRole(ILambdaFunctionSerializable lambdaFunction, string rolePath)
{
if (string.IsNullOrEmpty(lambdaFunction.Role))
{
return;
}

if (!lambdaFunction.Role.StartsWith("@"))
{
_templateWriter.SetToken(rolePath, lambdaFunction.Role);
return;
}

var role = lambdaFunction.Role.Substring(1);
if (_templateWriter.Exists($"{PARAMETERS}.{role}"))
{
_templateWriter.SetToken($"{rolePath}.{REF}", role);
}
else
{
_templateWriter.SetToken($"{rolePath}.{GET_ATTRIBUTE}", new List<string>{role, "Arn"}, TokenType.List);
}
}
}
}
8 changes: 5 additions & 3 deletions Libraries/src/Amazon.Lambda.Annotations.nuspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>Amazon.Lambda.Annotations</id>
<version>0.7.0-preview</version>
<version>0.8.0-preview</version>
<authors>Amazon Web Services</authors>
<tags>AWS Amazon Lambda</tags>
<description>Annotations that can be added to Lambda projects to generate C# code and CloudFormation templates.</description>
Expand All @@ -16,11 +16,13 @@
</metadata>

<files>
<file src="..\..\icon.png" target="images\" />
<file src="Amazon.Lambda.Annotations\README.md" target="docs\" />
<file src="..\..\icon.png" target="images\" />
<file src="Amazon.Lambda.Annotations\README.md" target="docs\" />
<file src="Amazon.Lambda.Annotations\THIRD_PARTY_LICENSES" target="THIRD_PARTY_LICENSES" />

<!-- Dependencies to make sure attributes are available in consuming csproj, this ensures packaged version of customer code have all the dependencies needed. -->
<file src="Amazon.Lambda.Annotations\bin\Release\netstandard2.0\Amazon.Lambda.Annotations.dll" target="lib/net6.0" />
<file src="Amazon.Lambda.Annotations\bin\Release\netstandard2.0\Amazon.Lambda.Annotations.xml" target="lib/net6.0" />

<!-- Include every dependency manually for analyzer, whenever a new dependency is added, it has to be added here. -->
<!-- NOTE: Project dependencies should come from their own bin folder to make sure a code signed binary is packed -->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<AssemblyVersion>0.7.0.0</AssemblyVersion>
<AssemblyVersion>0.8.0.0</AssemblyVersion>
<TargetFramework>netstandard2.0</TargetFramework>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>

</Project>
Loading

0 comments on commit 23abd2d

Please sign in to comment.