-
Notifications
You must be signed in to change notification settings - Fork 683
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
Allow users to reference resources from dependencies #1080
Conversation
568b818
to
a82dc95
Compare
@@ -182,58 +182,10 @@ def register_rules(ctx) | |||
|
|||
private | |||
|
|||
def block_source_info(block) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This just moved over to the rspec_formatter because I think it makes more sense there. If we want I can do that in a different pull request.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
be aware that inspec json
should return the same information. Therefore I disagree with the move to the rspec formatter
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor correction on my original comment: I move this to the rspec_runner not the rspec formatter.
I'm not sure if that difference influences your comment. My thinking was that the only callsite of this function seems to be called in check_to_example (did I miss one?) whose purpose seems tied precisely to the rspec_runner, so I moved both functions there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure why we move this to the RSpecRunner. the runner is the right place. By moving this to the RSpec runner, this method is not available to the mock runner anymore.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll move it back. The general reasons why I moved it was because with it here it makes are distinction between rspec runner a bit academic since this is tied directly to the rspec runner. But this isn't particularly a hill I care about.
a82dc95
to
3130afc
Compare
3130afc
to
45cf5e2
Compare
@@ -182,58 +182,10 @@ def register_rules(ctx) | |||
|
|||
private | |||
|
|||
def block_source_info(block) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
be aware that inspec json
should return the same information. Therefore I disagree with the move to the rspec formatter
@@ -72,6 +72,9 @@ def inspec | |||
end | |||
|
|||
# rubocop:enable Lint/NestedMethodDefinition | |||
if __resource_registry.key?(name) | |||
Inspec::Log.warn("Overwriting resource #{name}. To reference a specific version of #{name} use the resource() method") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is a nice warning
@arlimus We had a discussion about possible syntaxes for this feature. Default:
Will continue to work, gives access to the last eval'd resource with that name Option 1:
Pros
Cons
Option 2:
Cons
Pros
Option 2b:
Pros
Cons
Option 3:
With the potential shortcut (if we can implement it):
Cons
Pros
Option 4
Pros
Cons
|
My personal vote is for Option 2 for now, moving to 2b if we need more features. |
I'd like options 2 with the possibility to use 2b in combination. Option 4 may become relevant later if we have more that resources to cover in a profile |
I've been looking at 3 a little bit more this morning. I'm really skeptical that we'd be able to implement that without forcing the user to explicitly |
Thank you for listing these options! Option 1: Scrap due to naming + population of the namespace with profile names. Let's think about 2 in how it's being used:
This feels very long and clunky. But It'll do for now. Option 3 is the cleanest solution in my opinion and establishes a good pattern, by separating the point of resource declaration and resource calling. Imho it's a method to extend the context with a pre-defined name:
If you can implement it ^^, I'd 👍 this path. |
Hrm, is The following proposal is pretty different than Option 3, let's call it Option 5:
This is possible to implement (the problem with 3 is that I think we will run into issues with how the ruby parser works). It raises the question of whether, given a I think I like this the best. |
Since we return the resource, argument handling becomes as natural
|
We need to verify that once I do |
@stevendanna great question if we should load resources by default or not. We need to find a smart way to do that. Right now, we allow single loading for resources, but what you want is more like a package loading eg.
Maybe that would be written as
But we could extend that later. For now we can focus on the special case where we have to resources named the same |
I've added a test for this case. |
5b66790
to
850a430
Compare
@@ -182,58 +182,10 @@ def register_rules(ctx) | |||
|
|||
private | |||
|
|||
def block_source_info(block) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure why we move this to the RSpecRunner. the runner is the right place. By moving this to the RSpec runner, this method is not available to the mock runner anymore.
@@ -92,6 +92,14 @@ def to_s | |||
res | |||
end | |||
|
|||
define_method :add_resource do |name, new_res| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think we should make those methods private?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can, but I'm not sure that will actually do what we want. Since currently control code gets executed via instance_exec on this class, It'll still have access to private methods.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright, lets keep them as is
@@ -67,18 +68,31 @@ def profile_supports_os? | |||
|
|||
def all_rules |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should rename this to all_controls
and provide an alias for backwards-compatibility
inner_context.resource_registry[resource_name] | ||
end | ||
|
||
define_method :resource do |profile_name, resource_name, *args| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need that methods still?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That depends. Do we want a means of accessing specific resources without mutating the current namespace or not? If no, then we can certainly remove this.
850a430
to
3ccd1a2
Compare
3ccd1a2
to
ae411b3
Compare
b2a2041
to
29e88af
Compare
29e88af
to
a2da1c5
Compare
end | ||
|
||
describe gordy_config do | ||
its('version') { should eq(gordy_config.version) } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
All resources from deps are added into the control_eval_context used by the current profile. However, if there is a name conflict, the last loaded resource wins. The new `require_resource` dsl method allows the user to do the following: require_resource(profile: 'profile_name', resource: 'other', as: 'renamed') describe renamed do ... end Signed-off-by: Steven Danna <steve@chef.io>
a2da1c5
to
b2146d8
Compare
All resources from deps are added into the control_eval_context used by
the current profile. However, if there is a name conflict, the last
loaded resource wins. The new
require_resource
dsl method allows theuser to do the following:
Signed-off-by: Steven Danna steve@chef.io