homebrew-core/Formula/c7n.rb

149 lines
6.3 KiB
Ruby

class C7n < Formula
include Language::Python::Virtualenv
desc "Rules engine for cloud security, cost optimization, and governance"
homepage "https://github.com/cloud-custodian/cloud-custodian"
url "https://github.com/cloud-custodian/cloud-custodian/archive/0.9.7.0.tar.gz"
sha256 "3effbe679612be534e77a1bd42441c6c67ae419ce588574442e46134e5019c71"
license "Apache-2.0"
livecheck do
url "https://github.com/cloud-custodian/cloud-custodian/releases/latest"
regex(%r{href=.*?/tag/v?(\d+(?:\.\d+)+)["' >]}i)
end
bottle do
cellar :any_skip_relocation
sha256 "4f9e2537fc8023b1d090319be2c8c958601f7d4a87996765dbe76814d79bed12" => :catalina
sha256 "d3888b4697decc751cbdc4567cd901908b4dafd8cf5b3d4ea3fe773da5ee8ad8" => :mojave
sha256 "52cd5c6ab9acec4467ccc48614180859039c2b243f1b3f9179fbac94666bd198" => :high_sierra
end
depends_on "python@3.9"
resource "argcomplete" do
url "https://files.pythonhosted.org/packages/45/bd/98dfd56ea8f6b2b7dd89bea8b067a55a6dbaec7b4cc28186cbafe2e1d24e/argcomplete-1.12.1.tar.gz"
sha256 "849c2444c35bb2175aea74100ca5f644c29bf716429399c0f2203bb5d9a8e4e6"
end
resource "attrs" do
url "https://files.pythonhosted.org/packages/81/d0/641b698d05f0eaea4df4f9cebaff573d7a5276228ef6b7541240fe02f3ad/attrs-20.2.0.tar.gz"
sha256 "26b54ddbbb9ee1d34d5d3668dd37d6cf74990ab23c828c2888dccdceee395594"
end
resource "boto3" do
url "https://files.pythonhosted.org/packages/8d/5a/6ccd35b9b8d6a052220ce380bb2b129277e15c2bb71daf8df443ca04d9e3/boto3-1.15.17.tar.gz"
sha256 "83fc4652eb102c0ff862061d65280bb1ee6f773043b5231d1badb77681267318"
end
resource "botocore" do
url "https://files.pythonhosted.org/packages/c0/9d/017d4f0320cccc5bbce911e2f070ed62e96b3bc4d57e9e66db9b8ec8f659/botocore-1.18.17.tar.gz"
sha256 "4cdb114947391c88787df3e2f6a9f53ee15f1e2fef8691963e959858a034bb02"
end
resource "importlib-metadata" do
url "https://files.pythonhosted.org/packages/e2/ae/0b037584024c1557e537d25482c306cf6327b5a09b6c4b893579292c1c38/importlib_metadata-1.7.0.tar.gz"
sha256 "90bb658cdbbf6d1735b6341ce708fc7024a3e14e99ffdc5783edea9f9b077f83"
end
resource "jmespath" do
url "https://files.pythonhosted.org/packages/3c/56/3f325b1eef9791759784aa5046a8f6a1aff8f7c898a2e34506771d3b99d8/jmespath-0.10.0.tar.gz"
sha256 "b85d0567b8666149a93172712e68920734333c0ce7e89b78b3e987f71e5ed4f9"
end
resource "jsonpickle" do
url "https://files.pythonhosted.org/packages/8a/6d/92d8dadd0aa7a526fe5466e05e1b26b5fc033183af7dc0c38d67eb69915b/jsonpickle-1.3.tar.gz"
sha256 "71bca2b80ae28af4e3f86629ef247100af7f97032b5ca8d791c1f8725b411d95"
end
resource "jsonschema" do
url "https://files.pythonhosted.org/packages/69/11/a69e2a3c01b324a77d3a7c0570faa372e8448b666300c4117a516f8b1212/jsonschema-3.2.0.tar.gz"
sha256 "c8a85b28d377cc7737e46e2d9f2b4f44ee3c0e1deac6bf46ddefc7187d30797a"
end
resource "pyrsistent" do
url "https://files.pythonhosted.org/packages/4d/70/fd441df751ba8b620e03fd2d2d9ca902103119616f0f6cc42e6405035062/pyrsistent-0.17.3.tar.gz"
sha256 "2e636185d9eb976a18a8a8e96efce62f2905fea90041958d8cc2a189756ebf3e"
end
resource "python-dateutil" do
url "https://files.pythonhosted.org/packages/be/ed/5bbc91f03fa4c839c4c7360375da77f9659af5f7086b7a7bdda65771c8e0/python-dateutil-2.8.1.tar.gz"
sha256 "73ebfe9dbf22e832286dafa60473e4cd239f8592f699aa5adaf10050e6e1823c"
end
resource "PyYAML" do
url "https://files.pythonhosted.org/packages/64/c2/b80047c7ac2478f9501676c988a5411ed5572f35d1beff9cae07d321512c/PyYAML-5.3.1.tar.gz"
sha256 "b8eac752c5e14d3eca0e6dd9199cd627518cb5ec06add0de9d32baeee6fe645d"
end
resource "s3transfer" do
url "https://files.pythonhosted.org/packages/50/de/2b688c062107942486c81a739383b1432a72717d9a85a6a1a692f003c70c/s3transfer-0.3.3.tar.gz"
sha256 "921a37e2aefc64145e7b73d50c71bb4f26f46e4c9f414dc648c6245ff92cf7db"
end
resource "six" do
url "https://files.pythonhosted.org/packages/6b/34/415834bfdafca3c5f451532e8a8d9ba89a21c9743a0c59fbd0205c7f9426/six-1.15.0.tar.gz"
sha256 "30639c035cdb23534cd4aa2dd52c3bf48f06e5f4a941509c8bafd8ce11080259"
end
resource "tabulate" do
url "https://files.pythonhosted.org/packages/57/6f/213d075ad03c84991d44e63b6516dd7d185091df5e1d02a660874f8f7e1e/tabulate-0.8.7.tar.gz"
sha256 "db2723a20d04bcda8522165c73eea7c300eda74e0ce852d9022e0159d7895007"
end
resource "urllib3" do
url "https://files.pythonhosted.org/packages/81/f4/87467aeb3afc4a6056e1fe86626d259ab97e1213b1dfec14c7cb5f538bf0/urllib3-1.25.10.tar.gz"
sha256 "91056c15fa70756691db97756772bb1eb9678fa585d9184f24534b100dc60f4a"
end
resource "zipp" do
url "https://files.pythonhosted.org/packages/49/4d/374ccacda17692db1d93b00a637b8255ec97608b0c51f3b66bc9c57fe3e1/zipp-3.3.1.tar.gz"
sha256 "c1532a8030c32fd52ff6a288d855fe7adef5823ba1d26a29a68fd6314aa72baa"
end
def install
virtualenv_install_with_resources
end
test do
# trim last decimal point version to match semver returned from version command
assert_match version.major_minor_patch.to_s, shell_output("#{bin}/custodian version")
(testpath/"good-policy.yml").write <<~EOF
policies:
- name: ec2-auto-tag-user
resource: ec2
mode:
type: cloudtrail
role: arn:aws:iam::{account_id}:role/custodian-auto-tagger
# note {account_id} is optional. If you put that there instead of
# your actual account number, when the policy is provisioned it
# will automatically inherit the account_id properly
events:
- RunInstances
filters:
- tag:CreatorName: absent
actions:
- type: auto-tag-user
tag: CreatorName
principal_id_tag: CreatorId
EOF
output = shell_output("custodian validate --verbose #{testpath}/good-policy.yml 2>&1")
assert_match "valid", output
# has invalid "action" key instead of "actions"
(testpath/"bad-policy.yml").write <<~EOF
policies:
- name: ec2-auto-tag-user
resource: ec2
filters:
- tag:CreatorName: absent
action:
- type: auto-tag-user
tag: CreatorName
principal_id_tag: CreatorId
EOF
output = shell_output("custodian validate --verbose #{testpath}/bad-policy.yml 2>&1", 1)
assert_match "invalid", output
end
end