feat: add open opencensus telemetry support

This commit is contained in:
Vikram Rangnekar
2020-05-22 16:49:54 -04:00
parent 448e6bb72a
commit c7837bf758
9 changed files with 91 additions and 31 deletions

View File

@ -83,14 +83,14 @@ func (sg *SuperGraph) initConfig() error {
// Roles: validate and sanitize
c.RolesQuery = sanitizeVars(c.RolesQuery)
if len(c.RolesQuery) == 0 {
if c.RolesQuery == "" {
sg.log.Printf("WRN roles_query not defined: attribute based access control disabled")
}
_, userExists := sg.roles["user"]
_, sg.anonExists = sg.roles["anon"]
sg.abacEnabled = userExists && len(c.RolesQuery) != 0
sg.abacEnabled = userExists && c.RolesQuery != ""
return nil
}
@ -112,7 +112,7 @@ func getDBTableAliases(c *Config) map[string][]string {
func addTables(c *Config, di *psql.DBInfo) error {
for _, t := range c.Tables {
if len(t.Table) == 0 || len(t.Columns) == 0 {
if t.Table == "" || len(t.Columns) == 0 {
continue
}
if err := addTable(di, t.Columns, t); err != nil {
@ -163,7 +163,7 @@ func addTable(di *psql.DBInfo, cols []Column, t Table) error {
func addForeignKeys(c *Config, di *psql.DBInfo) error {
for _, t := range c.Tables {
for _, c := range t.Columns {
if len(c.ForeignKey) == 0 {
if c.ForeignKey == "" {
continue
}
if err := addForeignKey(di, c, t); err != nil {
@ -272,7 +272,7 @@ func addRole(qc *qcode.Compiler, r Role, t RoleTable) error {
Block: blocked.update,
}
delete := qcode.DeleteConfig{
del := qcode.DeleteConfig{
Filters: t.Delete.Filters,
Columns: t.Delete.Columns,
Block: blocked.delete,
@ -283,7 +283,7 @@ func addRole(qc *qcode.Compiler, r Role, t RoleTable) error {
Query: query,
Insert: insert,
Update: update,
Delete: delete,
Delete: del,
})
}

View File

@ -40,7 +40,7 @@ type Config struct {
func New(filename string, conf Config) (*List, error) {
al := List{}
if len(filename) != 0 {
if filename != "" {
fp := filename
if _, err := os.Stat(fp); err == nil {
@ -50,7 +50,7 @@ func New(filename string, conf Config) (*List, error) {
}
}
if len(al.filepath) == 0 {
if al.filepath == "" {
fp := "./allow.list"
if _, err := os.Stat(fp); err == nil {
@ -60,7 +60,7 @@ func New(filename string, conf Config) (*List, error) {
}
}
if len(al.filepath) == 0 {
if al.filepath == "" {
fp := "./config/allow.list"
if _, err := os.Stat(fp); err == nil {
@ -70,12 +70,12 @@ func New(filename string, conf Config) (*List, error) {
}
}
if len(al.filepath) == 0 {
if al.filepath == "" {
if !conf.CreateIfNotExists {
return nil, errors.New("allow.list not found")
}
if len(filename) == 0 {
if filename == "" {
al.filepath = "./config/allow.list"
} else {
al.filepath = filename
@ -112,7 +112,7 @@ func (al *List) Set(vars []byte, query, comment string) error {
return errors.New("allow.list is read-only")
}
if len(query) == 0 {
if query == "" {
return errors.New("empty query")
}
@ -253,7 +253,7 @@ func (al *List) save(item Item) error {
item.Name = QueryName(query)
item.key = strings.ToLower(item.Name)
if len(item.Name) == 0 {
if item.Name == "" {
return nil
}
@ -272,7 +272,7 @@ func (al *List) save(item Item) error {
}
if index != -1 {
if len(list[index].Comment) != 0 {
if list[index].Comment != "" {
item.Comment = list[index].Comment
}
list[index] = item
@ -296,7 +296,7 @@ func (al *List) save(item Item) error {
i := 0
for _, c := range cmtLines {
if c = strings.TrimSpace(c); len(c) == 0 {
if c = strings.TrimSpace(c); c == "" {
continue
}