aboutsummaryrefslogtreecommitdiff
path: root/pyenc/model.py
diff options
context:
space:
mode:
Diffstat (limited to 'pyenc/model.py')
-rw-r--r--pyenc/model.py44
1 files changed, 42 insertions, 2 deletions
diff --git a/pyenc/model.py b/pyenc/model.py
index 0a240d9..e774014 100644
--- a/pyenc/model.py
+++ b/pyenc/model.py
@@ -43,26 +43,66 @@ class Host(db.Model):
for column in self.__table__.columns}
+class PuppetEnvironment(db.Model):
+ """
+ A puppet environment.
+
+ An enviromnet is a collection of modules, but here we only keep
+ the files of the modules, in PuppetFile.
+ """
+ __tablename__ = 'puppet_environment'
+ id = db.Column(db.Integer, primary_key=True)
+ name = db.Column(db.Text, nullable=False)
+
+
class PuppetFile(db.Model):
"""
Puppet source code file.
Keeps track of known puppet files. Each file contains 0 to many
puppet classes.
+
+ Each file is uniquely identified by the pair (path, environment).
"""
__tablename__ = 'puppet_file'
id = db.Column(db.Integer, primary_key=True)
# Where we found the file
+ # TODO normalize this to <path-inside-environment>
path = db.Column(db.Text, nullable=False)
- # Output of 'puppet parser dump --format json <filename>'
- json = db.Column(db.Text, nullable=False)
+
+ environment = db.Column(db.Integer, db.ForeignKey(f'{PuppetEnvironment.__tablename__}.id'))
+
+ # Checksum of the content, should be usable as a key in
+ # PuppetFileContent
+ # TODO flask weak keys?
+ checksum = db.Column(db.Text)
+
# When we last read data into json
last_parse = db.Column(db.Float)
# classes = db.relationship('PuppetClass', back_populates='comes_from')
classes = db.relationship('PuppetClass', backref='comes_from')
+class PuppetFileContent(db.Model):
+ """
+ (Parsed) contents of puppet source files.
+
+ Separate from PuppetFile since many environments can share files,
+ and I don't want to store reduntand data.
+ """
+ __tablename__ = 'puppet_file_content'
+
+ id = db.Column(db.Integer, primary_key=True)
+
+ # Checksum of the original file
+ checksum = db.Column(db.Text, nullable=False)
+
+ # Output of 'puppet parser dump --format json <filename>'
+ json = db.Column(db.Text, nullable=False)
+
+
+
class PuppetClass(db.Model):
"""
A puppet class.