crashappsec / chalk

Chalk allows you to follow code from development, through builds and into production.
https://crashoverride.com/
GNU General Public License v3.0
322 stars 11 forks source link

refactor: reduce AttrScope usage #337

Open ee7 opened 3 weeks ago

ee7 commented 3 weeks ago

Issue

269

Description

Continue (from 9c4fc0b6866102217c165b87f1f97739fe2d2103) to prepare for the new con4m, by refactoring so that we get/set everything using the top-level chalk scope with fully-dotted keys. That helps prepare for the new con4m lookup interface, which at least in con4m v2 is:

proc lookup*[T](ctx: RuntimeState, key: string): Option[T] =

where key is fully-dotted. And similarly in libcon4m:

extern c4m_value_t *
c4m_vm_attr_get(c4m_vmthread_t *tstate,
                c4m_str_t      *key,
                bool           *found);

Before this PR we were passing subscopes around, and my understanding was that in the new con4m:

Later we can try to:


I previously had about 20 more reviewable, self-contained and test-passing commits for this PR, but there were too many tricky conflicts with main, and I'd lost context on this part of the branch. So unfortunately it was best to squash before rebasing this on main, to reduce the time spent and bugs introduced when resolving conflicts.

With this PR:

$ git log -1 --format='%h %s'
67b11bf Merge branch 'main' into ee7/reduce-AttrScope
$ git grep --ignore-case --break --heading AttrScope
src/run_management.nim
20:proc getChalkScope*(): AttrScope =
27:    if v.isA(AttrScope):
30:proc sectionExists*(scope: AttrScope, s: string): bool =
41:proc con4mAttrSet*(attrs: AttrScope, fqn: string, value: Box, attrType: Con4mType) =

src/sinks.nim
175:proc getAuthConfigByName*(name: string, attr: AttrScope = AttrScope(nil)): Option[AuthConfig] =

Bad hack for trying to find missing dots:

$ git diff -U0 HEAD~1 | grep '^[+]' | grep -o 'getChalkScope().*&.*)' | grep -v '.' | wc -l
0