pulumi / pulumi-policy

Pulumi's Policy as Code SDK, CrossGuard. Define infrastructure checks in code to enforce security, compliance, cost, and other practices, enforced at deployment time.
https://www.pulumi.com/docs/guides/crossguard/
Apache License 2.0
31 stars 4 forks source link

Python policy packs produce error when using verbose logging #350

Closed pierskarsenbarg closed 1 month ago

pierskarsenbarg commented 1 month ago

What happened?

I have a basic pulumi program with a python policy: https://github.com/pierskarsenbarg/policy-pack-logging-bug

I published the pack to the Demo org in Pulumi cloud and added the above stack to a policy group.

When I run either a preview or an update with logging turned on (i.e. pulumi up --logtostderr --logflow -v=10 2> out.txt) I get the following error:

I0517 09:36:21.421334   92949 main.go:309] one or more errors while discovering plugins: 2 errors occurred:
        * unmarshaling package.json /Users/piers/go/src/github.com/pierskarsenbarg/scratchpad/policy-pack-logging/node_modules/resolve/test/resolver/false_main/package.json: json: cannot unmarshal bool into Go struct field packageJSON.main of type string
        * unmarshaling package.json /Users/piers/go/src/github.com/pierskarsenbarg/scratchpad/policy-pack-logging/node_modules/resolve/test/resolver/invalid_main/package.json: json: cannot unmarshal array into Go struct field packageJSON.main of type string

    error: Program failed with an unhandled exception:
    Traceback (most recent call last):
      File "/Users/piers/.pulumi/policies/demo/pulumi-analyzer-piers-policy-test-v0.0.2/venv/lib/python3.12/site-packages/pulumi/policy/__main__.py", line 61, in main
        runpy.run_path(program, run_name="__main__")
      File "<frozen runpy>", line 285, in run_path
      File "<frozen runpy>", line 254, in _get_code_from_file
    FileNotFoundError: [Errno 2] No such file or directory: '/Users/piers/.pulumi/policies/demo/pulumi-analyzer-piers-policy-test-v0.0.2/-v=10'

(it looks like the -v=10 is being added to the file path for the policy pack)

Example

See above

Output of pulumi about

CLI
Version      3.115.2
Go Version   go1.22.2
Go Compiler  gc

Plugins
KIND      NAME    VERSION
resource  aws     6.36.0
resource  awsx    2.10.0
resource  docker  4.5.3
resource  docker  3.6.1
language  nodejs  unknown

Host
OS       darwin
Version  14.4.1
Arch     arm64

This project is written in nodejs: executable='/Users/piers/.nvm/versions/node/v20.11.1/bin/node' version='v20.11.1'

Current Stack: demo/policy-pack-logging/dev

Found no resources associated with demo/dev

Found no pending operations associated with demo/dev

Backend
Name           pulumi.com
URL            https://app.pulumi.com/pierskarsenbarg
User           pierskarsenbarg
Organizations  pierskarsenbarg, karsenbarg, team-ce, gitlab-test-piers, demo
Token type     personal

Dependencies:
NAME            VERSION
@pulumi/aws     6.36.0
@pulumi/awsx    2.10.0
@pulumi/pulumi  3.116.1
@types/node     18.19.33
typescript      5.4.5

Pulumi locates its logs in /var/folders/x8/cdd9j87s607fwpy0q62mfmmw0000gn/T/ by default

Additional context

No response

Contributing

Vote on this issue by adding a 👍 reaction. To contribute a fix for this issue, leave a comment (and link to your pull request, if you've opened one already).

pierskarsenbarg commented 1 month ago

The same process with a typescript policy doesn't have the same problem so looks like it's a python thing.

pierskarsenbarg commented 1 month ago

Closing as duplicate of pulumi/pulumi#11092