Skip to content

Commit

Permalink
Merge pull request #494 from seswarrajan/dev
Browse files Browse the repository at this point in the history
Added new fields(updatedTime,latest) to system_policy
  • Loading branch information
nyrahul authored Jul 1, 2022
2 parents bb42e47 + 87a0778 commit ed0e0bb
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 12 deletions.
19 changes: 13 additions & 6 deletions src/libs/mysqlHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ func GetSystemPoliciesFromMySQL(cfg types.ConfigDB, namespace, status string) ([
var results *sql.Rows
var err error

query := "SELECT apiVersion,kind,name,clusterName,namespace,type,status,outdated,spec,generatedTime FROM " + TableSystemPolicy_TableName
query := "SELECT apiVersion,kind,name,clusterName,namespace,type,status,outdated,spec,generatedTime,updatedTime,latest FROM " + TableSystemPolicy_TableName

if namespace != "" && status != "" {
query = query + " WHERE namespace = ? and status = ? "
Expand Down Expand Up @@ -339,6 +339,8 @@ func GetSystemPoliciesFromMySQL(cfg types.ConfigDB, namespace, status string) ([
&policy.Outdated,
&specByte,
&policy.GeneratedTime,
&policy.UpdatedTime,
&policy.Latest,
); err != nil {
return nil, err
}
Expand All @@ -364,7 +366,7 @@ func GetSystemPoliciesFromMySQL(cfg types.ConfigDB, namespace, status string) ([
}

func insertSystemPolicy(cfg types.ConfigDB, db *sql.DB, policy types.KnoxSystemPolicy) error {
stmt, err := db.Prepare("INSERT INTO " + TableSystemPolicy_TableName + "(apiVersion,kind,name,clusterName,namespace,type,status,outdated,spec,generatedTime) values(?,?,?,?,?,?,?,?,?,?)")
stmt, err := db.Prepare("INSERT INTO " + TableSystemPolicy_TableName + "(apiVersion,kind,name,clusterName,namespace,type,status,outdated,spec,generatedTime,updatedTime,latest) values(?,?,?,?,?,?,?,?,?,?,?,?)")
if err != nil {
return err
}
Expand All @@ -386,7 +388,9 @@ func insertSystemPolicy(cfg types.ConfigDB, db *sql.DB, policy types.KnoxSystemP
policy.Metadata["status"],
policy.Outdated,
spec,
policy.GeneratedTime)
ConvertStrToUnixTime("now"),
ConvertStrToUnixTime("now"),
true)
if err != nil {
return err
}
Expand All @@ -413,7 +417,7 @@ func UpdateSystemPolicyToMySQL(cfg types.ConfigDB, policy types.KnoxSystemPolicy

// set status -> outdated
stmt, err := db.Prepare("UPDATE " + TableSystemPolicy_TableName +
" SET apiVersion=?,kind=?,clusterName=?,namespace=?,type=?,status=?,outdated=?,spec=?,generatedTime=? WHERE name = ?")
" SET apiVersion=?,kind=?,clusterName=?,namespace=?,type=?,status=?,outdated=?,spec=?,updatedTime=?,latest=? WHERE name = ?")
if err != nil {
return err
}
Expand All @@ -434,7 +438,8 @@ func UpdateSystemPolicyToMySQL(cfg types.ConfigDB, policy types.KnoxSystemPolicy
policy.Metadata["status"],
policy.Outdated,
spec,
policy.GeneratedTime,
ConvertStrToUnixTime("now"),
true,
policy.Metadata["name"])
if err != nil {
return err
Expand Down Expand Up @@ -530,7 +535,9 @@ func CreateTableSystemPolicyMySQL(cfg types.ConfigDB) error {
" `status` varchar(10) DEFAULT NULL," +
" `outdated` varchar(50) DEFAULT NULL," +
" `spec` JSON DEFAULT NULL," +
" `generatedTime` int DEFAULT NULL," +
" `generatedTime` bigint NOT NULL," +
" `updatedTime` bigint NOT NULL," +
" `latest` BOOLEAN," +
" PRIMARY KEY (`id`)" +
" );"

Expand Down
19 changes: 13 additions & 6 deletions src/libs/sqliteHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ func GetSystemPoliciesFromSQLite(cfg types.ConfigDB, namespace, status string) (
var results *sql.Rows
var err error

query := "SELECT apiVersion,kind,name,clusterName,namespace,type,status,outdated,spec,generatedTime FROM " + TableSystemPolicySQLite_TableName
query := "SELECT apiVersion,kind,name,clusterName,namespace,type,status,outdated,spec,generatedTime,updatedTime,latest FROM " + TableSystemPolicySQLite_TableName

if namespace != "" && status != "" {
query = query + " WHERE namespace = ? and status = ? "
Expand Down Expand Up @@ -329,6 +329,8 @@ func GetSystemPoliciesFromSQLite(cfg types.ConfigDB, namespace, status string) (
&policy.Outdated,
&specByte,
&policy.GeneratedTime,
&policy.UpdatedTime,
&policy.Latest,
); err != nil {
return nil, err
}
Expand All @@ -354,7 +356,7 @@ func GetSystemPoliciesFromSQLite(cfg types.ConfigDB, namespace, status string) (
}

func insertSystemPolicySQLite(cfg types.ConfigDB, db *sql.DB, policy types.KnoxSystemPolicy) error {
stmt, err := db.Prepare("INSERT INTO " + TableSystemPolicySQLite_TableName + "(apiVersion,kind,name,clusterName,namespace,type,status,outdated,spec,generatedTime) values(?,?,?,?,?,?,?,?,?,?)")
stmt, err := db.Prepare("INSERT INTO " + TableSystemPolicySQLite_TableName + "(apiVersion,kind,name,clusterName,namespace,type,status,outdated,spec,generatedTime,updatedTime,latest) values(?,?,?,?,?,?,?,?,?,?,?,?)")
if err != nil {
return err
}
Expand All @@ -376,7 +378,9 @@ func insertSystemPolicySQLite(cfg types.ConfigDB, db *sql.DB, policy types.KnoxS
policy.Metadata["status"],
policy.Outdated,
spec,
policy.GeneratedTime)
ConvertStrToUnixTime("now"),
ConvertStrToUnixTime("now"),
true)
if err != nil {
return err
}
Expand All @@ -403,7 +407,7 @@ func UpdateSystemPolicyToSQLite(cfg types.ConfigDB, policy types.KnoxSystemPolic

// set status -> outdated
stmt, err := db.Prepare("UPDATE " + TableSystemPolicySQLite_TableName +
" SET apiVersion=?,kind=?,clusterName=?,namespace=?,type=?,status=?,outdated=?,spec=?,generatedTime=? WHERE name = ?")
" SET apiVersion=?,kind=?,clusterName=?,namespace=?,type=?,status=?,outdated=?,spec=?,updatedTime=?,latest=? WHERE name = ?")
if err != nil {
return err
}
Expand All @@ -424,7 +428,8 @@ func UpdateSystemPolicyToSQLite(cfg types.ConfigDB, policy types.KnoxSystemPolic
policy.Metadata["status"],
policy.Outdated,
spec,
policy.GeneratedTime,
ConvertStrToUnixTime("now"),
true,
policy.Metadata["name"])
if err != nil {
return err
Expand Down Expand Up @@ -508,7 +513,9 @@ func CreateTableSystemPolicySQLite(cfg types.ConfigDB) error {
" `status` varchar(10) DEFAULT NULL," +
" `outdated` varchar(50) DEFAULT NULL," +
" `spec` JSON DEFAULT NULL," +
" `generatedTime` int DEFAULT NULL," +
" `generatedTime` bigint NOT NULL," +
" `updatedTime` bigint NOT NULL," +
" `latest` BOOLEAN," +
" PRIMARY KEY (`id`)" +
" );"

Expand Down
2 changes: 2 additions & 0 deletions src/types/policyData.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,8 @@ type KnoxSystemPolicy struct {
Spec KnoxSystemSpec `json:"spec,omitempty" yaml:"spec,omitempty" bson:"spec,omitempty"`

GeneratedTime int64 `json:"generatedTime,omitempty" yaml:"generatedTime,omitempty" bson:"generatedTime,omitempty"`
UpdatedTime int64 `json:"updatedTime,omitempty" yaml:"updatedTime,omitempty" bson:"updatedTime,omitempty"`
Latest int64 `json:"latest,omitempty" yaml:"latest,omitempty" bson:"latest,omitempty"`
}

// ============================= //
Expand Down

0 comments on commit ed0e0bb

Please sign in to comment.