inspec 0.30.0 → 0.31.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +50 -2
- data/Gemfile +2 -1
- data/docs/cli.rst +1 -17
- data/docs/resources.rst +128 -0
- data/docs/shell.rst +130 -0
- data/inspec.gemspec +3 -4
- data/lib/bundles/inspec-compliance/.kitchen.yml +0 -1
- data/lib/bundles/inspec-compliance/README.md +8 -3
- data/lib/bundles/inspec-compliance/api.rb +21 -6
- data/lib/bundles/inspec-compliance/bootstrap.sh +13 -9
- data/lib/bundles/inspec-compliance/cli.rb +23 -19
- data/lib/bundles/inspec-compliance/target.rb +1 -0
- data/lib/bundles/inspec-compliance/test/integration/default/cli.rb +42 -5
- data/lib/bundles/inspec-init/cli.rb +9 -0
- data/lib/bundles/inspec-supermarket/cli.rb +9 -0
- data/lib/bundles/inspec-supermarket/target.rb +2 -1
- data/lib/fetchers/local.rb +5 -2
- data/lib/fetchers/url.rb +1 -0
- data/lib/inspec/base_cli.rb +2 -1
- data/lib/inspec/cli.rb +14 -5
- data/lib/inspec/dependencies/dependency_set.rb +38 -0
- data/lib/inspec/dependencies/requirement.rb +103 -0
- data/lib/inspec/{dependencies.rb → dependencies/resolver.rb} +13 -132
- data/lib/inspec/dependencies/vendor_index.rb +98 -0
- data/lib/inspec/plugins/source_reader.rb +4 -0
- data/lib/inspec/profile.rb +2 -2
- data/lib/inspec/resource.rb +2 -0
- data/lib/inspec/runner.rb +13 -1
- data/lib/inspec/runner_mock.rb +4 -0
- data/lib/inspec/runner_rspec.rb +6 -2
- data/lib/inspec/shell.rb +22 -1
- data/lib/inspec/version.rb +1 -1
- data/lib/resources/iis_site.rb +107 -0
- data/lib/resources/port.rb +11 -4
- data/lib/resources/ssh_conf.rb +10 -2
- data/lib/resources/ssl.rb +94 -0
- data/lib/resources/xinetd.rb +11 -2
- data/lib/utils/parser.rb +6 -1
- metadata +17 -561
- data/lib/utils/hash_map.rb +0 -37
- data/tasks/maintainers.rb +0 -213
- data/test/bench/startup/startup.flat.txt +0 -1005
- data/test/bench/startup/startup.graph.html +0 -71958
- data/test/bench/startup/startup.grind.dat +0 -101602
- data/test/bench/startup/startup.stack.html +0 -24516
- data/test/bench/startup.flat.txt +0 -998
- data/test/bench/startup.graph.html +0 -71420
- data/test/bench/startup.grind.dat +0 -103554
- data/test/bench/startup.stack.html +0 -25015
- data/test/cookbooks/os_prepare/attributes/default.rb +0 -2
- data/test/cookbooks/os_prepare/files/empty.iso +0 -0
- data/test/cookbooks/os_prepare/files/example.csv +0 -7
- data/test/cookbooks/os_prepare/files/example.ini +0 -6
- data/test/cookbooks/os_prepare/files/example.json +0 -12
- data/test/cookbooks/os_prepare/files/example.yml +0 -7
- data/test/cookbooks/os_prepare/metadata.rb +0 -13
- data/test/cookbooks/os_prepare/recipes/_runit_service_centos.rb +0 -34
- data/test/cookbooks/os_prepare/recipes/_upstart_service_centos.rb +0 -25
- data/test/cookbooks/os_prepare/recipes/apache.rb +0 -14
- data/test/cookbooks/os_prepare/recipes/apt.rb +0 -20
- data/test/cookbooks/os_prepare/recipes/auditctl.rb +0 -8
- data/test/cookbooks/os_prepare/recipes/default.rb +0 -29
- data/test/cookbooks/os_prepare/recipes/file.rb +0 -46
- data/test/cookbooks/os_prepare/recipes/iptables.rb +0 -13
- data/test/cookbooks/os_prepare/recipes/json_yaml_csv_ini.rb +0 -34
- data/test/cookbooks/os_prepare/recipes/mount.rb +0 -33
- data/test/cookbooks/os_prepare/recipes/package.rb +0 -25
- data/test/cookbooks/os_prepare/recipes/postgres.rb +0 -20
- data/test/cookbooks/os_prepare/recipes/prep_container.rb +0 -15
- data/test/cookbooks/os_prepare/recipes/registry_key.rb +0 -87
- data/test/cookbooks/os_prepare/recipes/service.rb +0 -19
- data/test/cookbooks/os_prepare/templates/default/sv-default-svlog-run.erb +0 -2
- data/test/docker_run.rb +0 -162
- data/test/docker_test.rb +0 -58
- data/test/functional/helper.rb +0 -37
- data/test/functional/inheritance_test.rb +0 -62
- data/test/functional/inspec_archive_test.rb +0 -80
- data/test/functional/inspec_compliance_test.rb +0 -61
- data/test/functional/inspec_exec_json_test.rb +0 -122
- data/test/functional/inspec_exec_jsonmin_test.rb +0 -59
- data/test/functional/inspec_exec_test.rb +0 -123
- data/test/functional/inspec_json_profile_test.rb +0 -103
- data/test/functional/inspec_test.rb +0 -91
- data/test/helper.rb +0 -329
- data/test/integration/default/_debug_spec.rb +0 -8
- data/test/integration/default/apache_conf_spec.rb +0 -21
- data/test/integration/default/apt_spec.rb +0 -37
- data/test/integration/default/auditd_rules_spec.rb +0 -32
- data/test/integration/default/cmp_matcher_spec.rb +0 -115
- data/test/integration/default/csv_spec.rb +0 -11
- data/test/integration/default/etc_group_spec.rb +0 -29
- data/test/integration/default/file_spec.rb +0 -195
- data/test/integration/default/group_spec.rb +0 -59
- data/test/integration/default/ini_spec.rb +0 -11
- data/test/integration/default/iptables_spec.rb +0 -29
- data/test/integration/default/json_spec.rb +0 -11
- data/test/integration/default/kernel_module_spec.rb +0 -23
- data/test/integration/default/kernel_parameter_spec.rb +0 -60
- data/test/integration/default/mount_spec.rb +0 -19
- data/test/integration/default/os_spec.rb +0 -13
- data/test/integration/default/package_spec.rb +0 -30
- data/test/integration/default/port_spec.rb +0 -27
- data/test/integration/default/postgres_session_spec.rb +0 -13
- data/test/integration/default/powershell_spec.rb +0 -42
- data/test/integration/default/registry_key_spec.rb +0 -109
- data/test/integration/default/secpol_spec.rb +0 -11
- data/test/integration/default/service_spec.rb +0 -128
- data/test/integration/default/user_spec.rb +0 -96
- data/test/integration/default/vbscript_spec.rb +0 -22
- data/test/integration/default/wmi_spec.rb +0 -66
- data/test/integration/default/yaml_spec.rb +0 -11
- data/test/resource/command_test.rb +0 -33
- data/test/resource/dsl_test.rb +0 -45
- data/test/resource/file_test.rb +0 -146
- data/test/resource/ssh_config.rb +0 -9
- data/test/resource/sshd_config.rb +0 -9
- data/test/test-extra.yaml +0 -11
- data/test/test.yaml +0 -11
- data/test/unit/control_test.rb +0 -58
- data/test/unit/fetchers/local_test.rb +0 -67
- data/test/unit/fetchers/mock_test.rb +0 -43
- data/test/unit/fetchers/tar_test.rb +0 -36
- data/test/unit/fetchers/url_test.rb +0 -152
- data/test/unit/fetchers/zip_test.rb +0 -36
- data/test/unit/fetchers_test.rb +0 -65
- data/test/unit/metadata_test.rb +0 -137
- data/test/unit/mock/cmd/$env-PATH +0 -1
- data/test/unit/mock/cmd/Get-NetAdapter +0 -24
- data/test/unit/mock/cmd/GetUserAccount +0 -33
- data/test/unit/mock/cmd/GetWin32Group +0 -23
- data/test/unit/mock/cmd/Resolve-DnsName +0 -26
- data/test/unit/mock/cmd/Test-NetConnection +0 -4
- data/test/unit/mock/cmd/auditctl +0 -3
- data/test/unit/mock/cmd/auditctl-legacy +0 -7
- data/test/unit/mock/cmd/auditctl-s +0 -8
- data/test/unit/mock/cmd/auditpol +0 -2
- data/test/unit/mock/cmd/brew-info-jq +0 -1
- data/test/unit/mock/cmd/chage-l-root +0 -7
- data/test/unit/mock/cmd/dpkg-s-curl +0 -21
- data/test/unit/mock/cmd/dscl +0 -5
- data/test/unit/mock/cmd/env +0 -1
- data/test/unit/mock/cmd/etc-apt +0 -7
- data/test/unit/mock/cmd/find-apache2-conf-enabled +0 -1
- data/test/unit/mock/cmd/find-apache2-ports-conf +0 -1
- data/test/unit/mock/cmd/find-etc-rc-d-name-S +0 -12
- data/test/unit/mock/cmd/find-net-interface +0 -9
- data/test/unit/mock/cmd/find-xinetd.d +0 -2
- data/test/unit/mock/cmd/gem-list-local-a-q-rubocop +0 -1
- data/test/unit/mock/cmd/get-net-tcpconnection +0 -24
- data/test/unit/mock/cmd/get-netadapter-binding-bridge +0 -4
- data/test/unit/mock/cmd/get-package-firefox +0 -30
- data/test/unit/mock/cmd/get-package-ruby +0 -18
- data/test/unit/mock/cmd/get-service-dhcp +0 -10
- data/test/unit/mock/cmd/get-windows-feature +0 -7
- data/test/unit/mock/cmd/get-wmiobject +0 -9
- data/test/unit/mock/cmd/getent-hosts-example.com +0 -1
- data/test/unit/mock/cmd/getent-passwd-jfolmer +0 -1
- data/test/unit/mock/cmd/getent-passwd-root +0 -1
- data/test/unit/mock/cmd/hpux-netstat-inet +0 -10
- data/test/unit/mock/cmd/hpux-netstat-inet6 +0 -11
- data/test/unit/mock/cmd/id-chartmann +0 -1
- data/test/unit/mock/cmd/id-jfolmer +0 -1
- data/test/unit/mock/cmd/id-root +0 -1
- data/test/unit/mock/cmd/initctl--version +0 -5
- data/test/unit/mock/cmd/initctl-show-config-ssh +0 -3
- data/test/unit/mock/cmd/initctl-status-ssh +0 -1
- data/test/unit/mock/cmd/iptables-s +0 -6
- data/test/unit/mock/cmd/launchctl-list +0 -3
- data/test/unit/mock/cmd/logins-x +0 -4
- data/test/unit/mock/cmd/ls-1-etc-init.d +0 -2
- data/test/unit/mock/cmd/ls-sys-class-net-br +0 -2
- data/test/unit/mock/cmd/lsmod +0 -2
- data/test/unit/mock/cmd/lsof-nP-i-FpctPn +0 -63
- data/test/unit/mock/cmd/mount +0 -1
- data/test/unit/mock/cmd/mount-multiple +0 -2
- data/test/unit/mock/cmd/netstat-an.utf8 +0 -13
- data/test/unit/mock/cmd/netstat-tulpen +0 -6
- data/test/unit/mock/cmd/npm-ls-g--json-bower +0 -9
- data/test/unit/mock/cmd/pacman-qi-curl +0 -21
- data/test/unit/mock/cmd/ping-example.com +0 -6
- data/test/unit/mock/cmd/pip-show-jinja2 +0 -11
- data/test/unit/mock/cmd/pkg-info-system-file-system-zfs +0 -8
- data/test/unit/mock/cmd/pkginfo-l-SUNWzfsr +0 -7
- data/test/unit/mock/cmd/ps-aux +0 -5
- data/test/unit/mock/cmd/ps-auxZ +0 -3
- data/test/unit/mock/cmd/pw-usershow-root-7 +0 -1
- data/test/unit/mock/cmd/reg_schedule +0 -6
- data/test/unit/mock/cmd/rpm-qia-curl +0 -24
- data/test/unit/mock/cmd/s11-netstat-an-finet-finet6 +0 -32
- data/test/unit/mock/cmd/sbin_sysctl +0 -1
- data/test/unit/mock/cmd/secedit-export +0 -7
- data/test/unit/mock/cmd/service-e +0 -2
- data/test/unit/mock/cmd/service-sendmail-onestatus +0 -3
- data/test/unit/mock/cmd/service-sshd-status +0 -1
- data/test/unit/mock/cmd/sockstat +0 -5
- data/test/unit/mock/cmd/success +0 -0
- data/test/unit/mock/cmd/swlist-l-product +0 -1
- data/test/unit/mock/cmd/systemctl-show-all-dbus +0 -6
- data/test/unit/mock/cmd/systemctl-show-all-sshd +0 -7
- data/test/unit/mock/cmd/win32_product +0 -8
- data/test/unit/mock/cmd/yum-repolist-all +0 -52
- data/test/unit/mock/files/apache2.conf +0 -14
- data/test/unit/mock/files/auditd.conf +0 -4
- data/test/unit/mock/files/bond0 +0 -37
- data/test/unit/mock/files/etcgroup +0 -3
- data/test/unit/mock/files/example.csv +0 -6
- data/test/unit/mock/files/grub.conf +0 -21
- data/test/unit/mock/files/inetd.conf +0 -2
- data/test/unit/mock/files/kitchen.yml +0 -7
- data/test/unit/mock/files/limits.conf +0 -5
- data/test/unit/mock/files/login.defs +0 -5
- data/test/unit/mock/files/mysql.conf +0 -8
- data/test/unit/mock/files/mysql2.conf +0 -2
- data/test/unit/mock/files/ntp.conf +0 -5
- data/test/unit/mock/files/passwd +0 -2
- data/test/unit/mock/files/policyfile.lock.json +0 -12
- data/test/unit/mock/files/ports.conf +0 -6
- data/test/unit/mock/files/rootwrap.conf +0 -7
- data/test/unit/mock/files/serve-cgi-bin.conf +0 -20
- data/test/unit/mock/files/shadow +0 -2
- data/test/unit/mock/files/ssh_config +0 -5
- data/test/unit/mock/files/sshd_config +0 -7
- data/test/unit/mock/files/sysctl.conf +0 -7
- data/test/unit/mock/files/xinetd.conf +0 -9
- data/test/unit/mock/files/xinetd.d/.gitkeep +0 -0
- data/test/unit/mock/files/xinetd.d_chargen-dgram +0 -9
- data/test/unit/mock/files/xinetd.d_chargen-stream +0 -9
- data/test/unit/mock/profiles/complete-metadata/inspec.yml +0 -7
- data/test/unit/mock/profiles/complete-profile/controls/filesystem_spec.rb +0 -16
- data/test/unit/mock/profiles/complete-profile/inspec.yml +0 -10
- data/test/unit/mock/profiles/complete-profile/libraries/testlib.rb +0 -1
- data/test/unit/mock/profiles/empty-metadata/inspec.yml +0 -0
- data/test/unit/mock/profiles/legacy-complete-metadata/metadata.rb +0 -7
- data/test/unit/mock/profiles/legacy-complete-metadata/test/.gitkeep +0 -0
- data/test/unit/mock/profiles/legacy-empty-metadata/controls/.gitkeep +0 -0
- data/test/unit/mock/profiles/legacy-empty-metadata/metadata.rb +0 -0
- data/test/unit/mock/profiles/legacy-simple-metadata/metadata.rb +0 -1
- data/test/unit/mock/profiles/legacy-simple-metadata/test/.gitkeep +0 -0
- data/test/unit/mock/profiles/library/controls/filesystem_spec.rb +0 -7
- data/test/unit/mock/profiles/library/inspec.yml +0 -10
- data/test/unit/mock/profiles/library/libraries/gordonlib.rb +0 -2
- data/test/unit/mock/profiles/library/libraries/testlib.rb +0 -12
- data/test/unit/mock/profiles/resource-tiny/inspec.yml +0 -10
- data/test/unit/mock/profiles/resource-tiny/libraries/resource.rb +0 -3
- data/test/unit/mock/profiles/simple-metadata/inspec.yml +0 -1
- data/test/unit/mock/profiles/skippy-profile-os/controls/one.rb +0 -3
- data/test/unit/mock/profiles/skippy-profile-os/inspec.yml +0 -5
- data/test/unit/mock/profiles/spec_only/specfile.rb +0 -11
- data/test/unit/mock/profiles/supported_inspec/inspec.yml +0 -2
- data/test/unit/mock/profiles/unsupported_inspec/inspec.yml +0 -2
- data/test/unit/objects_test.rb +0 -65
- data/test/unit/plugin_test.rb +0 -44
- data/test/unit/plugins/resource_test.rb +0 -60
- data/test/unit/profile_context_test.rb +0 -345
- data/test/unit/profile_test.rb +0 -252
- data/test/unit/resources/apache_conf_test.rb +0 -31
- data/test/unit/resources/apt_test.rb +0 -46
- data/test/unit/resources/audit_policy_test.rb +0 -13
- data/test/unit/resources/auditd_conf_test.rb +0 -15
- data/test/unit/resources/auditd_rules_test.rb +0 -91
- data/test/unit/resources/bash_test.rb +0 -29
- data/test/unit/resources/bond_test.rb +0 -24
- data/test/unit/resources/bridge_test.rb +0 -56
- data/test/unit/resources/csv_test.rb +0 -35
- data/test/unit/resources/etc_group_test.rb +0 -37
- data/test/unit/resources/file_test.rb +0 -202
- data/test/unit/resources/gem_test.rb +0 -20
- data/test/unit/resources/group_test.rb +0 -96
- data/test/unit/resources/grub_conf_test.rb +0 -29
- data/test/unit/resources/host_test.rb +0 -38
- data/test/unit/resources/inetd_conf_test.rb +0 -15
- data/test/unit/resources/ini_test.rb +0 -16
- data/test/unit/resources/interface_test.rb +0 -54
- data/test/unit/resources/iptables_test.rb +0 -35
- data/test/unit/resources/json_test.rb +0 -36
- data/test/unit/resources/kernel_module_test.rb +0 -23
- data/test/unit/resources/kernel_parameter_test.rb +0 -13
- data/test/unit/resources/limits_conf_test.rb +0 -14
- data/test/unit/resources/login_def_test.rb +0 -16
- data/test/unit/resources/mount_test.rb +0 -26
- data/test/unit/resources/mysql_conf_test.rb +0 -14
- data/test/unit/resources/npm_test.rb +0 -20
- data/test/unit/resources/ntp_conf_test.rb +0 -16
- data/test/unit/resources/oneget_test.rb +0 -45
- data/test/unit/resources/os_env_test.rb +0 -18
- data/test/unit/resources/os_test.rb +0 -40
- data/test/unit/resources/package_test.rb +0 -87
- data/test/unit/resources/parse_config_test.rb +0 -26
- data/test/unit/resources/passwd_test.rb +0 -111
- data/test/unit/resources/pip_test.rb +0 -15
- data/test/unit/resources/port_test.rb +0 -165
- data/test/unit/resources/powershell_test.rb +0 -32
- data/test/unit/resources/processes_test.rb +0 -72
- data/test/unit/resources/registry_key_test.rb +0 -18
- data/test/unit/resources/security_policy_test.rb +0 -16
- data/test/unit/resources/service_test.rb +0 -305
- data/test/unit/resources/shadow_test.rb +0 -67
- data/test/unit/resources/ssh_conf_test.rb +0 -33
- data/test/unit/resources/user_test.rb +0 -124
- data/test/unit/resources/vbscript_test.rb +0 -18
- data/test/unit/resources/windows_feature.rb +0 -17
- data/test/unit/resources/wmi_test.rb +0 -42
- data/test/unit/resources/xinetd_test.rb +0 -60
- data/test/unit/resources/yaml_test.rb +0 -34
- data/test/unit/resources/yum_test.rb +0 -68
- data/test/unit/shell_detector_test.rb +0 -78
- data/test/unit/source_reader_test.rb +0 -17
- data/test/unit/source_readers/flat_test.rb +0 -61
- data/test/unit/source_readers/inspec_test.rb +0 -38
- data/test/unit/utils/filter_array_test.rb +0 -59
- data/test/unit/utils/filter_table_test.rb +0 -177
- data/test/unit/utils/find_files_test.rb +0 -23
- data/test/unit/utils/passwd_parser_test.rb +0 -32
- data/test/unit/utils/simpleconfig_test.rb +0 -80
- data/test/unit/utils/solaris_netstat_parser.rb +0 -124
data/lib/utils/hash_map.rb
DELETED
@@ -1,37 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
# author: Dominik Richter
|
3
|
-
# author: Christoph Hartmann
|
4
|
-
|
5
|
-
class HashMap
|
6
|
-
class << self
|
7
|
-
def [](hash, *keys)
|
8
|
-
return hash if keys.empty? || hash.nil?
|
9
|
-
key = keys.shift
|
10
|
-
if hash.is_a?(Array)
|
11
|
-
map = hash.map { |i| [i, key] }
|
12
|
-
else
|
13
|
-
map = hash[key]
|
14
|
-
end
|
15
|
-
[map, *keys]
|
16
|
-
rescue NoMethodError => _
|
17
|
-
nil
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
class StringMap
|
23
|
-
class << self
|
24
|
-
def [](hash, *keys)
|
25
|
-
return hash if keys.empty? || hash.nil?
|
26
|
-
key = keys.shift
|
27
|
-
if hash.is_a?(Array)
|
28
|
-
map = hash.map { |i| [i, key] }
|
29
|
-
else
|
30
|
-
map = hash[key]
|
31
|
-
end
|
32
|
-
[map, *keys]
|
33
|
-
rescue NoMethodError => _
|
34
|
-
nil
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
data/tasks/maintainers.rb
DELETED
@@ -1,213 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
# Copyright:: Copyright (c) 2015 Chef Software, Inc.
|
3
|
-
# License:: Apache License, Version 2.0
|
4
|
-
#
|
5
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
-
# you may not use this file except in compliance with the License.
|
7
|
-
# You may obtain a copy of the License at
|
8
|
-
#
|
9
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
-
#
|
11
|
-
# Unless required by applicable law or agreed to in writing, software
|
12
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
-
# See the License for the specific language governing permissions and
|
15
|
-
# limitations under the License.
|
16
|
-
#
|
17
|
-
|
18
|
-
require 'rake'
|
19
|
-
|
20
|
-
SOURCE = File.join(File.dirname(__FILE__), '..', 'MAINTAINERS.toml')
|
21
|
-
TARGET = File.join(File.dirname(__FILE__), '..', 'MAINTAINERS.md')
|
22
|
-
|
23
|
-
# The list of repositories that teams should own
|
24
|
-
REPOSITORIES = ['chef/inspec'].freeze
|
25
|
-
|
26
|
-
begin
|
27
|
-
require 'tomlrb'
|
28
|
-
require 'octokit'
|
29
|
-
require 'pp'
|
30
|
-
task default: :generate
|
31
|
-
|
32
|
-
namespace :maintainers do
|
33
|
-
desc 'Generate MarkDown version of MAINTAINERS file'
|
34
|
-
task :generate do
|
35
|
-
maintainers = Tomlrb.load_file SOURCE
|
36
|
-
out = "<!-- This is a generated file. Please do not edit directly -->\n\n"
|
37
|
-
out << "<!-- Modify MAINTAINERS.toml and run `rake maintainers:generate` to regenerate. -->\n\n"
|
38
|
-
out << '# ' + maintainers['Preamble']['title'] + "\n\n"
|
39
|
-
out << maintainers['Preamble']['text'] + "\n"
|
40
|
-
out << components(maintainers['people'], maintainers['Org']['Components'])
|
41
|
-
File.open(TARGET, 'w') { |fn|
|
42
|
-
fn.write out
|
43
|
-
}
|
44
|
-
end
|
45
|
-
|
46
|
-
desc 'Synchronize GitHub teams'
|
47
|
-
task :synchronize do
|
48
|
-
Octokit.auto_paginate = true
|
49
|
-
github_teams
|
50
|
-
prepare_teams(source['Org']['Components'].dup)
|
51
|
-
sync_teams!
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
def github
|
56
|
-
@github ||= Octokit::Client.new(netrc: true)
|
57
|
-
end
|
58
|
-
|
59
|
-
def source
|
60
|
-
@source ||= Tomlrb.load_file SOURCE
|
61
|
-
end
|
62
|
-
|
63
|
-
def teams
|
64
|
-
@teams ||= { 'inspec-maintainers' => { 'title' => 'Maintainers of the InSpec toolset' } }
|
65
|
-
end
|
66
|
-
|
67
|
-
def add_members(team, name)
|
68
|
-
teams['inspec-maintainers']['members'] ||= []
|
69
|
-
teams['inspec-maintainers']['members'] << name
|
70
|
-
teams[team] ||= {}
|
71
|
-
teams[team]['members'] ||= []
|
72
|
-
teams[team]['members'] << name
|
73
|
-
end
|
74
|
-
|
75
|
-
def set_team_title(team, title)
|
76
|
-
teams[team] ||= {}
|
77
|
-
teams[team]['title'] = title
|
78
|
-
end
|
79
|
-
|
80
|
-
def gh_teams
|
81
|
-
@gh_teams ||= {}
|
82
|
-
end
|
83
|
-
|
84
|
-
# we have to resolve team names to ids. While we're at it, we can get the privacy
|
85
|
-
# setting, so we know whether we need to update it
|
86
|
-
def github_teams
|
87
|
-
github.org_teams('chef').each do |team|
|
88
|
-
gh_teams[team[:slug]] = { 'id' => team[:id], 'privacy' => team[:privacy] }
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
def get_github_team(team)
|
93
|
-
github.team_members(gh_teams[team]['id']).map do |member|
|
94
|
-
member[:login]
|
95
|
-
end.sort.uniq.map(&:downcase)
|
96
|
-
rescue
|
97
|
-
[]
|
98
|
-
end
|
99
|
-
|
100
|
-
def create_team(team)
|
101
|
-
puts "creating new github team: #{team} with title: #{teams[team]['title']} "
|
102
|
-
t = github.create_team('chef', name: team, description: teams[team]['title'],
|
103
|
-
privacy: 'closed', repo_names: REPOSITORIES,
|
104
|
-
accept: 'application/vnd.github.ironman-preview+json')
|
105
|
-
gh_teams[team] = { 'id' => t[:id], 'privacy' => t[:privacy] }
|
106
|
-
end
|
107
|
-
|
108
|
-
def compare_teams(current, desired)
|
109
|
-
# additions are the subtraction of the current state from the desired state
|
110
|
-
# deletions are the subtraction of the desired state from the current state
|
111
|
-
[desired - current, current - desired]
|
112
|
-
end
|
113
|
-
|
114
|
-
def prepare_teams(cmp)
|
115
|
-
%w{text paths}.each { |k| cmp.delete(k) }
|
116
|
-
if cmp.key?('team')
|
117
|
-
team = cmp.delete('team')
|
118
|
-
add_members(team, cmp.delete('lieutenant')) if cmp.key?('lieutenant')
|
119
|
-
add_members(team, cmp.delete('maintainers')) if cmp.key?('maintainers')
|
120
|
-
set_team_title(team, cmp.delete('title'))
|
121
|
-
else
|
122
|
-
%w{maintainers lieutenant title}.each { |k| cmp.delete(k) }
|
123
|
-
end
|
124
|
-
cmp.each { |_k, v| prepare_teams(v) }
|
125
|
-
end
|
126
|
-
|
127
|
-
def update_team(team, additions, deletions)
|
128
|
-
create_team(team) unless gh_teams.key?(team)
|
129
|
-
update_team_privacy(team)
|
130
|
-
add_team_members(team, additions)
|
131
|
-
remove_team_members(team, deletions)
|
132
|
-
rescue
|
133
|
-
puts "failed for #{team}"
|
134
|
-
end
|
135
|
-
|
136
|
-
def update_team_privacy(_team)
|
137
|
-
# return
|
138
|
-
# return if gh_teams[team]['privacy'] == 'closed'
|
139
|
-
# puts "Setting #{team} privacy to closed from #{gh_teams[team]['privacy']}"
|
140
|
-
# github.update_team(gh_teams[team]['id'], privacy: 'closed',
|
141
|
-
# accept: 'application/vnd.github.ironman-preview+json')
|
142
|
-
end
|
143
|
-
|
144
|
-
def add_team_members(team, additions)
|
145
|
-
additions.each do |member|
|
146
|
-
puts "Adding #{member} to #{team}"
|
147
|
-
github.add_team_membership(gh_teams[team]['id'], member, role: 'member',
|
148
|
-
accept: 'application/vnd.github.ironman-preview+json')
|
149
|
-
end
|
150
|
-
end
|
151
|
-
|
152
|
-
def remove_team_members(team, deletions)
|
153
|
-
deletions.each do |member|
|
154
|
-
puts "Removing #{member} from #{team}"
|
155
|
-
github.remove_team_membership(gh_teams[team]['id'], member,
|
156
|
-
accept: 'application/vnd.github.ironman-preview+json')
|
157
|
-
end
|
158
|
-
end
|
159
|
-
|
160
|
-
def sync_teams!
|
161
|
-
teams.each do |name, details|
|
162
|
-
current = get_github_team(name)
|
163
|
-
desired = details['members'].flatten.sort.uniq.map(&:downcase)
|
164
|
-
additions, deletions = compare_teams(current, desired)
|
165
|
-
update_team(name, additions, deletions)
|
166
|
-
end
|
167
|
-
end
|
168
|
-
|
169
|
-
def get_person(person)
|
170
|
-
source['people'][person]
|
171
|
-
end
|
172
|
-
|
173
|
-
def components(list, cmp)
|
174
|
-
out = '## ' + cmp.delete('title') + "\n\n"
|
175
|
-
out << cmp.delete('text') + "\n" if cmp.key?('text')
|
176
|
-
out << "To mention the team, use @chef/#{cmp.delete('team')}\n\n" if cmp.key?('team')
|
177
|
-
if cmp.key?('lieutenant')
|
178
|
-
out << "### Lieutenant\n\n"
|
179
|
-
out << person(list, cmp.delete('lieutenant')) + "\n\n"
|
180
|
-
end
|
181
|
-
out << maintainers(list, cmp.delete('maintainers')) + "\n" if cmp.key?('maintainers')
|
182
|
-
cmp.delete('paths')
|
183
|
-
cmp.each { |_k, v| out << components(list, v) }
|
184
|
-
out
|
185
|
-
end
|
186
|
-
|
187
|
-
def maintainers(list, people)
|
188
|
-
o = "### Maintainers\n\n"
|
189
|
-
people.each do |p|
|
190
|
-
o << person(list, p) + "\n"
|
191
|
-
end
|
192
|
-
o
|
193
|
-
end
|
194
|
-
|
195
|
-
# rubocop:disable Metrics/AbcSize
|
196
|
-
def person(list, person)
|
197
|
-
out = if list[person].key?('GitHub')
|
198
|
-
"* [#{list[person]['Name']}](https://github.com/#{list[person]['GitHub']})"
|
199
|
-
else
|
200
|
-
"* #{list[person]['Name']}"
|
201
|
-
end
|
202
|
-
out << "\n * IRC - #{list[person]['IRC']}" if list[person].key?('IRC')
|
203
|
-
out << "\n * [@#{list[person]['Twitter']}](https://twitter.com/#{list[person]['Twitter']})" if list[person].key?('Twitter')
|
204
|
-
out << "\n * [#{list[person]['email']}](mailto:#{list[person]['email']})" if list[person].key?('email')
|
205
|
-
out << "\n * #{list[person]['phone']}" if list[person].key?('phone')
|
206
|
-
out << "\n * [ServerFault](#{list[person]['ServerFault']})" if list[person].key?('ServerFault')
|
207
|
-
out
|
208
|
-
end
|
209
|
-
# rubocop:enable all
|
210
|
-
|
211
|
-
rescue LoadError
|
212
|
-
STDERR.puts "\n*** TomlRb not available.\n\n"
|
213
|
-
end
|