This commit is contained in:
Anthony Riley II 2023-12-08 10:41:32 -08:00
Родитель 680f1b9831
Коммит ef8cc2ab41
Не найден ключ, соответствующий данной подписи
42 изменённых файлов: 60 добавлений и 24 удалений

Просмотреть файл

@ -1,5 +1,5 @@
#!/usr/bin/env ruby
# frozen_literal_string: true
# frozen_string_literal: true
#
require "bundler/setup"
require "octofacts_updater"

Просмотреть файл

@ -1,4 +1,4 @@
# frozen_literal_string: true
# frozen_string_literal: true
require "octofacts/constructors/from_file"
require "octofacts/constructors/from_index"
require "octofacts/manipulators"

Просмотреть файл

@ -1,4 +1,4 @@
# frozen_literal_string: true
# frozen_string_literal: true
module Octofacts
module Backends
# This is a template class to define the minimum API to be implemented

Просмотреть файл

@ -1,4 +1,4 @@
# frozen_literal_string: true
# frozen_string_literal: true
require "yaml"
require "set"

Просмотреть файл

@ -1,4 +1,4 @@
# frozen_literal_string: true
# frozen_string_literal: true
#
require "yaml"

Просмотреть файл

@ -1,3 +1,4 @@
# frozen_string_literal: true
module Octofacts
# Octofacts.from_index(options) - Construct Octofacts::Facts from an index file.
#

Просмотреть файл

@ -1,4 +1,4 @@
# # frozen_string_literal: true
# frozen_string_literal: true
module Octofacts
class Manipulators
# Delete a fact from a hash.

Просмотреть файл

@ -1,3 +1,4 @@
# frozen_string_literal: true
# This class contains methods to interact with an external node classifier.
require "open3"

Просмотреть файл

@ -1,3 +1,4 @@
# frozen_string_literal: true
# This class reads a YAML file from the local file system so that it can be used as a source
# in octofacts-updater. This was originally intended for a quickstart tutorial, since it requires
# no real configuration. However it could also be used in production, if the user wants to create

Просмотреть файл

@ -1,3 +1,4 @@
# frozen_string_literal: true
# This class interacts with puppetdb to pull the facts from the recent
# run of Puppet on a given node. This uses octocatalog-diff on the back end to
# pull the facts from puppetdb.

Просмотреть файл

@ -1,3 +1,4 @@
# frozen_string_literal: true
# This class interacts with a puppetserver to obtain facts from that server's YAML cache.
# This is achieved by SSH-ing to the server and obtaining the fact file directly from the
# puppetserver's cache. This can also be used to SSH to an actual node and run a command,

Просмотреть файл

@ -1,3 +1,4 @@
# frozen_string_literal: true
module OctofactsUpdater
VERSION = File.read(File.expand_path("../../.version", File.dirname(__FILE__))).strip
end

Просмотреть файл

@ -1,3 +1,4 @@
# frozen_string_literal: true
# coding: utf-8
Gem::Specification.new do |spec|

Просмотреть файл

@ -1,3 +1,4 @@
# frozen_string_literal: true
# coding: utf-8
Gem::Specification.new do |spec|

Просмотреть файл

@ -5,7 +5,7 @@
## 3. Commit changes, PR, and merge to master
## 4. Check out master branch locally
## 5. Run `bundle exec rake gem:release`
# frozen_string_literal: true
require "fileutils"
require "open3"
require "shellwords"

Просмотреть файл

@ -1,4 +1,5 @@
#!/usr/bin/env ruby
# frozen_string_literal: true
require "bundler/setup"
require "octofacts"

Просмотреть файл

@ -1,3 +1,4 @@
# frozen_string_literal: true
require_relative "../../../../spec/spec_helper"
describe "test::one" do
@ -7,7 +8,7 @@ describe "test::one" do
let(:facts) do
{
ec2: true,
ec2_metadata: { placement: { :"availability-zone" => "us-foo-1a" } },
ec2_metadata: { placement: { :"availability-zone" : "us-foo-1a" } },
gid: "root",
id: "root"
}

Просмотреть файл

@ -1,3 +1,4 @@
# frozen_string_literal: true
# spec_helper for rspec-puppet fixture
require_relative "../../../lib/octofacts"

Просмотреть файл

@ -1,3 +1,4 @@
# frozen_string_literal: true
require "spec_helper"
describe Octofacts::Backends::Index do

Просмотреть файл

@ -1,3 +1,4 @@
# frozen_string_literal: true
require "spec_helper"
describe Octofacts::Backends::YamlFile do

Просмотреть файл

@ -1,3 +1,4 @@
# frozen_string_literal: true
require "spec_helper"
describe Octofacts do

