Brightspace / serverless-plugin-for-each

Serverless plugin that adds $forEach syntax to reduce code duplication and allow creating dynamic templates
Apache License 2.0
1 stars 5 forks source link

Changed from string delimiter based paths to array based paths #47

Open mikkelramlov opened 1 year ago

mikkelramlov commented 1 year ago

Problem The main function: findAndReplace(obj, path) takes a string as path and relies on period as delimiter. That works well in most cases except when a key consist of a name with periods in it. My example is this:

  GithubActionRole:
    Type: AWS::IAM::Role
    Properties:
      RoleName: GithubActionRole
      AssumeRolePolicyDocument:
        Version: '2012-10-17'
        Statement:
          - Effect: Allow
            Principal:
              Federated: !Ref OIDCProvider
            Action: sts:AssumeRoleWithWebIdentity
            Condition:
              StringEquals:
                token.actions.githubusercontent.com:aud: sts.amazonaws.com
              StringLike:
                token.actions.githubusercontent.com:sub:
                  - $forEach:
                      iterator: ${self:custom.sourceRepos}
                      template:
                        - 'repo:$forEach.value:*'

Notice

token.actions.githubusercontent.com:sub

in the Condition statement.

Solution

Utilize the lodash.get capability to use Array as path to a given property.