mirror of
https://github.com/inspec/inspec
synced 2024-11-23 13:13:22 +00:00
Merge pull request #4789 from Perceptyx/add-freebsd-package
Add suport for freebsd package resource
This commit is contained in:
commit
83f7504d7c
4 changed files with 68 additions and 2 deletions
|
@ -46,6 +46,8 @@ module Inspec::Resources
|
||||||
@pkgman = HpuxPkg.new(inspec)
|
@pkgman = HpuxPkg.new(inspec)
|
||||||
elsif ["alpine"].include?(os[:name])
|
elsif ["alpine"].include?(os[:name])
|
||||||
@pkgman = AlpinePkg.new(inspec)
|
@pkgman = AlpinePkg.new(inspec)
|
||||||
|
elsif ["freebsd"].include?(os[:name])
|
||||||
|
@pkgman = FreebsdPkg.new(inspec)
|
||||||
else
|
else
|
||||||
raise Inspec::Exceptions::ResourceSkipped, "The `package` resource is not supported on your OS yet."
|
raise Inspec::Exceptions::ResourceSkipped, "The `package` resource is not supported on your OS yet."
|
||||||
end
|
end
|
||||||
|
@ -274,6 +276,26 @@ module Inspec::Resources
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
class FreebsdPkg < PkgManagement
|
||||||
|
def info(package_name)
|
||||||
|
cmd = inspec.command("pkg info #{package_name}")
|
||||||
|
return {} if cmd.exit_status.to_i != 0
|
||||||
|
|
||||||
|
params = SimpleConfig.new(
|
||||||
|
cmd.stdout.chomp,
|
||||||
|
assignment_regex: /^\s*([^:]*?)\s*:\s*(.*?)\s*$/,
|
||||||
|
multiple_values: false
|
||||||
|
).params
|
||||||
|
|
||||||
|
{
|
||||||
|
name: params["Name"],
|
||||||
|
installed: true,
|
||||||
|
version: params["Version"],
|
||||||
|
type: "pkg",
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# Determines the installed packages on Windows using the Windows package registry entries.
|
# Determines the installed packages on Windows using the Windows package registry entries.
|
||||||
# @see: http://blogs.technet.com/b/heyscriptingguy/archive/2013/11/15/use-powershell-to-find-installed-software.aspx
|
# @see: http://blogs.technet.com/b/heyscriptingguy/archive/2013/11/15/use-powershell-to-find-installed-software.aspx
|
||||||
class WindowsPkg < PkgManagement
|
class WindowsPkg < PkgManagement
|
||||||
|
|
32
test/fixtures/cmd/pkg-info-vim-console
vendored
Normal file
32
test/fixtures/cmd/pkg-info-vim-console
vendored
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
vim-console-8.1.1954
|
||||||
|
Name : vim-console
|
||||||
|
Version : 8.1.1954
|
||||||
|
Installed on : Mon Dec 16 05:18:03 2019 PST
|
||||||
|
Origin : editors/vim-console
|
||||||
|
Architecture : FreeBSD:11:amd64
|
||||||
|
Prefix : /usr/local
|
||||||
|
Categories : editors
|
||||||
|
Licenses : VIM
|
||||||
|
Maintainer : adamw@FreeBSD.org
|
||||||
|
WWW : http://www.vim.org/
|
||||||
|
Comment : Improved version of the vi editor (console only)
|
||||||
|
Options :
|
||||||
|
DEFAULT_VIMRC : on
|
||||||
|
Annotations :
|
||||||
|
FreeBSD_version: 1103000
|
||||||
|
cpe : cpe:2.3:a:vim:vim:8.1:::::freebsd11:x64
|
||||||
|
repo_type : binary
|
||||||
|
repository : FreeBSD
|
||||||
|
Flat size : 25.0MiB
|
||||||
|
Description :
|
||||||
|
Vim is a highly configurable text editor built to enable efficient text editing.
|
||||||
|
It is an improved version of the vi editor distributed with most UNIX systems.
|
||||||
|
|
||||||
|
Vim is often called a "programmer's editor," and so useful for programming that
|
||||||
|
many consider it an entire IDE. It's not just for programmers, though. Vim is
|
||||||
|
perfect for all kinds of text editing, from composing email to editing
|
||||||
|
configuration files.
|
||||||
|
|
||||||
|
WWW: http://www.vim.org/
|
||||||
|
WWW: https://github.com/vim/vim
|
||||||
|
|
|
@ -13,8 +13,9 @@ class MockLoader
|
||||||
debian7: { name: "debian", family: "debian", release: "7", arch: "x86_64" },
|
debian7: { name: "debian", family: "debian", release: "7", arch: "x86_64" },
|
||||||
debian8: { name: "debian", family: "debian", release: "8", arch: "x86_64" },
|
debian8: { name: "debian", family: "debian", release: "8", arch: "x86_64" },
|
||||||
debian10: { name: "debian", family: "debian", release: "buster/sid", arch: "x86_64" },
|
debian10: { name: "debian", family: "debian", release: "buster/sid", arch: "x86_64" },
|
||||||
freebsd9: { name: "freebsd", family: "freebsd", release: "9", arch: "amd64" },
|
|
||||||
freebsd10: { name: "freebsd", family: "freebsd", release: "10", arch: "amd64" },
|
freebsd10: { name: "freebsd", family: "freebsd", release: "10", arch: "amd64" },
|
||||||
|
freebsd11: { name: "freebsd", family: "freebsd", release: "11", arch: "amd64" },
|
||||||
|
freebsd12: { name: "freebsd", family: "freebsd", release: "12", arch: "amd64" },
|
||||||
osx104: { name: "mac_os_x", family: "darwin", release: "10.10.4", arch: nil },
|
osx104: { name: "mac_os_x", family: "darwin", release: "10.10.4", arch: nil },
|
||||||
ubuntu1204: { name: "ubuntu", family: "debian", release: "12.04", arch: "x86_64" },
|
ubuntu1204: { name: "ubuntu", family: "debian", release: "12.04", arch: "x86_64" },
|
||||||
ubuntu1404: { name: "ubuntu", family: "debian", release: "14.04", arch: "x86_64" },
|
ubuntu1404: { name: "ubuntu", family: "debian", release: "14.04", arch: "x86_64" },
|
||||||
|
@ -275,7 +276,7 @@ class MockLoader
|
||||||
"/path/to/systemctl show --no-pager --all dbus" => cmd.call("systemctl-show-all-dbus"),
|
"/path/to/systemctl show --no-pager --all dbus" => cmd.call("systemctl-show-all-dbus"),
|
||||||
# services on macos
|
# services on macos
|
||||||
"launchctl list" => cmd.call("launchctl-list"),
|
"launchctl list" => cmd.call("launchctl-list"),
|
||||||
# services on freebsd 10
|
# services on freebsd 11
|
||||||
"service -e" => cmd.call("service-e"),
|
"service -e" => cmd.call("service-e"),
|
||||||
"service sendmail onestatus" => cmd.call("service-sendmail-onestatus"),
|
"service sendmail onestatus" => cmd.call("service-sendmail-onestatus"),
|
||||||
# services for system 5 e.g. centos6, debian 6
|
# services for system 5 e.g. centos6, debian 6
|
||||||
|
@ -353,6 +354,8 @@ class MockLoader
|
||||||
"dpkg-query -W -f='${db:Status-Abbrev} ${Package} ${Version} ${Architecture}\\n'" => cmd.call("dpkg-query-W"),
|
"dpkg-query -W -f='${db:Status-Abbrev} ${Package} ${Version} ${Architecture}\\n'" => cmd.call("dpkg-query-W"),
|
||||||
# rpm query all packages
|
# rpm query all packages
|
||||||
"rpm -qa --queryformat '%{NAME} %{VERSION}-%{RELEASE} %{ARCH}\\n'" => cmd.call("rpm-qa-queryformat"),
|
"rpm -qa --queryformat '%{NAME} %{VERSION}-%{RELEASE} %{ARCH}\\n'" => cmd.call("rpm-qa-queryformat"),
|
||||||
|
# pkg query all packages
|
||||||
|
"pkg info vim-console" => cmd.call("pkg-info-vim-console"),
|
||||||
# port netstat on solaris 10 & 11
|
# port netstat on solaris 10 & 11
|
||||||
"netstat -an -f inet -f inet6" => cmd.call("s11-netstat-an-finet-finet6"),
|
"netstat -an -f inet -f inet6" => cmd.call("s11-netstat-an-finet-finet6"),
|
||||||
# xinetd configuration
|
# xinetd configuration
|
||||||
|
|
|
@ -158,6 +158,15 @@ describe "Inspec::Resources::Package" do
|
||||||
_(resource.info).must_equal pkg
|
_(resource.info).must_equal pkg
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# freebsd
|
||||||
|
it "can parse FreeBSD packages" do
|
||||||
|
resource = MockLoader.new(:freebsd11).load_resource("package", "vim-console")
|
||||||
|
pkg = { name: "vim-console", installed: true, version: "8.1.1954", type: "pkg" }
|
||||||
|
_(resource.installed?).must_equal true
|
||||||
|
_(resource.version).must_equal "8.1.1954"
|
||||||
|
_(resource.info).must_equal pkg
|
||||||
|
end
|
||||||
|
|
||||||
# undefined
|
# undefined
|
||||||
it "verify package handling on unsupported os" do
|
it "verify package handling on unsupported os" do
|
||||||
resource = MockLoader.new(:undefined).load_resource("package", "curl")
|
resource = MockLoader.new(:undefined).load_resource("package", "curl")
|
||||||
|
|
Loading…
Reference in a new issue