Просмотреть файл

@ -1,3 +1,4 @@
# frozen_string_literal: true
# Make sure the examples in the README document actually work. :-)
require "spec_helper"

Просмотреть файл

@ -1,3 +1,4 @@
# frozen_string_literal: true
require "spec_helper"
describe Octofacts::Facts do

Просмотреть файл

@ -1,3 +1,4 @@
# frozen_string_literal: true
require "spec_helper"
describe Octofacts::Manipulators do

Просмотреть файл

@ -1,3 +1,4 @@
# frozen_string_literal: true
require "spec_helper"
require "yaml"

Просмотреть файл

@ -1,3 +1,4 @@
# frozen_string_literal: true
require "spec_helper"
describe Octofacts::Manipulators do

Просмотреть файл

@ -1,3 +1,5 @@
# frozen_string_literal: true
#
require "spec_helper"
# FIXME: Remove when real specs are added

Просмотреть файл

@ -1,3 +1,4 @@
# frozen_string_literal: true
module Octofacts
class Spec
def self.fixture_root

Просмотреть файл

@ -1,3 +1,4 @@
# frozen_string_literal: true
require "spec_helper"
describe Octofacts::Util::Config do

Просмотреть файл

@ -1,3 +1,4 @@
# frozen_string_literal: true
describe Octofacts::Util::Keys do
describe "#downcase_keys!" do
let(:facts) do
@ -7,8 +8,8 @@ describe Octofacts::Util::Keys do
it "should work" do
f = facts
result = described_class.downcase_keys!(f)
expect(f).to eq({"foo" => "foo-value", baz: "baz-value", "bar" => "bar-value", buzz: "buzz-value"})
expect(result).to eq({"foo" => "foo-value", baz: "baz-value", "bar" => "bar-value", buzz: "buzz-value"})
expect(f).to eq({"foo": "foo-value", baz: "baz-value", "bar": "bar-value", buzz: "buzz-value"})
expect(result).to eq({"foo": "foo-value", baz: "baz-value", "bar": "bar-value", buzz: "buzz-value"})
end
end

Просмотреть файл

@ -1,3 +1,4 @@
# frozen_string_literal: true
require "spec_helper"
describe OctofactsUpdater::FactIndex do

Просмотреть файл

@ -1,3 +1,4 @@
# frozen_string_literal: true
require "spec_helper"
describe OctofactsUpdater::Fact do

Просмотреть файл

@ -1,11 +1,12 @@
# frozen_string_literal: true
require "spec_helper"
describe OctofactsUpdater::Fixture do
describe "#make" do
let(:hostname) { "HostName" }
let(:config) {{ "enc" => { "path" => "/foo" }, "puppetdb" => { "url" => "https://puppetdb.example.com:8081" } }}
let(:enc_return) {{ "parameters" => { "fizz" => "buzz" }, "classes" => ["class1", "class2"] }}
let(:fact_hash_with_values) {{ "name" => hostname, "values" => { "foo" => "bar" } }}
let(:config) { { "enc" => { "path" => "/foo" }, "puppetdb" => { "url" => "https://puppetdb.example.com:8081" } } }
let(:enc_return) { { "parameters" => { "fizz" => "buzz" }, "classes" => ["class1", "class2"] } }
let(:fact_hash_with_values) { { "name" => hostname, "values" => { "foo" => "bar" } } }
it "should instantiate and return a fixture object with the given facts" do
expect(OctofactsUpdater::Service::ENC).to receive(:run_enc).with(hostname, config).and_return(enc_return)

Просмотреть файл

@ -1,3 +1,4 @@
# frozen_string_literal: true
require "spec_helper"
describe OctofactsUpdater::VERSION do

Просмотреть файл

@ -1,3 +1,4 @@
# frozen_string_literal: true
require "spec_helper"
describe OctofactsUpdater::Plugin do

Просмотреть файл

@ -1,3 +1,4 @@
# frozen_string_literal: true
require "spec_helper"
require "ipaddr"

Просмотреть файл

@ -1,9 +1,10 @@
# frozen_string_literal: true
require "spec_helper"
describe "sshfp_randomize plugin" do
let(:plugin) { OctofactsUpdater::Plugin.plugins[:sshfp_randomize] }
let(:value) { "SSHFP 1 1 0123456789abcdef0123456789abcdef01234567\nSSHFP 1 2 0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" }
let(:args) {{ "plugin" => "sshfp_randomize" }}
let(:args) { { "plugin" => "sshfp_randomize" } }
it "should be defined" do
expect(plugin).to be_a_kind_of(Proc)

Просмотреть файл

