-
Notifications
You must be signed in to change notification settings - Fork 256
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
39 changed files
with
1,640 additions
and
509 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,35 @@ | ||
# standard libraries | ||
import re | ||
from __future__ import print_function | ||
import json | ||
|
||
# 1st party libraries | ||
from blastradius.graph import Graph, Node, Edge | ||
from blastradius.handlers.dot import DotNode | ||
from blastradius.util import Re | ||
|
||
class Apply(Graph): | ||
def __init__(self, filename): | ||
self.filename = filename | ||
self.contents = '' | ||
self.nodes = [] # we can populate this, | ||
self.edges = [] # but not this! | ||
|
||
ansi_escape = re.compile(r'\x1b[^m]*m') | ||
with open(filename, 'r') as f: | ||
self.contents = ansi_escape.sub('', f.read()) | ||
|
||
# example output: | ||
# | ||
# aws_vpc.default: Creation complete after 4s (ID: vpc-024f7a64) | ||
# ... | ||
# aws_key_pair.auth: Creating... | ||
# fingerprint: "" => "<computed>" | ||
# key_name: "" => "default-key" | ||
# ... | ||
# aws_instance.web: Still creating... (10s elapsed) | ||
# aws_instance.web: Still creating... (20s elapsed) | ||
# aws_instance.web (remote-exec): Connecting to remote host via SSH... | ||
# aws_instance.web (remote-exec): Host: 1.2.3.4 | ||
# aws_instance.web (remote-exec): User: ubuntu | ||
# ... | ||
|
||
node_begin_re =r'(?P<name>\S+)\:\s+Creating...' | ||
node_compl_re = r'(?P<name>\S+)\:\s+Creation\s+complete\s+after\s+(?P<duration>\S+)\s+' | ||
node_still_re = r'(?P<name>\S+)\:\s+Still\s+creating\.\.\.\s+\((?P<duration>\S+)\s+' | ||
|
||
for line in self.contents.splitlines(): | ||
|
||
r = Re() | ||
if r.match(node_begin_re, line): | ||
|
||
|
||
|
||
|
||
break | ||
|
||
|
||
|
||
|
||
print(self.contents) | ||
|
||
|
||
import sys | ||
import jinja2 | ||
import json | ||
import subprocess | ||
import os.path | ||
from os import path | ||
|
||
class Apply(): | ||
def __init__(self,filename=None): | ||
self.apply_resource_info = [] | ||
#reading from state file | ||
if filename == None: | ||
if(path.exists("terraform.tfstate")): | ||
with open("terraform.tfstate", 'r') as f: | ||
data = json.load(f) | ||
else: | ||
data = "" | ||
else: | ||
with open(filename, 'r') as f: | ||
data = json.load(f) | ||
|
||
if (data) : | ||
for _, var in enumerate(data["resources"]): | ||
temp_data = dict() | ||
temp_data = var | ||
self.apply_resource_info.append(temp_data) | ||
|
||
else: | ||
self.apply_resource_info.append("not applied") | ||
|
||
def json(self): | ||
my_json_string = json.dumps(self.apply_resource_info,indent=4, sort_keys=True) | ||
return my_json_string |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import json | ||
import os.path | ||
from os import path | ||
|
||
class Controls(): | ||
def __init__(self,filename=None): | ||
self.resource_controls_info = [] | ||
if filename == None: | ||
if(path.exists("policy.json")): | ||
with open("policy.json", 'r') as f: | ||
data = json.load(f) | ||
else: | ||
data = "" | ||
else: | ||
with open(filename, 'r') as f: | ||
data = json.load(f) | ||
|
||
if (data) : | ||
for _, var in enumerate(data["resources"]): | ||
temp_data = dict() | ||
temp_data = var | ||
self.resource_controls_info.append(temp_data) | ||
|
||
else: | ||
self.resource_controls_info.append("not available") | ||
|
||
|
||
def json(self): | ||
controls_json = json.dumps(self.resource_controls_info,indent=4, sort_keys=True) | ||
return controls_json |
Oops, something went wrong.