Skip to content

Commit 90dae79

Browse files
committed
made it a pypi package
1 parent d7ab393 commit 90dae79

14 files changed

+492
-140
lines changed

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,8 @@ target/
5555

5656
# Results files
5757
*.html
58-
*.dot
58+
*.dot
59+
60+
# .idea
61+
.idea/workspace.xml
62+
.idea/tasks.xml

.idea/aws-visualizer.iml

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/inspectionProfiles/profiles_settings.xml

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.make-release-support

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
#!/bin/bash
2+
#
3+
# Copyright 2015 Xebia Nederland B.V.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
18+
function hasChanges() {
19+
test -n "$(git status -s .)"
20+
}
21+
22+
function getRelease() {
23+
awk -F= '/^release=/{print $2}' .release
24+
}
25+
26+
function getBaseTag() {
27+
sed -n -e "s/^tag=\(.*\)$(getRelease)\$/\1/p" .release
28+
}
29+
30+
function getTag() {
31+
if [ -z "$1" ] ; then
32+
awk -F= '/^tag/{print $2}' .release
33+
else
34+
echo "$(getBaseTag)$1"
35+
fi
36+
}
37+
38+
function setRelease() {
39+
if [ -n "$1" ] ; then
40+
sed -i.x -e "s/^tag=.*/tag=$(getTag $1)/" .release
41+
sed -i.x -e "s/^release=.*/release=$1/g" .release
42+
rm -f .release.x
43+
runPreTagCommand "$1"
44+
else
45+
echo "ERROR: missing release version parameter " >&2
46+
return 1
47+
fi
48+
}
49+
50+
function runPreTagCommand() {
51+
if [ -n "$1" ] ; then
52+
COMMAND=$(sed -n -e "s/@@RELEASE@@/$1/g" -e 's/^pre_tag_command=\(.*\)/\1/p' .release)
53+
if [ -n "$COMMAND" ] ; then
54+
if ! OUTPUT=$(bash -c "$COMMAND" 2>&1) ; then echo $OUTPUT >&2 && exit 1 ; fi
55+
fi
56+
else
57+
echo "ERROR: missing release version parameter " >&2
58+
return 1
59+
fi
60+
}
61+
62+
function tagExists() {
63+
tag=${1:-$(getTag)}
64+
test -n "$tag" && test -n "$(git tag | grep "^$tag\$")"
65+
}
66+
67+
function differsFromRelease() {
68+
tag=$(getTag)
69+
! tagExists $tag || test -n "$(git diff --shortstat -r $tag .)"
70+
}
71+
72+
function getVersion() {
73+
result=$(getRelease)
74+
75+
if differsFromRelease; then
76+
result="$result-$(git rev-parse --short HEAD)"
77+
fi
78+
79+
if hasChanges ; then
80+
result="$result-dirty"
81+
fi
82+
echo $result
83+
}
84+
85+
function nextPatchLevel() {
86+
version=${1:-$(getRelease)}
87+
major_and_minor=$(echo $version | cut -d. -f1,2)
88+
patch=$(echo $version | cut -d. -f3)
89+
version=$(printf "%s.%d" $major_and_minor $(($patch + 1)))
90+
echo $version
91+
}
92+
93+
function nextMinorLevel() {
94+
version=${1:-$(getRelease)}
95+
major=$(echo $version | cut -d. -f1);
96+
minor=$(echo $version | cut -d. -f2);
97+
version=$(printf "%d.%d.0" $major $(($minor + 1))) ;
98+
echo $version
99+
}
100+
101+
function nextMajorLevel() {
102+
version=${1:-$(getRelease)}
103+
major=$(echo $version | cut -d. -f1);
104+
version=$(printf "%d.0.0" $(($major + 1)))
105+
echo $version
106+
}

.release

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
release=0.0.0
2+
tag=v0.0.0
3+
pre_tag_command=sed -i "" -e 's/^version=.*/version="@@RELEASE@@"/' setup.py

Makefile

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
include Makefile.mk
2+
USERNAME=mvanholsteijn
3+
NAME=aws-visualizer
4+
5+
do-build:
6+
python setup.py check
7+
python setup.py build
8+
9+
push:
10+
rm -rf dist/*
11+
python setup.py sdist
12+
twine upload dist/*
13+
14+
clean:
15+
python setup.py clean
16+
rm -rf build/* dist/*
17+
18+
install:
19+
python setup.py install

Makefile.mk

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
#
2+
# Copyright 2015 Xebia Nederland B.V.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
#
16+
REGISTRY_HOST=docker.io
17+
USERNAME=$(USER)
18+
NAME=$(shell basename $(PWD))
19+
20+
RELEASE_SUPPORT := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))/.make-release-support
21+
IMAGE=$(REGISTRY_HOST)/$(USERNAME)/$(NAME)
22+
23+
VERSION=$(shell . $(RELEASE_SUPPORT) ; getVersion)
24+
TAG=$(shell . $(RELEASE_SUPPORT); getTag)
25+
26+
SHELL=/bin/bash
27+
28+
.PHONY: pre-build do-build post-build build release patch-release minor-release major-release tag check-status check-release showver \
29+
push do-push post-push
30+
31+
build: pre-build do-build post-build
32+
33+
pre-build:
34+
35+
36+
post-build:
37+
38+
39+
post-push:
40+
41+
42+
do-build: .release
43+
@if [[ -f Dockerfile ]]; then docker build -t $(IMAGE):$(VERSION) . ; else echo "INFO: No Dockerfile found." >/dev/null ; fi
44+
@if [[ -f Dockerfile ]]; then \
45+
DOCKER_MAJOR=$(shell docker -v | sed -e 's/.*version //' -e 's/,.*//' | cut -d\. -f1) ; \
46+
DOCKER_MINOR=$(shell docker -v | sed -e 's/.*version //' -e 's/,.*//' | cut -d\. -f2) ; \
47+
if [ $$DOCKER_MAJOR -eq 1 ] && [ $$DOCKER_MINOR -lt 10 ] ; then \
48+
echo docker tag -f $(IMAGE):$(VERSION) $(IMAGE):latest ;\
49+
docker tag -f $(IMAGE):$(VERSION) $(IMAGE):latest ;\
50+
else \
51+
echo docker tag $(IMAGE):$(VERSION) $(IMAGE):latest ;\
52+
docker tag $(IMAGE):$(VERSION) $(IMAGE):latest ; \
53+
fi ; \
54+
else \
55+
echo 'No Dockerfile found.' > /dev/null ;\
56+
fi
57+
58+
.release:
59+
@echo "release=0.0.0" > .release
60+
@echo "tag=$(NAME)-0.0.0" >> .release
61+
@echo INFO: .release created
62+
@cat .release
63+
64+
65+
release: check-status check-release build push
66+
67+
68+
push: do-push post-push
69+
70+
do-push:
71+
@if [[ -f Dockerfile ]]; then \
72+
docker push $(IMAGE):$(VERSION) ; \
73+
docker push $(IMAGE):latest ; \
74+
else \
75+
echo > /dev/null ; \
76+
fi
77+
78+
snapshot: build push
79+
80+
showver: .release
81+
@. $(RELEASE_SUPPORT); getVersion
82+
83+
tag-patch-release: VERSION := $(shell . $(RELEASE_SUPPORT); nextPatchLevel)
84+
tag-patch-release: .release tag
85+
86+
tag-minor-release: VERSION := $(shell . $(RELEASE_SUPPORT); nextMinorLevel)
87+
tag-minor-release: .release tag
88+
89+
tag-major-release: VERSION := $(shell . $(RELEASE_SUPPORT); nextMajorLevel)
90+
tag-major-release: .release tag
91+
92+
patch-release: tag-patch-release release
93+
@echo $(VERSION)
94+
95+
minor-release: tag-minor-release release
96+
@echo $(VERSION)
97+
98+
major-release: tag-major-release release
99+
@echo $(VERSION)
100+
101+
102+
tag: TAG=$(shell . $(RELEASE_SUPPORT); getTag $(VERSION))
103+
tag: check-status
104+
@. $(RELEASE_SUPPORT) ; ! tagExists $(TAG) || (echo "ERROR: tag $(TAG) for version $(VERSION) already tagged in git" >&2 && exit 1) ;
105+
@. $(RELEASE_SUPPORT) ; setRelease $(VERSION)
106+
git add .
107+
git commit -m "bumped to version $(VERSION)" ;
108+
git tag $(TAG) ;
109+
@[ -n "$(shell git remote -v)" ] && git push --tags
110+
111+
check-status:
112+
@. $(RELEASE_SUPPORT) ; ! hasChanges || (echo "ERROR: there are still outstanding changes" >&2 && exit 1) ;
113+
114+
check-release: .release
115+
@. $(RELEASE_SUPPORT) ; tagExists $(TAG) || (echo "ERROR: version not yet tagged in git. make [minor,major,patch]-release." >&2 && exit 1) ;
116+
@. $(RELEASE_SUPPORT) ; ! differsFromRelease $(TAG) || (echo "ERROR: current directory differs from tagged $(TAG). make [minor,major,patch]-release." ; exit 1)

