mirror of
https://github.com/inspec/inspec
synced 2024-11-23 05:03:07 +00:00
Merge pull request #5302 from yarick/yt/wildcart_support_platform_name
Added platform-name wildcard support
This commit is contained in:
commit
c766519485
4 changed files with 61 additions and 9 deletions
|
@ -18,7 +18,7 @@ is a standalone structure with its own distribution and execution flow.
|
|||
|
||||
## Profile Structure
|
||||
|
||||
A profile should have the following structure::
|
||||
A profile should have the following structure:
|
||||
|
||||
```YAML
|
||||
examples/profile
|
||||
|
@ -115,8 +115,8 @@ inspec check examples/profile
|
|||
Use the `supports` setting in the `inspec.yml` file to specify one (or more) platforms for which a profile is targeting. The list of supported platforms may contain the following:
|
||||
|
||||
- Use `platform-family` to restrict to a specific platform family.
|
||||
- Use `platform-name` to restrict on a specific platform name.
|
||||
- Use `release` to restrict to a specific platform version (used with platform-name).
|
||||
- Use `platform-name` to restrict on a specific platform name. `platform-name` supports asterisk (`*`) wildcard use.
|
||||
- Use `release` to restrict to a specific platform version, and use together with `platform-name`. `release` supports asterisk (`*`) wildcard use.
|
||||
- Use `platform` to restrict on either platform-name or platform-family.
|
||||
|
||||
For compatibility we support `os-name` and `os-family`. We recommend all users
|
||||
|
@ -125,7 +125,7 @@ to change `os-name` to `platform-name` and `os-family` to `platform-family`.
|
|||
With Chef InSpec 2.0, we introduced new families to help distinguish the cloud
|
||||
platforms. The new families can restrict the platform family to `os`, `aws`, `azure` or `gcp`.
|
||||
|
||||
For example, to target anything running Debian Linux:
|
||||
For example, to target anything running Debian Linux, use:
|
||||
|
||||
```YAML
|
||||
name: ssh
|
||||
|
@ -133,7 +133,7 @@ supports:
|
|||
- platform-name: debian
|
||||
```
|
||||
|
||||
and to target only Ubuntu version 14.04
|
||||
To target only Ubuntu version 14.04, use:
|
||||
|
||||
```YAML
|
||||
name: ssh
|
||||
|
@ -142,7 +142,16 @@ supports:
|
|||
release: 14.04
|
||||
```
|
||||
|
||||
and to target the entire RedHat platform (including CentOS and Oracle Linux):
|
||||
To target the entire release of Ubuntu version 14.x, use:
|
||||
|
||||
```YAML
|
||||
name: ssh
|
||||
supports:
|
||||
- platform-name: ubuntu
|
||||
release: 14.*
|
||||
```
|
||||
|
||||
To target the entire RedHat platform (including CentOS and Oracle Linux), use:
|
||||
|
||||
```YAML
|
||||
name: ssh
|
||||
|
@ -150,7 +159,15 @@ supports:
|
|||
- platform-family: redhat
|
||||
```
|
||||
|
||||
and to target anything running on Amazon AWS:
|
||||
To target the entire Windows 2019 platform family including Datcenter and Core Servers, use:
|
||||
|
||||
```YAML
|
||||
name: ssh
|
||||
supports:
|
||||
- platform-name: windows_server_2019*
|
||||
```
|
||||
|
||||
To target anything running on Amazon AWS, use:
|
||||
|
||||
```YAML
|
||||
name: ssh
|
||||
|
@ -158,7 +175,7 @@ supports:
|
|||
- platform: aws
|
||||
```
|
||||
|
||||
and to target all of these examples in a single `inspec.yml` file:
|
||||
To target all of these examples in a single `inspec.yml` file, use:
|
||||
|
||||
```YAML
|
||||
name: ssh
|
||||
|
|
|
@ -81,7 +81,7 @@ module Inspec::Resources
|
|||
when :os, :platform then
|
||||
platform?(v)
|
||||
when :os_name, :platform_name then
|
||||
name == v
|
||||
check_name(v)
|
||||
when :release then
|
||||
check_release(v)
|
||||
end
|
||||
|
@ -99,6 +99,16 @@ module Inspec::Resources
|
|||
|
||||
private
|
||||
|
||||
def check_name(value)
|
||||
# allow wild card matching
|
||||
if value.include?("*")
|
||||
cleaned = Regexp.escape(value).gsub('\*', ".*?")
|
||||
name =~ /#{cleaned}/
|
||||
else
|
||||
name == value
|
||||
end
|
||||
end
|
||||
|
||||
def check_release(value)
|
||||
# allow wild card matching
|
||||
if value.include?("*")
|
||||
|
|
|
@ -25,6 +25,8 @@ class MockLoader
|
|||
mint17: { name: "linuxmint", family: "debian", release: "17.3", arch: "x86_64" },
|
||||
mint18: { name: "linuxmint", family: "debian", release: "18", arch: "x86_64" },
|
||||
windows: { name: "windows", family: "windows", release: "6.2.9200", arch: "x86_64" },
|
||||
windows2016: { name: "windows_server_2016_datacenter", family: "windows", release: "10.0.14393", arch: "x86_64" },
|
||||
windows2019: { name: "windows_server_2019_datacenter", family: "windows", release: "10.0.17763", arch: "x86_64" },
|
||||
wrlinux: { name: "wrlinux", family: "redhat", release: "7.0(3)I2(2)", arch: "x86_64" },
|
||||
solaris11: { name: "solaris", family: "solaris", release: "11", arch: "i386" },
|
||||
solaris10: { name: "solaris", family: "solaris", release: "10", arch: "i386" },
|
||||
|
|
|
@ -98,4 +98,27 @@ describe "Inspec::Resources::Platform" do
|
|||
]
|
||||
_(resource).wont_be :supported?, supports
|
||||
end
|
||||
|
||||
let(:resource2) { MockLoader.new(:windows2016).load_resource("platform") }
|
||||
it "loads a profile which supports platform-name windows_server_2016*" do
|
||||
supports = [
|
||||
{ 'platform-name': "windows_server_2016*" },
|
||||
]
|
||||
_(resource2).must_be :supported?, supports
|
||||
end
|
||||
|
||||
it "loads a profile which supports platform-name windows_server_2016*" do
|
||||
supports = [
|
||||
{ 'platform-name': "*2016*" },
|
||||
]
|
||||
_(resource2).must_be :supported?, supports
|
||||
end
|
||||
|
||||
it "reject a profile which supports platform-name not matching regex windows_server_2016*" do
|
||||
supports = [
|
||||
{ 'platform-name': "*2019*" },
|
||||
]
|
||||
_(resource2).wont_be :supported?, supports
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue