Initializes the graphjin instance with the config
()
| 12 | |
| 13 | // Initializes the graphjin instance with the config |
| 14 | func (gj *graphjinEngine) initConfig() error { |
| 15 | c := gj.conf |
| 16 | |
| 17 | if err := c.ValidateIsSourcesUsed(); err != nil { |
| 18 | return err |
| 19 | } |
| 20 | if err := c.NormalizeSources(); err != nil { |
| 21 | return err |
| 22 | } |
| 23 | if !c.IsSourcesUsed() { |
| 24 | if err := c.applyRelationshipOverlays(); err != nil { |
| 25 | return err |
| 26 | } |
| 27 | } |
| 28 | |
| 29 | // Validate configuration before proceeding |
| 30 | if err := c.Validate(); err != nil { |
| 31 | return err |
| 32 | } |
| 33 | |
| 34 | // Normalize databases so the primary DB is always an entry in Databases |
| 35 | c.NormalizeDatabases() |
| 36 | |
| 37 | tableMap := make(map[string]struct{}) |
| 38 | |
| 39 | for _, table := range c.Tables { |
| 40 | k := table.Schema + table.Name |
| 41 | if _, ok := tableMap[k]; ok { |
| 42 | return fmt.Errorf("duplicate table found: %s", table.Name) |
| 43 | } |
| 44 | tableMap[k] = struct{}{} |
| 45 | } |
| 46 | |
| 47 | for k, v := range c.Vars { |
| 48 | if v == "" || !strings.HasPrefix(v, "sql:") { |
| 49 | continue |
| 50 | } |
| 51 | if n, ok := isASCII(v); !ok { |
| 52 | return fmt.Errorf("variables: %s: invalid character '%s' at %d", |
| 53 | k, c.RolesQuery[:n+1], n+1) |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | gj.roles = make(map[string]*Role) |
| 58 | |
| 59 | for i, role := range c.Roles { |
| 60 | k := role.Name |
| 61 | if _, ok := gj.roles[(role.Name)]; ok { |
| 62 | return fmt.Errorf("duplicate role found: %s", role.Name) |
| 63 | } |
| 64 | |
| 65 | role.Match = sanitize(role.Match) |
| 66 | role.tm = make(map[string]*RoleTable) |
| 67 | |
| 68 | for n, t := range role.Tables { |
| 69 | role.tm[t.Schema+t.Name] = &role.Tables[n] |
| 70 | } |
| 71 |
no test coverage detected