README.md

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
aws-visualizer
22
==============
3-
Visualizing the potential network dependencies within a VPC based on the security groups.
3+
A visualizer of the network of security group dependencies in an AWS VPC.
44

55
It can generate the following:
66
- An HTML table with all security group dependencies between network components.
@@ -30,48 +30,48 @@ A graph of all security group dependencies between network components grouped by
3030
![A graph of all dependencies grouped by subnet](sample/subnets/vpc-security-groups.png)
3131

3232

33-
3433
usage
3534
=====
36-
graph\_region.py [--directory output-directory ]
37-
[ --use-subnets | --use-security-group-subgraphs ]
38-
[--profile aws-profile]
39-
[--region aws-region]
40-
[--exclude-security-group security-group]
41-
[--no-dot-output]
42-
43-
--profile aws-profile
44-
to use to connect
45-
46-
--region aws-region
47-
to graph vpc's of
48-
49-
--use-subnets
50-
uses subgraphs for use subnet in the vpc.
51-
default is false.
52-
53-
----use-security-group-subgraphs
54-
uses security group grouping as subgraphs.
55-
default is false.
35+
```
36+
aws-visualizer [-h] [--directory DIRECTORY] [--use-subnets]
37+
[--use-security-group-subgraphs]
38+
[--exclude-security-group SECURITY-GROUP]
39+
[--profile PROFILE] [--region REGION]
40+
[--assume-role ROLE]
41+
```
5642

57-
--exclude-security-group
58-
comma separated list of security groups to exclude from graph.
5943

60-
--no-dot-output
61-
do not generate dot output files. Will only generate a HTML table
44+
optional arguments:
45+
```
46+
-h, --help show this help message and exit
47+
--directory DIRECTORY, -d DIRECTORY
48+
output directory defaults to .
49+
--use-subnets, -n use subnet subgraphs
50+
--use-security-group-subgraphs, -s
51+
use security group subgraphs
52+
--exclude-security-group SECURITY-GROUP, -x SECURITY-GROUP
53+
exclude security group
54+
--profile PROFILE, -p PROFILE
55+
select the AWS profile to use
56+
--region REGION, -r REGION
57+
select region to graph
58+
--assume-role ROLE, -a ROLE
59+
ARN of the role to assume
60+
```
6261

6362

64-
INSTALL
63+
Install
6564
-------
66-
- install python
67-
- install graphviz
68-
- pip install boto3 netaddr
65+
- brew install graphviz
66+
- pip install aws-visualizer
6967

7068
Example
7169
-------
70+
7271
```
73-
python graph_region.py --profile name_goes_here --directory /tmp/ --use-subnets --region us-west-1
74-
profile python graph_region.py --profile another_profile --directory /tmp/ --use-subnets --region us-west-1
72+
$ aws-visualizer --directory .
73+
$ for F in *.dot; do dot -Tpng -o $(basename $F .dot).png $F; done
74+
$ open *.html *.png
7575
```
7676

7777
Quickstart

0 commit comments

Comments
 (0)