Add comments so lint will shut up
This commit is contained in:
parent
ab2a7fce28
commit
1bd02fbeb3
|
|
@ -24,11 +24,15 @@ type domainRule struct {
|
||||||
Type string `db:"type"`
|
Type string `db:"type"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PolicyAuthorityDatabaseImpl enforces policy decisions based on various rule
|
||||||
|
// lists
|
||||||
type PolicyAuthorityDatabaseImpl struct {
|
type PolicyAuthorityDatabaseImpl struct {
|
||||||
log *blog.AuditLogger
|
log *blog.AuditLogger
|
||||||
dbMap *gorp.DbMap
|
dbMap *gorp.DbMap
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewPolicyAuthorityDatabaseImpl constructs a Policy Authority Database (and
|
||||||
|
// creates tables if they are non-existent)
|
||||||
func NewPolicyAuthorityDatabaseImpl(driver, name string) (padb core.PolicyAuthorityDatabase, err error) {
|
func NewPolicyAuthorityDatabaseImpl(driver, name string) (padb core.PolicyAuthorityDatabase, err error) {
|
||||||
logger := blog.GetAuditLogger()
|
logger := blog.GetAuditLogger()
|
||||||
dbMap, err := sa.NewDbMap(driver, name)
|
dbMap, err := sa.NewDbMap(driver, name)
|
||||||
|
|
@ -51,6 +55,7 @@ func NewPolicyAuthorityDatabaseImpl(driver, name string) (padb core.PolicyAuthor
|
||||||
return padb, nil
|
return padb, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AddRule will add a whitelist or blacklist rule to the database
|
||||||
func (padb *PolicyAuthorityDatabaseImpl) AddRule(rule string, string string) error {
|
func (padb *PolicyAuthorityDatabaseImpl) AddRule(rule string, string string) error {
|
||||||
tx, err := padb.dbMap.Begin()
|
tx, err := padb.dbMap.Begin()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -78,16 +83,11 @@ func (padb *PolicyAuthorityDatabaseImpl) AddRule(rule string, string string) err
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CheckRules will query the database for white/blacklist rules that match host,
|
||||||
|
// if both whitelist and blacklist rules are found the whitelist will always win
|
||||||
func (padb *PolicyAuthorityDatabaseImpl) CheckRules(host string) error {
|
func (padb *PolicyAuthorityDatabaseImpl) CheckRules(host string) error {
|
||||||
// Wrap in transaction so the whitelist doesn't change under us
|
|
||||||
tx, err := padb.dbMap.Begin()
|
|
||||||
if err != nil {
|
|
||||||
tx.Rollback()
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
var rules []domainRule
|
var rules []domainRule
|
||||||
_, err = tx.Select(
|
_, err := padb.dbMap.Select(
|
||||||
&rules,
|
&rules,
|
||||||
`SELECT type,rule FROM ruleList WHERE :host LIKE rule`,
|
`SELECT type,rule FROM ruleList WHERE :host LIKE rule`,
|
||||||
map[string]interface{}{"host": host},
|
map[string]interface{}{"host": host},
|
||||||
|
|
@ -96,12 +96,6 @@ func (padb *PolicyAuthorityDatabaseImpl) CheckRules(host string) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = tx.Commit()
|
|
||||||
if err != nil {
|
|
||||||
tx.Rollback()
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
var wRules []string
|
var wRules []string
|
||||||
var bRules []string
|
var bRules []string
|
||||||
for _, rule := range rules {
|
for _, rule := range rules {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue