diff --git a/.rubocop.yml b/.rubocop.yml index ffd1e3f61f..6b328315bd 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -13,6 +13,8 @@ require: Layout/LineLength: Max: 120 + Exclude: + - spec/facter/resolvers/gce_spec.rb Lint/RaiseException: Enabled: true @@ -51,25 +53,7 @@ Naming/ClassAndModuleCamelCase: - 'spec/mocks/**/*' Metrics/AbcSize: - Max: 16 - Exclude: - - 'spec/custom_facts/util/parser_spec.rb' - - 'spec/custom_facts/core/logging_spec.rb' - - 'lib/facter/custom_facts/util/values.rb' - - 'lib/facter/custom_facts/util/loader.rb' - - 'lib/facter/custom_facts/util/confine.rb' - - 'lib/facter/custom_facts/util/confine.rb' - - 'lib/facter/custom_facts/core/execution/windows.rb' - - 'lib/facter/custom_facts/core/execution/base.rb' - - 'lib/facter/custom_facts/core/resolvable.rb' - - 'lib/facter/resolvers/bsd/ffi/ffi_helper.rb' - - 'install.rb' - - 'scripts/generate_changelog.rb' - - 'lib/facter/resolvers/aix/ffi/ffi_helper.rb' - - 'lib/facter/custom_facts/core/execution/popen3.rb' - - 'lib/facter.rb' - - 'lib/facter/framework/parsers/query_parser.rb' - - 'lib/facter/framework/core/fact_manager.rb' + Enabled: false Metrics/PerceivedComplexity: Exclude: diff --git a/lib/facter/resolvers/freebsd/swap_memory.rb b/lib/facter/resolvers/freebsd/swap_memory.rb index 109885a168..299249fc10 100644 --- a/lib/facter/resolvers/freebsd/swap_memory.rb +++ b/lib/facter/resolvers/freebsd/swap_memory.rb @@ -13,7 +13,7 @@ def post_resolve(fact_name, _options) @fact_list.fetch(fact_name) { read_swap_memory(fact_name) } end - def read_swap_memory(fact_name) # rubocop:disable Metrics/AbcSize + def read_swap_memory(fact_name) output = Facter::Core::Execution.execute('swapinfo -k', logger: log) data = output.split("\n")[1..-1].map { |line| line.split(/\s+/) } diff --git a/lib/facter/resolvers/gce.rb b/lib/facter/resolvers/gce.rb index 54b7e72e8d..d5ae616a91 100644 --- a/lib/facter/resolvers/gce.rb +++ b/lib/facter/resolvers/gce.rb @@ -39,6 +39,15 @@ def parse_instance(gce_data) instance_data = gce_data['instance'] return if instance_data.nil? || instance_data.empty? + # See https://cloud.google.com/compute/docs/metadata for information about these values + %w[sshKeys ssh-keys].each do |name| + keys = gce_data.dig('project', 'attributes', name) + gce_data['project']['attributes'][name] = keys.strip.split("\n") if keys + + keys = instance_data.dig('attributes', name) + instance_data['attributes'][name] = keys.strip.split("\n") if keys + end + %w[image machineType zone].each do |key| instance_data[key] = instance_data[key].split('/').last if instance_data[key] end diff --git a/lib/facter/resolvers/macosx/swap_memory.rb b/lib/facter/resolvers/macosx/swap_memory.rb index 12012842b8..d254635707 100644 --- a/lib/facter/resolvers/macosx/swap_memory.rb +++ b/lib/facter/resolvers/macosx/swap_memory.rb @@ -13,7 +13,7 @@ def post_resolve(fact_name, _options) @fact_list.fetch(fact_name) { read_swap_memory(fact_name) } end - def read_swap_memory(fact_name) # rubocop:disable Metrics/AbcSize + def read_swap_memory(fact_name) output = Facter::Core::Execution.execute('sysctl -n vm.swapusage', logger: log) data = output.match(/^total = ([\d.]+)M used = ([\d.]+)M free = ([\d.]+)M (\(encrypted\))$/) diff --git a/lib/facter/resolvers/solaris/mountpoints.rb b/lib/facter/resolvers/solaris/mountpoints.rb index 6b3acb2069..8ca69c5da6 100644 --- a/lib/facter/resolvers/solaris/mountpoints.rb +++ b/lib/facter/resolvers/solaris/mountpoints.rb @@ -21,7 +21,7 @@ def exclude_auto_home_mounts! end end - def read_mounts(fact_name) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength + def read_mounts(fact_name) # rubocop:disable Metrics/MethodLength @mounts = [] @auto_home_paths = [] diff --git a/lib/facter/util/api_debugger.rb b/lib/facter/util/api_debugger.rb index 800321250b..0921f6c852 100644 --- a/lib/facter/util/api_debugger.rb +++ b/lib/facter/util/api_debugger.rb @@ -3,7 +3,7 @@ module Facter module Util module ApiDebugger - def self.prepended(receiver) # rubocop:disable Metrics/AbcSize + def self.prepended(receiver) exclude, print_caller = parse_options(ENV['API_DEBUG']) receiver_methods = receiver.instance_methods - Object.methods diff --git a/lib/facter/util/resolvers/ffi/hostname.rb b/lib/facter/util/resolvers/ffi/hostname.rb index d620e4cc46..3a1a0b1804 100644 --- a/lib/facter/util/resolvers/ffi/hostname.rb +++ b/lib/facter/util/resolvers/ffi/hostname.rb @@ -36,7 +36,7 @@ def self.getffihostname raw_hostname.read_string end - def self.getffiaddrinfo(hostname) # rubocop:disable Metrics/AbcSize + def self.getffiaddrinfo(hostname) ret = FFI::MemoryPointer.new(:pointer) hints = Facter::Util::Resolvers::Ffi::AddrInfo.new diff --git a/spec/facter/resolvers/gce_spec.rb b/spec/facter/resolvers/gce_spec.rb index e1f96347b2..35e65294fc 100644 --- a/spec/facter/resolvers/gce_spec.rb +++ b/spec/facter/resolvers/gce_spec.rb @@ -20,6 +20,15 @@ { 'instance' => { 'attributes' => { + # resolver transforms key1\nkey2 into array of keys + 'ssh-keys' => [ + 'john_doe:ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDA9D8Op48TtEiDmb+Gtna3Bs9B google-ssh {"userName":"john.doe@puppet.com","expireOn":"2020-08-13T12:17:19+0000"}', + 'jane_doe:ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDA9D8Op48TtEiDmb+Gtna3Bs9B google-ssh {"userName":"jane.doe@puppet.com","expireOn":"2020-08-13T12:17:19+0000"}' + ], + 'sshKeys' => [ + 'jill_doe:ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDA9D8Op48TtEiDmb+Gtna3Bs9B google-ssh {"userName":"jill.doe@puppet.com","expireOn":"2020-08-13T12:17:19+0000"}', + 'jacob_doe:ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDA9D8Op48TtEiDmb+Gtna3Bs9B google-ssh {"userName":"jacob.doe@puppet.com","expireOn":"2020-08-13T12:17:19+0000"}' + ] }, 'cpuPlatform' => 'Intel Broadwell', 'description' => '', @@ -122,8 +131,13 @@ }, 'project' => { 'attributes' => { - 'ssh-keys' => 'john_doe:ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDA9D8Op48TtEiDmb+Gtna3Bs9B' \ - " google-ssh {\"userName\":\"john.doe@puppet.com\",\"expireOn\":\"2020-08-13T12:17:19+0000\"}\n" + # resolver transforms key1\nkey2 into array of keys + 'ssh-keys' => ['john_doe:ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDA9D8Op48TtEiDmb+Gtna3Bs9B google-ssh {"userName":"john.doe@puppet.com","expireOn":"2020-08-13T12:17:19+0000"}', + 'jane_doe:ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDA9D8Op48TtEiDmb+Gtna3Bs9B google-ssh {"userName":"jane.doe@puppet.com","expireOn":"2020-08-13T12:17:19+0000"}'], + 'sshKeys' => [ + 'jill_doe:ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDA9D8Op48TtEiDmb+Gtna3Bs9B google-ssh {"userName":"jill.doe@puppet.com","expireOn":"2020-08-13T12:17:19+0000"}', + 'jacob_doe:ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDA9D8Op48TtEiDmb+Gtna3Bs9B google-ssh {"userName":"jacob.doe@puppet.com","expireOn":"2020-08-13T12:17:19+0000"}' + ] }, 'numericProjectId' => 728_618_928_092, 'projectId' => 'facter-performance-history' diff --git a/spec/fixtures/gce b/spec/fixtures/gce index ddf34476d3..9bb4a33d1c 100644 --- a/spec/fixtures/gce +++ b/spec/fixtures/gce @@ -1,7 +1,10 @@ { "instance": { - "attributes":{}, + "attributes":{ + "ssh-keys":"john_doe:ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDA9D8Op48TtEiDmb+Gtna3Bs9B google-ssh {\"userName\":\"john.doe@puppet.com\",\"expireOn\":\"2020-08-13T12:17:19+0000\"}\njane_doe:ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDA9D8Op48TtEiDmb+Gtna3Bs9B google-ssh {\"userName\":\"jane.doe@puppet.com\",\"expireOn\":\"2020-08-13T12:17:19+0000\"}\n", + "sshKeys":"jill_doe:ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDA9D8Op48TtEiDmb+Gtna3Bs9B google-ssh {\"userName\":\"jill.doe@puppet.com\",\"expireOn\":\"2020-08-13T12:17:19+0000\"}\njacob_doe:ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDA9D8Op48TtEiDmb+Gtna3Bs9B google-ssh {\"userName\":\"jacob.doe@puppet.com\",\"expireOn\":\"2020-08-13T12:17:19+0000\"}" + }, "cpuPlatform":"Intel Broadwell", "description":"", "disks":[{"deviceName":"instance-3","index":0,"interface":"SCSI","mode":"READ_WRITE","type":"PERSISTENT"}], @@ -63,7 +66,8 @@ { "attributes": { - "ssh-keys":"john_doe:ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDA9D8Op48TtEiDmb+Gtna3Bs9B google-ssh {\"userName\":\"john.doe@puppet.com\",\"expireOn\":\"2020-08-13T12:17:19+0000\"}\n" + "ssh-keys":"john_doe:ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDA9D8Op48TtEiDmb+Gtna3Bs9B google-ssh {\"userName\":\"john.doe@puppet.com\",\"expireOn\":\"2020-08-13T12:17:19+0000\"}\njane_doe:ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDA9D8Op48TtEiDmb+Gtna3Bs9B google-ssh {\"userName\":\"jane.doe@puppet.com\",\"expireOn\":\"2020-08-13T12:17:19+0000\"}\n", + "sshKeys":"jill_doe:ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDA9D8Op48TtEiDmb+Gtna3Bs9B google-ssh {\"userName\":\"jill.doe@puppet.com\",\"expireOn\":\"2020-08-13T12:17:19+0000\"}\njacob_doe:ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDA9D8Op48TtEiDmb+Gtna3Bs9B google-ssh {\"userName\":\"jacob.doe@puppet.com\",\"expireOn\":\"2020-08-13T12:17:19+0000\"}" }, "numericProjectId":728618928092, "projectId":"facter-performance-history"