Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate service docs from Go files #390

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

CapacitorSet
Copy link
Contributor

There have been some talks of adding configuration examples in the source files, so I figured I'd make them machine-readable and integrate them with Jekyll.

This PR adds a script that can parse descriptions from service files and output them as a JSON file, which can then be used in Jekyll to generate the documentation files.

Example usage:

$ go run scripts/gen-service-docs.go services > /honeytrap-docs/services.json
Added service redis
$ cat /honeytrap-docs/services.json
[
    {
        "Name": "redis",
        "Description": "The Redis service will simulate a redis server. Currently the INFO command has been implemented.",
        "Config": "version=\"4.0.6\"\nos=\"Linux 4.9.49-moby x86_64\"\n",
        "Filename": "services/redis/redis.go"
    }
]

I added a quick example of the metadata in redis.go; it shouldn't take much to do the same for all services.

@codecov-io
Copy link

codecov-io commented Jul 16, 2018

Codecov Report

Merging #390 into master will increase coverage by 0.45%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #390      +/-   ##
==========================================
+ Coverage   41.22%   41.67%   +0.45%     
==========================================
  Files          81       78       -3     
  Lines        8949     8796     -153     
==========================================
- Hits         3689     3666      -23     
+ Misses       4828     4705     -123     
+ Partials      432      425       -7
Impacted Files Coverage Δ
server/honeytrap.go 3.15% <0%> (-0.29%) ⬇️
server/matchers.go 0% <0%> (ø) ⬆️
services/ldap/search.go 0% <0%> (ø) ⬆️
services/smtp/storage.go 65.15% <0%> (ø) ⬆️
services/limiter.go 0% <0%> (ø) ⬆️
server/options.go 0% <0%> (ø) ⬆️
services/ldap/bind.go 47.5% <0%> (ø) ⬆️
services/copy.go 0% <0%> (ø) ⬆️
pushers/elasticsearch/elasticsearch.go 0% <0%> (ø) ⬆️
pushers/splunk/config.go 0% <0%> (ø) ⬆️
... and 60 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b1f9418...66634b0. Read the comment docs.

@nl5887
Copy link
Contributor

nl5887 commented Aug 12, 2018

Great idea. In hindsight, this docs can be generated out of the config struct within the service configuration itself. If we add comment to there, we can reuse them in the generated docs.

@CapacitorSet
Copy link
Contributor Author

I'll try that and push a commit later today.

@CapacitorSet
Copy link
Contributor Author

CapacitorSet commented Aug 12, 2018

Done.

It now expects a struct whose name ends in Config, and for which members that have a toml tag also have a default tag.

In code, it expects this:

type redisServiceConfig struct {
	Version string `toml:"version" default:"4.0.6"`
	Os string `toml:"os" default:"Linux 4.9.49-moby x86_64"`
}

And produces this:

os = "Linux 4.9.49-moby x86_64"
version = "4.0.6"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants