Skip to content

Commit

Permalink
Use pyjq for macOS and Linux
Browse files Browse the repository at this point in the history
  • Loading branch information
zjinmei committed Nov 10, 2021
1 parent c57e4e0 commit d350f06
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 14 deletions.
15 changes: 10 additions & 5 deletions .github/workflows/pr-ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,16 @@ jobs:
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python }}
- name: Install JQ on windows
run: choco install jq
if: matrix.os == 'windows-latest'
- name: Install JQ on Macos
run: brew install jq
- name: Install PYJQ dependencies on Ubuntu
run: |
yum install autoconf automake libtool
pip install pyjq
if: matrix.os == 'ubuntu-latest'
- name: Install PYJQ dependencies on Macos
run: |
brew install autoconf automake libtool
brew install jq
pip install pyjq
if: matrix.os == 'macos-latest'
- name: Install dependencies
run: |
Expand Down
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,23 @@ cfn test --log-group-name cw_log_group --log-role-arn log_delivery_role_arn # Ha

Note: To use your type configuration in contract tests, you will need to save your type configuration json file in `~/.cfn-cli/typeConfiguration.json`.

When the resource type with propertyTransform in schema, need to install PYJQ firstly(contract tests propertyTransform is not available for Windows system)

For Linux

```bash
yum install autoconf automake libtool
pip install pyjq
```

For macOS

```bash
brew install autoconf automake libtool
brew install jq
pip install pyjq
```

### Command: validate

To validate the schema, use the `validate` command.
Expand Down
14 changes: 5 additions & 9 deletions src/rpdk/core/contract/resource_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import json
import logging
import re
import subprocess
import sys
import time
from time import sleep
from uuid import uuid4
Expand Down Expand Up @@ -236,18 +236,14 @@ def _update_schema(self, schema):
]

def transform_model(self, input_model):
if not self.property_transform:
if not self.property_transform or sys.platform.startswith("win"):
return None
import pyjq

for key in self.property_transform_keys:
path = "/" + "/".join(key)
expression = self.property_transform[path]
child_process = subprocess.Popen(
["jq", expression], stdin=subprocess.PIPE, stdout=subprocess.PIPE
)
child_process_output = child_process.communicate(
json.dumps(input_model).encode()
)[0]
tranformed_value = json.loads(child_process_output.decode())
tranformed_value = pyjq.first(expression, input_model)
input_model = self.update_property(input_model, tranformed_value, key[1:])

return input_model
Expand Down

0 comments on commit d350f06

Please sign in to comment.