MCPcopy
hub / github.com/dosco/graphjin / initConfig

Method initConfig

core/init.go:14–105  ·  view source on GitHub ↗

Initializes the graphjin instance with the config

()

Source from the content-addressed store, hash-verified

12
13// Initializes the graphjin instance with the config
14func (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

Callers 3

newGraphJinMethod · 0.95

Calls 8

isASCIIFunction · 0.85
sanitizeFunction · 0.85
ValidateIsSourcesUsedMethod · 0.80
NormalizeSourcesMethod · 0.80
IsSourcesUsedMethod · 0.80
ValidateMethod · 0.80
NormalizeDatabasesMethod · 0.80

Tested by

no test coverage detected