pycfmodel


Namepycfmodel JSON
Version 0.22.0 PyPI version JSON
download
home_pagehttps://github.com/Skyscanner/pycfmodel
SummaryA python model for CloudFormation scripts
upload_time2024-02-08 16:37:02
maintainer
docs_urlNone
authorSkyscanner Product Security
requires_python>=3.7
license
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # pycfmodel

![Build Status](https://github.com/Skyscanner/pycfmodel/workflows/PyPI%20release/badge.svg)
[![PyPI version](https://badge.fury.io/py/pycfmodel.svg)](https://badge.fury.io/py/pycfmodel)
[![Documentation Status](https://readthedocs.org/projects/pycfmodel/badge/?version=latest)](https://pycfmodel.readthedocs.io/en/latest/?badge=latest)
![License](https://img.shields.io/github/license/skyscanner/pycfmodel)

*A python model for Cloud Formation scripts.*

**pycfmodel** makes it easier to work with CloudFormation scripts in Python by
creating a model comprised of python objects. Objects have various helper
functions which help with performing common tasks related to parsing and
inspecting CloudFormation scripts.

`pip install pycfmodel`

## Currently Supported

* AWSTemplateFormatVersion
* Conditions
* Description
* Mappings
* Metadata
* Outputs
* Parameters
* Resources:
    * Properties:
        * Policy
        * Policy Document
        * Principal
        * Security Group Egress Prop
        * Security Group Ingress Prop
        * Statement
        * Tag
    * EC2 VPC Endpoint Policy
    * Generic Resource
    * IAM Group
    * IAM Managed Policy
    * IAM Policy
    * IAM Role
    * IAM User
    * KMS Key
    * OpenSearch Service (legacy ElasticSearch resource)
        * Elasticsearch Domain
    * OpenSearch Service
        * OpenSearchService Domain
    * S3 Bucket
    * S3 Bucket Policy
    * Security Group
    * Security Group Egress
    * Security Group Ingress
    * SNS Topic Policy
    * SQS Queue Policy
* Transform

## Example

```python
from pycfmodel import parse

template = {
    "AWSTemplateFormatVersion": "2010-09-09",
    "Parameters": {"StarParameter": {"Type": "String", "Default": "*", "Description": "Star Param"}},
    "Resources": {
        "rootRole": {
            "Type": "AWS::IAM::Role",
            "Properties": {
                "AssumeRolePolicyDocument": {
                    "Version": "2012-10-17",
                    "Statement": [
                        {
                            "Effect": "Allow",
                            "Principal": {"AWS": {"Fn::Sub": "arn:aws:iam::${AWS::AccountId}:root"}},
                            "Action": ["sts:AssumeRole"],
                        }
                    ],
                },
                "Path": "/",
                "Policies": [
                    {
                        "PolicyName": "root",
                        "PolicyDocument": {
                            "Version": "2012-10-17",
                            "Statement": [
                                {
                                    "Effect": "Allow",
                                    "Action": {"Ref": "StarParameter"},
                                    "Resource": {"Ref": "StarParameter"},
                                }
                            ],
                        },
                    }
                ],
            },
        }
    },
}

model = parse(template).resolve(extra_params={"AWS::AccountId": "123"})
rootRole = model.Resources["rootRole"]
policy = rootRole.Properties.Policies[0]
statement = policy.PolicyDocument.Statement[0]

assert statement.Action == "*"
assert statement.Resource == "*"
assert rootRole.Properties.AssumeRolePolicyDocument.Statement[0].Principal == {"AWS": "arn:aws:iam::123:root"}
```

## Local Development Commands

```bash
make install-dev
make coverage
make test
make freeze
```

If the test `tests/test_constants.py::test_cloudformation_actions` is failing, it can be resolved by updating the known
AWS Actions:

```bash
python3 scripts/generate_cloudformation_actions_file.py
```



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/Skyscanner/pycfmodel",
    "name": "pycfmodel",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": "",
    "keywords": "",
    "author": "Skyscanner Product Security",
    "author_email": "security@skyscanner.net",
    "download_url": "https://files.pythonhosted.org/packages/de/7a/bab391457bd63298866854a203d243e794f779d933b468211712c62f84fb/pycfmodel-0.22.0.tar.gz",
    "platform": null,
    "description": "# pycfmodel\n\n![Build Status](https://github.com/Skyscanner/pycfmodel/workflows/PyPI%20release/badge.svg)\n[![PyPI version](https://badge.fury.io/py/pycfmodel.svg)](https://badge.fury.io/py/pycfmodel)\n[![Documentation Status](https://readthedocs.org/projects/pycfmodel/badge/?version=latest)](https://pycfmodel.readthedocs.io/en/latest/?badge=latest)\n![License](https://img.shields.io/github/license/skyscanner/pycfmodel)\n\n*A python model for Cloud Formation scripts.*\n\n**pycfmodel** makes it easier to work with CloudFormation scripts in Python by\ncreating a model comprised of python objects. Objects have various helper\nfunctions which help with performing common tasks related to parsing and\ninspecting CloudFormation scripts.\n\n`pip install pycfmodel`\n\n## Currently Supported\n\n* AWSTemplateFormatVersion\n* Conditions\n* Description\n* Mappings\n* Metadata\n* Outputs\n* Parameters\n* Resources:\n    * Properties:\n        * Policy\n        * Policy Document\n        * Principal\n        * Security Group Egress Prop\n        * Security Group Ingress Prop\n        * Statement\n        * Tag\n    * EC2 VPC Endpoint Policy\n    * Generic Resource\n    * IAM Group\n    * IAM Managed Policy\n    * IAM Policy\n    * IAM Role\n    * IAM User\n    * KMS Key\n    * OpenSearch Service (legacy ElasticSearch resource)\n        * Elasticsearch Domain\n    * OpenSearch Service\n        * OpenSearchService Domain\n    * S3 Bucket\n    * S3 Bucket Policy\n    * Security Group\n    * Security Group Egress\n    * Security Group Ingress\n    * SNS Topic Policy\n    * SQS Queue Policy\n* Transform\n\n## Example\n\n```python\nfrom pycfmodel import parse\n\ntemplate = {\n    \"AWSTemplateFormatVersion\": \"2010-09-09\",\n    \"Parameters\": {\"StarParameter\": {\"Type\": \"String\", \"Default\": \"*\", \"Description\": \"Star Param\"}},\n    \"Resources\": {\n        \"rootRole\": {\n            \"Type\": \"AWS::IAM::Role\",\n            \"Properties\": {\n                \"AssumeRolePolicyDocument\": {\n                    \"Version\": \"2012-10-17\",\n                    \"Statement\": [\n                        {\n                            \"Effect\": \"Allow\",\n                            \"Principal\": {\"AWS\": {\"Fn::Sub\": \"arn:aws:iam::${AWS::AccountId}:root\"}},\n                            \"Action\": [\"sts:AssumeRole\"],\n                        }\n                    ],\n                },\n                \"Path\": \"/\",\n                \"Policies\": [\n                    {\n                        \"PolicyName\": \"root\",\n                        \"PolicyDocument\": {\n                            \"Version\": \"2012-10-17\",\n                            \"Statement\": [\n                                {\n                                    \"Effect\": \"Allow\",\n                                    \"Action\": {\"Ref\": \"StarParameter\"},\n                                    \"Resource\": {\"Ref\": \"StarParameter\"},\n                                }\n                            ],\n                        },\n                    }\n                ],\n            },\n        }\n    },\n}\n\nmodel = parse(template).resolve(extra_params={\"AWS::AccountId\": \"123\"})\nrootRole = model.Resources[\"rootRole\"]\npolicy = rootRole.Properties.Policies[0]\nstatement = policy.PolicyDocument.Statement[0]\n\nassert statement.Action == \"*\"\nassert statement.Resource == \"*\"\nassert rootRole.Properties.AssumeRolePolicyDocument.Statement[0].Principal == {\"AWS\": \"arn:aws:iam::123:root\"}\n```\n\n## Local Development Commands\n\n```bash\nmake install-dev\nmake coverage\nmake test\nmake freeze\n```\n\nIf the test `tests/test_constants.py::test_cloudformation_actions` is failing, it can be resolved by updating the known\nAWS Actions:\n\n```bash\npython3 scripts/generate_cloudformation_actions_file.py\n```\n\n\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "A python model for CloudFormation scripts",
    "version": "0.22.0",
    "project_urls": {
        "Homepage": "https://github.com/Skyscanner/pycfmodel"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "8992091811f00af20a843af36172ba5bd76b3fad2fcee685afcf4a1fa2fc979a",
                "md5": "2d717bbdc866f889dbda018584942fe4",
                "sha256": "9b816c9f42f728ec2b5687725e2da5018dd9e918719e10e63ddeb08164ae2843"
            },
            "downloads": -1,
            "filename": "pycfmodel-0.22.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "2d717bbdc866f889dbda018584942fe4",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 159813,
            "upload_time": "2024-02-08T16:36:52",
            "upload_time_iso_8601": "2024-02-08T16:36:52.428108Z",
            "url": "https://files.pythonhosted.org/packages/89/92/091811f00af20a843af36172ba5bd76b3fad2fcee685afcf4a1fa2fc979a/pycfmodel-0.22.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "de7abab391457bd63298866854a203d243e794f779d933b468211712c62f84fb",
                "md5": "08eacfc9effa6b7fd25cccbbc4789c18",
                "sha256": "af07ea1dd2f8c4f5f187595e420ba841f30bce4e785ecab17d68248e64085a52"
            },
            "downloads": -1,
            "filename": "pycfmodel-0.22.0.tar.gz",
            "has_sig": false,
            "md5_digest": "08eacfc9effa6b7fd25cccbbc4789c18",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 129591,
            "upload_time": "2024-02-08T16:37:02",
            "upload_time_iso_8601": "2024-02-08T16:37:02.177895Z",
            "url": "https://files.pythonhosted.org/packages/de/7a/bab391457bd63298866854a203d243e794f779d933b468211712c62f84fb/pycfmodel-0.22.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-02-08 16:37:02",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "Skyscanner",
    "github_project": "pycfmodel",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "lcname": "pycfmodel"
}
        
Elapsed time: 0.35394s