Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception calling application: Object of type StackValidationArgs is not JSON serializable #295

Open
rshade opened this issue Oct 6, 2022 · 2 comments
Labels
kind/enhancement Improvements or new features language/python

Comments

@rshade
Copy link

rshade commented Oct 6, 2022

Hello!

  • Vote on this issue by adding a 👍 reaction
  • If you want to implement this feature, comment to let us know (we'll work with you on design, scheduling, etc.)

Issue details

I would like the stack in policies to be serializable to a file so I can call an external application against it(snyk,checkov,infracost) and report violations back via status code.

Affected area/feature

@rshade rshade added kind/enhancement Improvements or new features needs-triage Needs attention from the triage team labels Oct 6, 2022
@Frassle Frassle added language/python and removed needs-triage Needs attention from the triage team labels Oct 6, 2022
@Frassle
Copy link
Member

Frassle commented Oct 6, 2022

Pythons json.dump by default doesn't support user classes. We think we could add a __dict__ method to these types (they are just data containers) to get json.dump to accept it (possibly look at data classes, they might just do this for free).

@rshade
Copy link
Author

rshade commented Oct 6, 2022

I tried this also:

from pulumi_policy import (
    EnforcementLevel,
    PolicyPack,
    ReportViolation,
    StackValidationArgs,
    StackValidationPolicy,
)
import os
import json

required_region = "us-west-1"
max_num_buckets = 1

def s3_region_check_validator(stack: StackValidationArgs, report_violation: ReportViolation):
    resources = []
    t = open("demo.json", "a")
    t.write(json.dumps(stack.__dict__))

s3_region_check = StackValidationPolicy(
    name="s3-region-check",
    description= "Checks the region the bucket was deployed in.",
    validate=s3_region_check_validator
)

PolicyPack(
    name="aws-python",
    enforcement_level=EnforcementLevel.ADVISORY,
    policies=[
        s3_region_check,
    ],
)

I get the same error:

Diagnostics:
  pulumi:pulumi:Stack (test-project-dev):
    error: Exception calling application: Object of type PolicyResource is not JSON serializable```

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/enhancement Improvements or new features language/python
Projects
None yet
Development

No branches or pull requests

2 participants