Skip to content

Commit

Permalink
Merge 3c1a685 into 5ba749e
Browse files Browse the repository at this point in the history
  • Loading branch information
jeff1evesque committed Jun 12, 2018
2 parents 5ba749e + 3c1a685 commit 715fa0a
Show file tree
Hide file tree
Showing 3 changed files with 275 additions and 5 deletions.
7 changes: 4 additions & 3 deletions hiera/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,10 @@ application:
- poly
- rbf
- sigmoid
model_type:
- svm
- svr
result_type:
- r2
- decision_function
- probability
log_level: 'DEBUG'
error_log_path: '/log/application/error'
warning_log_path: '/log/application/warning'
Expand Down
60 changes: 60 additions & 0 deletions hiera/test/hiera/application.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
##
## This file contains general application configurations.
##
## @LOG_LEVEL, defines the application baseline (i.e. handler) level for logs.
## This means the logger level cannot exceed this baseline.
##
## The following are supported 'LOG_LEVEL' values:
##
## - ERROR
## - WARNING
## - INFO
## - DEBUG
##
## Note: the specific log levels can be reviewed:
##
## https://docs.python.org/2/library/logging.html#logging-levels
##
## Note: when referencing a hash path value, remember to prefix the call with
## the above 'general: root' definition.
##
application:
dataset:
anonymous:
max_collection: 50
max_document: 10
authenticated:
max_collection: 150
max_document: 30
types:
- file_upload
- dataset_url
- json_string
security_key: 'change-this'
model_type:
- svm
- svr
sv_kernel_type:
- linear
- poly
- rbf
- sigmoid
result_type:
- r2
- decision_function
- probability
log_level: 'DEBUG'
error_log_path: '/log/application/error'
warning_log_path: '/log/application/warning'
info_log_path: '/log/application/info'
debug_log_path: '/log/application/debug'

crypto:
salt_length: 32
scrypt_n: 18
scrypt_r: 8
scrypt_p: 1

validate_password:
password_min_c: 10
password_max_c: 64
213 changes: 211 additions & 2 deletions puppet/environment/docker/modules/mariadb/scripts/setup_tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@
# yaml configuration: application attributes
with open(prepath + '/application.yaml', 'r') as stream:
settings = yaml.load(stream)
models = settings['application']['model_type']
model_types = settings['application']['model_type']
result_types = settings['application']['result_type']

# yaml configuration: general attributes
with open(prepath + '/common.yaml', 'r') as stream:
Expand All @@ -71,6 +72,11 @@
# create cursor object
cur = conn.cursor()

# ################################################################################# #
# LEGACY TABLES: these tables will be iteratively phased out, as corresponding #
# backend and frontend are developed. #
# ################################################################################# #

# create 'tbl_user'
sql_statement = '''\
CREATE TABLE IF NOT EXISTS tbl_user (
Expand Down Expand Up @@ -114,7 +120,7 @@
sql_statement = '''\
INSERT INTO tbl_model_type (model) VALUES (%s);
'''
cur.executemany(sql_statement, models)
cur.executemany(sql_statement, model_types)

# create 'tbl_prediction_results'
sql_statement = '''\
Expand Down Expand Up @@ -169,3 +175,206 @@ class VARCHAR (50) NOT NULL
);
'''
cur.execute(sql_statement)

# ################################################################################# #
# NEW STRUCTURE: when the above legacy tables have been completely phased out, the #
# below tables will completely define our sql implementation. #
# ################################################################################# #

# ################################################################################# #
# #
# user and roles #
# #
# @RoleOwner, whether role is owned, or given. #
# #
# ################################################################################# #
query = '''\
CREATE TABLE IF NOT EXISTS Account (
UserID INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
Username VARCHAR (50) NOT NULL,
Password VARCHAR (1069) NOT NULL,
Joined DATETIME NOT NULL,
UNIQUE (Username)
);
'''
cur.execute(query)

query = '''\
CREATE TABLE IF NOT EXISTS RoleType (
RoleTypeID INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
RoleType VARCHAR (50) NOT NULL,
UNIQUE (RoleType)
);
'''
cur.execute(query)

query = '''\
CREATE TABLE IF NOT EXISTS Role (
RoleID INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
RoleOwner INT NOT NULL,
RoleTypeID INT NOT NULL,
UserID INT NOT NULL,
UNIQUE (RoleTypeID, UserID),
FOREIGN KEY (RoleTypeID) REFERENCES RoleType(RoleTypeID),
FOREIGN KEY (UserID) REFERENCES Account(UserID)
);
'''
cur.execute(query)

# ################################################################################# #
# #
# collection #
# #
# ################################################################################# #
query = '''\
CREATE TABLE IF NOT EXISTS Collection (
CollectionID INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
CollectionName VARCHAR (50) NOT NULL,
CollectionVersion INT NOT NULL
);
'''
cur.execute(query)

# ################################################################################# #
# #
# model #
# #
# ################################################################################# #
query = '''\
CREATE TABLE IF NOT EXISTS ModelType (
ModelTypeID INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
ModelType VARCHAR (50) NOT NULL,
UNIQUE (ModelType)
);
'''
cur.execute(query)

query = '''\
CREATE TABLE IF NOT EXISTS Model (
ModelID INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
ModelName VARCHAR (50) NOT NULL,
Model BLOB NOT NULL,
ModelTypeID INT NOT NULL,
FOREIGN KEY (ModelTypeID) REFERENCES ModelType(ModelTypeID)
);
'''
cur.execute(query)

# ################################################################################# #
# #
# results #
# #
# ################################################################################# #
query = '''\
CREATE TABLE IF NOT EXISTS ResultType (
ResultTypeID INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
ResultType VARCHAR (50) NOT NULL,
UNIQUE (ResultType)
);
'''
cur.execute(query)

query = '''\
CREATE TABLE IF NOT EXISTS Result (
ResultID INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
ResultValue DECIMAL (65,12) NOT NULL,
ModelTypeID INT (50) NOT NULL,
ResultTypeID INT NOT NULL,
FOREIGN KEY (ModelTypeID) REFERENCES ModelType(ModelTypeID),
FOREIGN KEY (ResultTypeID) REFERENCES ResultType(ResultTypeID)
);
'''
cur.execute(query)

# ################################################################################# #
# #
# applied permission #
# #
# ################################################################################# #
query = '''\
CREATE TABLE IF NOT EXISTS PermissionCollection (
PermissionCollectionID INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
PermissionValueCode INT NOT NULL,
CollectionID INT NOT NULL,
UserID INT NOT NULL,
RoleID INT DEFAULT 0,
UNIQUE (CollectionID, UserID, RoleID),
FOREIGN KEY (CollectionID) REFERENCES Collection(CollectionID),
FOREIGN KEY (UserID) REFERENCES Account(UserID),
FOREIGN KEY (RoleID) REFERENCES Role(RoleID)
);
'''
cur.execute(query)

query = '''\
CREATE TABLE IF NOT EXISTS PermissionModel (
PermissionModelID INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
PermissionValueCode INT NOT NULL,
ModelID INT NOT NULL,
UserID INT NOT NULL,
RoleID INT DEFAULT 0,
UNIQUE (ModelID, UserID, RoleID),
FOREIGN KEY (ModelID) REFERENCES Model(ModelID),
FOREIGN KEY (UserID) REFERENCES Account(UserID),
FOREIGN KEY (RoleID) REFERENCES Role(RoleID)
);
'''
cur.execute(query)

query = '''\
CREATE TABLE IF NOT EXISTS PermissionResult (
PermissionResultID INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
PermissionValueCode INT NOT NULL,
ResultID INT NOT NULL,
UserID INT NOT NULL,
RoleID INT DEFAULT 0,
UNIQUE (ResultID, UserID, RoleID),
FOREIGN KEY (ResultID) REFERENCES Result(ResultID),
FOREIGN KEY (UserID) REFERENCES Account(UserID),
FOREIGN KEY (RoleID) REFERENCES Role(RoleID)
);
'''
cur.execute(query)

# ################################################################################# #
# #
# populate User, and Role #
# #
# ################################################################################# #
query = '''\
INSERT INTO Account (Username, Password, Joined) VALUES (%s, %s, %s);
'''
args = ('anonymous', '0', '2018-01-25 12:00:00')
cur.execute(query, args)

query = '''\
INSERT INTO RoleType (RoleType) VALUES (%s);
'''
args = ('default')
cur.execute(query, args)

query = '''\
INSERT INTO Role (RoleOwner, RoleTypeID, UserID) VALUES (%s, %s, %s);
'''
args = ('0', '1', '1')
cur.execute(query, args)

# ################################################################################# #
# #
# populate ModelType #
# #
# ################################################################################# #
query = '''\
INSERT INTO ModelType (ModelType) VALUES (%s);
'''
cur.executemany(query, model_types)

# ################################################################################# #
# #
# populate ResultType #
# #
# ################################################################################# #
query = '''\
INSERT INTO ResultType (ResultType) VALUES (%s);
'''
cur.executemany(query, result_types)

0 comments on commit 715fa0a

Please sign in to comment.