@ -1,3 +1,4 @@
# frozen_string_literal: true
require "spec_helper"
describe "delete plugin" do
@ -112,7 +113,7 @@ end
describe "randomize_long_string plugin" do
let(:plugin) { OctofactsUpdater::Plugin.plugins[:randomize_long_string] }
let(:value) { "1234567890abcdef" }
let(:args) {{ "plugin" => "randomize_long_string" }}
let(:args) { { "plugin" => "randomize_long_string" } }
it "should be defined" do
expect(plugin).to be_a_kind_of(Proc)

Просмотреть файл

@ -1,3 +1,4 @@
# frozen_string_literal: true
require "spec_helper"
require "ostruct"

Просмотреть файл

@ -1,3 +1,4 @@
# frozen_string_literal: true
require "spec_helper"
describe OctofactsUpdater::Service::LocalFile do
@ -8,12 +9,12 @@ describe OctofactsUpdater::Service::LocalFile do
context "when localfile is not configured" do
it "should raise ArgumentError when localfile is undefined" do
config = {}
expect{ described_class.facts(node, config) }.to raise_error(ArgumentError, /requires localfile section/)
expect { described_class.facts(node, config) }.to raise_error(ArgumentError, /requires localfile section/)
end
it "should raise ArgumentError when localfile is not a hash" do
config = {"localfile" => :do_it}
expect{ described_class.facts(node, config) }.to raise_error(ArgumentError, /requires localfile section/)
expect { described_class.facts(node, config) }.to raise_error(ArgumentError, /requires localfile section/)
end
end
@ -22,12 +23,12 @@ describe OctofactsUpdater::Service::LocalFile do
it "should raise error if the path is undefined" do
config = { "localfile" => {} }
expect{ described_class.facts(node, config) }.to raise_error(ArgumentError, /requires 'path' in the localfile section/)
expect { described_class.facts(node, config) }.to raise_error(ArgumentError, /requires 'path' in the localfile section/)
end
it "should raise error if the path does not exist" do
config = { "localfile" => { "path" => File.join(file_path, "missing.yaml") } }
expect{ described_class.facts(node, config) }.to raise_error(Errno::ENOENT, /LocalFile cannot find a file at/)
expect { described_class.facts(node, config) }.to raise_error(Errno::ENOENT, /LocalFile cannot find a file at/)
end
it "should return the proper object from the parsed file" do

Просмотреть файл

@ -1,3 +1,4 @@
# frozen_string_literal: true
require "spec_helper"
describe OctofactsUpdater::Service::SSH do
@ -8,19 +9,19 @@ describe OctofactsUpdater::Service::SSH do
context "when ssh is not configured" do
it "should raise ArgumentError when ssh is undefined" do
config = {}
expect{ described_class.facts(node, config) }.to raise_error(ArgumentError, /requires ssh section/)
expect { described_class.facts(node, config) }.to raise_error(ArgumentError, /requires ssh section/)
end
it "should raise ArgumentError when ssh is not a hash" do
config = {"ssh" => :do_it}
expect{ described_class.facts(node, config) }.to raise_error(ArgumentError, /requires ssh section/)
expect { described_class.facts(node, config) }.to raise_error(ArgumentError, /requires ssh section/)
end
end
context "when ssh is configured" do
it "should raise error if no server is configured" do
config = { "ssh" => {} }
expect{ described_class.facts(node, config) }.to raise_error(ArgumentError, /requires 'server' in the ssh section/)
expect { described_class.facts(node, config) }.to raise_error(ArgumentError, /requires 'server' in the ssh section/)
end
context "when user is unspecified" do
@ -38,14 +39,14 @@ describe OctofactsUpdater::Service::SSH do
it "should raise error if no user is configured" do
config = { "ssh" => { "server" => "puppetserver.example.net" } }
expect{ described_class.facts(node, config) }.to raise_error(ArgumentError, /requires 'user' in the ssh section/)
expect { described_class.facts(node, config) }.to raise_error(ArgumentError, /requires 'user' in the ssh section/)
end
it "should use USER from environment if no user is configured" do
ENV["USER"] = "ssh-user-from-env"
config = { "ssh" => { "server" => "puppetserver.example.net" } }
expect(Net::SSH).to receive(:start).with("puppetserver.example.net", "ssh-user-from-env", {}).and_raise(custom_exception)
expect{ described_class.facts(node, config) }.to raise_error(custom_exception)
expect { described_class.facts(node, config) }.to raise_error(custom_exception)
end
end

Просмотреть файл

@ -1,3 +1,4 @@
# frozen_string_literal: true
if ENV["SPEC_NAME"]
require "simplecov"
require "simplecov-json"