splunk / contentctl

Splunk Content Control Tool
Apache License 2.0
80 stars 20 forks source link

Add simple API for a more #170

Closed pyth0n1c closed 2 months ago

pyth0n1c commented 2 months ago

Add a simple was to get a contentctl config and run contentctl operations without going through the Command Line Interface/main function in contentctl.

Assuming that you are already in a repo that has contentctl.yml, the following should work:

from contentctl import api
from contentctl.contentctl import validate_func

#loads by default from ./contentctl.yml, but that can be overridden. 
#config is a dict that overrides default values in that file

cfg = api.configFromFile(config={'enrichments':True})
director_obj = validate_func(cfg)

#director_obj has all your validated, constructed python objects (if you try to interactively print this out, you will get an error. that is expected)
josehelps commented 2 months ago

Nice thank you for the quick turn around. Waiting on CI but LGTM.

cmcginley-splunk commented 2 months ago

Could I similarly call test_common_func(cfg)?

pyth0n1c commented 2 months ago

Could I similarly call test_common_func(cfg)?

Yes, this should work too. I moved the creation of the container objects (part of the test object, not the underlying actual containers themselves) from main into test_common_func to account for this: https://github.com/splunk/contentctl/blob/bf63cdd76dc8992fc41dfafa20ca8dd8ab3752ad/contentctl/contentctl.py#L105-L108

Doing a bit more logic in the class's pydantic validator functions might be better for this, but we can chat about that.