-
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
Fix recursive deps for path-based deps #929
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# encoding: utf-8 | ||
module Inspec | ||
class Requirement | ||
attr_reader :name, :dep, :cwd, :opts | ||
def initialize(name, version_constraints, cwd, opts) | ||
@name = name | ||
@dep = Gem::Dependency.new(name, | ||
Gem::Requirement.new(Array(version_constraints)), | ||
:runtime) | ||
@opts = opts | ||
@cwd = cwd | ||
end | ||
|
||
def matches_spec?(spec) | ||
params = spec.profile.metadata.params | ||
@dep.match?(params[:name], params[:version]) | ||
end | ||
|
||
def pull | ||
case | ||
when @opts[:path] | ||
File.expand_path(@opts[:path], @cwd) | ||
else | ||
fail 'You must specify the source of the dependency (for now...)' | ||
end | ||
end | ||
|
||
def path | ||
@path ||= pull | ||
end | ||
|
||
def profile | ||
return nil if path.nil? | ||
@profile ||= Inspec::Profile.for_target(path, {}) | ||
end | ||
|
||
def self.from_metadata(dep, opts) | ||
fail 'Cannot load empty dependency.' if dep.nil? || dep.empty? | ||
name = dep[:name] || fail('You must provide a name for all dependencies') | ||
version = dep[:version] | ||
new(name, version, opts[:cwd], opts.merge(dep)) | ||
end | ||
end | ||
end |
4 changes: 4 additions & 0 deletions
4
test/unit/mock/profiles/dependencies-file/inheritance/controls/example.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# encoding: utf-8 | ||
|
||
include_controls 'profile_a' | ||
include_controls 'profile_b' |
12 changes: 12 additions & 0 deletions
12
test/unit/mock/profiles/dependencies-file/inheritance/inspec.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
name: inheritance | ||
title: InSpec example inheritance | ||
maintainer: Chef Software, Inc. | ||
copyright: Chef Software, Inc. | ||
copyright_email: support@chef.io | ||
license: Apache 2 license | ||
version: 1.0.0 | ||
depends: | ||
- name: profile_a | ||
path: ../profile_a | ||
- name: profile_b | ||
path: ../profile_b |
21 changes: 21 additions & 0 deletions
21
test/unit/mock/profiles/dependencies-file/profile_a/controls/example.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# encoding: utf-8 | ||
# copyright: 2015, The Authors | ||
# license: All rights reserved | ||
|
||
title 'sample section' | ||
include_controls 'profile_c' | ||
|
||
# you can also use plain tests | ||
describe file('/tmp') do | ||
it { should be_directory } | ||
end | ||
|
||
# you add controls here | ||
control 'tmp-1.0' do # A unique ID for this control | ||
impact 0.7 # The criticality, if this control fails. | ||
title 'Create /tmp directory' # A human-readable title | ||
desc 'An optional description...' | ||
describe file('/tmp') do # The actual test | ||
it { should be_directory } | ||
end | ||
end |
11 changes: 11 additions & 0 deletions
11
test/unit/mock/profiles/dependencies-file/profile_a/inspec.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
name: profile_a | ||
title: InSpec Profile | ||
maintainer: The Authors | ||
copyright: The Authors | ||
copyright_email: you@example.com | ||
license: All Rights Reserved | ||
summary: An InSpec Compliance Profile | ||
version: 0.1.0 | ||
depends: | ||
- name: profile_c | ||
path: ../profile_c |
20 changes: 20 additions & 0 deletions
20
test/unit/mock/profiles/dependencies-file/profile_b/controls/example.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# encoding: utf-8 | ||
# copyright: 2015, The Authors | ||
# license: All rights reserved | ||
|
||
title 'sample section' | ||
|
||
# you can also use plain tests | ||
describe file('/tmp') do | ||
it { should be_directory } | ||
end | ||
|
||
# you add controls here | ||
control 'tmp-1.0' do # A unique ID for this control | ||
impact 0.7 # The criticality, if this control fails. | ||
title 'Create /tmp directory' # A human-readable title | ||
desc 'An optional description...' | ||
describe file('/tmp') do # The actual test | ||
it { should be_directory } | ||
end | ||
end |
8 changes: 8 additions & 0 deletions
8
test/unit/mock/profiles/dependencies-file/profile_b/inspec.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
name: profile_b | ||
title: InSpec Profile | ||
maintainer: The Authors | ||
copyright: The Authors | ||
copyright_email: you@example.com | ||
license: All Rights Reserved | ||
summary: An InSpec Compliance Profile | ||
version: 0.1.0 |
8 changes: 8 additions & 0 deletions
8
test/unit/mock/profiles/dependencies-file/profile_c/inspec.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
name: profile_c | ||
title: InSpec Profile | ||
maintainer: The Authors | ||
copyright: The Authors | ||
copyright_email: you@example.com | ||
license: All Rights Reserved | ||
summary: An InSpec Compliance Profile | ||
version: 0.1.0 |
Empty file.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 would move that to the cli and set the default there, not as part of the code.
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.
Maybe we can reuse the profile path here to avoid adding a new option? Overall I think we'll need to refactor a lot of this current working directory as it is currently very confusing. Once we have the fetchers/vendoring more flushed out, I think this level of the code won't need to worry about this.
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.
👍