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

Plugin Type: DSLs #3557

Merged
merged 10 commits into from Nov 29, 2018

Conversation

Projects
None yet
3 participants
@clintoncwolfe
Contributor

clintoncwolfe commented Oct 31, 2018

This PR adds 5 closely related plugin types, which allow a plugin to implement new DSL methods / keywords. The mechanism to activate the plugins are all very similar - basically, in a particular location in the code, method_missing is implemented, and is used to activate the particular type of DSL being requested.

4 of the DSL plugin types relate to code that could appear in a profile control file.

  • outer_profile_dsl plugins allow you to extend the code in profile Ruby files that appear outside control or describe blocks.
  • control_dsl plugins allow you to extend the code within control blocks.
  • describe_dsl plugins allow you to extend the code within describe blocks.
  • test_dsl plugins allow you to extend the code within it/its blocks.

Finally, the resource_dsl plugin allows you to extend the code used within custom resources.

Basic unit tests are provided to prove that the plugin types are properly defined.

A simple plugin fixture defining DSL hooks (based on favorite foods) is included, and is exercised through a set of functional tests.

The plugin developer docs are updated to describe the 5 DSLs.

Note: Implementing a plugin using any of the DSL plugin types is experimental. The contexts that are exposed to the DSL methods are private and poorly documented. The InSpec project does not claim the APIs used by these plugin types are covered by SemVer. Plugin authors are encouraged to pin tightly to the inspec gem in their gemspecs.

Motivation for this plugin comes from the desire to allow passionate community members to implement things like "2 out of 3" tests, example groups, improved serverspec compatibility, "they/their" and other "fluency" changes, as well as make it possible for future work by the InSpec team to be implemented as a core plugin, rather than a direct change to the main codebase.

@jquick

jquick approved these changes Nov 26, 2018

This is piece of art 👨‍🎨 . Love the implementation and dynamic nature of the plugin. Solid job @clintoncwolfe !!

In your `plugin.rb`, include one or more `outer_profile_dsl`, `control_dsl`, `describe_dsl`, or `resource_dsl` activation blocks. A DSL activation block *must* do two things (though it may do more):
* Return a Module that will be used as a mixin to the file, control, describe block, or resource

This comment has been minimized.

@jquick

jquick Nov 26, 2018

Contributor

Missing an ending period.

end
```
This approach may make sense among the four Profile DSLs; however the Resource DSL is quite different, and is unlikely to respond well to such an approach.

This comment has been minimized.

@jquick

jquick Nov 26, 2018

Contributor

This is some really flushed out documentation. Nice work 💯 !

@jerryaldrichiii

Solid work as usual @clintoncwolfe. Thank you especially for the plethora of comments.

# This control will pass if at least 2
# out of the describe blocks pass
control 'Like Meatloaf Sings' do

This comment has been minimized.

@jerryaldrichiii

jerryaldrichiii Nov 28, 2018

Contributor

I see what you did there...I like it. 🥇

clintoncwolfe added some commits Oct 12, 2018

Add run_inspec_process, with JSON handling, to functional helper
Signed-off-by: Clinton Wolfe <clintoncwolfe@gmail.com>
Fixture, unit, and functional tests for control_dsl
Signed-off-by: Clinton Wolfe <clintoncwolfe@gmail.com>
Implement control_dsl and describe_dsl
Signed-off-by: Clinton Wolfe <clintoncwolfe@gmail.com>
Move activate from loader to registry
Signed-off-by: Clinton Wolfe <clintoncwolfe@gmail.com>
Linting
Signed-off-by: Clinton Wolfe <clintoncwolfe@gmail.com>
Adds test_dsl
Signed-off-by: Clinton Wolfe <clintoncwolfe@gmail.com>
Add Outer Profile DSL support
Signed-off-by: Clinton Wolfe <clintoncwolfe@gmail.com>
Work towards Resource DSL; can't find custom resource
Signed-off-by: Clinton Wolfe <clintoncwolfe@gmail.com>
Resource DSL now works
Signed-off-by: Clinton Wolfe <clintoncwolfe@gmail.com>
Get unit tests passing
Signed-off-by: Clinton Wolfe <clintoncwolfe@gmail.com>

@clintoncwolfe clintoncwolfe force-pushed the cw/plugins-dsl-types branch from 79114fe to 035e15a Nov 29, 2018

@clintoncwolfe clintoncwolfe merged commit fefa6c2 into master Nov 29, 2018

3 of 4 checks passed

continuous-integration/travis-ci/pr The Travis CI build failed
Details
DCO This commit has a DCO Signed-off-by
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
expeditor/config-validation Validated your Expeditor config file
Details
@clintoncwolfe

This comment has been minimized.

Contributor

clintoncwolfe commented Nov 29, 2018

Looks like the last travis failure was all of the kicthen tests, which @jquick is investigating separately. Those are flukes.

@clintoncwolfe clintoncwolfe deleted the cw/plugins-dsl-types branch Nov 29, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment