knife-ec-backup 3.0.8 → 3.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/chef/knife/ec_base.rb +2 -4
- data/lib/chef/knife/ec_key_base.rb +13 -6
- data/lib/knife_ec_backup/version.rb +1 -1
- data/spec/chef/knife/ec_key_base_spec.rb +51 -0
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 5f2a9570f14dc2fb44eb99732fd69f1f9da32c48ceab68bd6e94511f1e2c464d
|
|
4
|
+
data.tar.gz: de9b0f5cd3bc62c6402bd364151c1237d6e1107b89ce9b80753240091e0b3303
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 5c68fe7a9f2af77f36bff226a63d131cd7dc1a9bb0dd0086b0d65125913310080b4b2acc52f1284438116aae4d14baa248624078d08b3abf37484cebacda3c5f
|
|
7
|
+
data.tar.gz: d2d04dfab678b7d4629e88369208807be1af0f92a930dc6c2bf4d6ead3ba813836f4542ba93322c390f8e120a59c7ab9a9d07d142cb5aa3137af2578864d6e0a
|
data/lib/chef/knife/ec_base.rb
CHANGED
|
@@ -67,13 +67,11 @@ class Chef
|
|
|
67
67
|
|
|
68
68
|
option :sql_host,
|
|
69
69
|
:long => '--sql-host HOSTNAME',
|
|
70
|
-
:description => 'PostgreSQL database hostname (default: localhost)'
|
|
71
|
-
:default => "localhost"
|
|
70
|
+
:description => 'PostgreSQL database hostname (default: value from chef-server-running.json, or localhost)'
|
|
72
71
|
|
|
73
72
|
option :sql_port,
|
|
74
73
|
:long => '--sql-port PORT',
|
|
75
|
-
:description => 'PostgreSQL database port (default: 5432)'
|
|
76
|
-
:default => 5432
|
|
74
|
+
:description => 'PostgreSQL database port (default: value from chef-server-running.json, or 5432)'
|
|
77
75
|
|
|
78
76
|
option :sql_db,
|
|
79
77
|
:long => '--sql-db DBNAME',
|
|
@@ -34,13 +34,11 @@ class Chef
|
|
|
34
34
|
|
|
35
35
|
option :sql_host,
|
|
36
36
|
:long => '--sql-host HOSTNAME',
|
|
37
|
-
:description => 'PostgreSQL database hostname (default: localhost)'
|
|
38
|
-
:default => "localhost"
|
|
37
|
+
:description => 'PostgreSQL database hostname (default: value from chef-server-running.json, or localhost)'
|
|
39
38
|
|
|
40
39
|
option :sql_port,
|
|
41
40
|
:long => '--sql-port PORT',
|
|
42
|
-
:description => 'PostgreSQL database port (default: 5432)'
|
|
43
|
-
:default => 5432
|
|
41
|
+
:description => 'PostgreSQL database port (default: value from chef-server-running.json, or 5432)'
|
|
44
42
|
|
|
45
43
|
option :sql_db,
|
|
46
44
|
:long => '--sql-db DBNAME',
|
|
@@ -88,8 +86,9 @@ class Chef
|
|
|
88
86
|
require 'sequel'
|
|
89
87
|
require 'uri'
|
|
90
88
|
server_uri = URI('postgres://')
|
|
91
|
-
server_uri.host = config[:sql_host]
|
|
92
|
-
server_uri.port = config[:sql_port]
|
|
89
|
+
server_uri.host = config[:sql_host] || 'localhost'
|
|
90
|
+
server_uri.port = config[:sql_port] || 5432
|
|
91
|
+
server_uri.path = "/#{config[:sql_db]}" if config[:sql_db]
|
|
93
92
|
server_uri.user = URI.encode_www_form_component(config[:sql_user]) if config[:sql_user]
|
|
94
93
|
server_uri.password = URI.encode_www_form_component(config[:sql_password]) if config[:sql_password]
|
|
95
94
|
query_params = []
|
|
@@ -123,6 +122,14 @@ class Chef
|
|
|
123
122
|
config[:sql_user] ||= running_config['private_chef'][hash_key]['sql_user']
|
|
124
123
|
config[:sql_password] ||= (running_config['private_chef'][hash_key]['sql_password'] || sql_password)
|
|
125
124
|
config[:sql_db] ||= 'opscode_chef'
|
|
125
|
+
# Source the PostgreSQL host/port from the running config so external
|
|
126
|
+
# PostgreSQL deployments are picked up automatically, the same way the
|
|
127
|
+
# sql_user/sql_password/sql_db are. ||= ensures an explicit --sql-host /
|
|
128
|
+
# --sql-port still wins. Embedded installs report a loopback vip, and the
|
|
129
|
+
# db method falls back to localhost:5432 when these are absent.
|
|
130
|
+
pg_config = running_config['private_chef']['postgresql'] || {}
|
|
131
|
+
config[:sql_host] ||= pg_config['vip']
|
|
132
|
+
config[:sql_port] ||= pg_config['port']
|
|
126
133
|
end
|
|
127
134
|
end
|
|
128
135
|
end
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "spec_helper"))
|
|
2
2
|
require 'chef/knife/ec_key_base'
|
|
3
3
|
require 'chef/automate'
|
|
4
|
+
require 'sequel'
|
|
4
5
|
|
|
5
6
|
class KeyBaseTester < Chef::Knife
|
|
6
7
|
include Chef::Knife::EcKeyBase
|
|
@@ -38,4 +39,54 @@ describe Chef::Knife::EcKeyBase do
|
|
|
38
39
|
expect(knife.config[:sql_password]).to eq("secrete")
|
|
39
40
|
end
|
|
40
41
|
end
|
|
42
|
+
|
|
43
|
+
# Regression coverage for the external-PostgreSQL bug: the SQL host/port must
|
|
44
|
+
# be sourced from chef-server-running.json (like sql_user/sql_password/sql_db),
|
|
45
|
+
# while an explicit --sql-host / --sql-port supplied on the CLI must still win.
|
|
46
|
+
describe "#load_config_from_file! PostgreSQL host/port autoconfiguration" do
|
|
47
|
+
let(:external_pg_running_config) {
|
|
48
|
+
'{"private_chef": { "opscode-erchef": {}, "postgresql": { "vip": "db.external.example.com", "port": 6432, "sql_user": "jiminy", "sql_password": "secret" } } }'
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
before(:each) do
|
|
52
|
+
allow(Chef::Automate).to receive(:is_installed?).and_return(false)
|
|
53
|
+
allow(File).to receive(:exist?).and_call_original
|
|
54
|
+
allow(File).to receive(:exist?).with("/etc/opscode/chef-server-running.json").and_return(true)
|
|
55
|
+
allow(File).to receive(:read).and_call_original
|
|
56
|
+
allow(File).to receive(:read).with("/etc/opscode/chef-server-running.json").and_return(external_pg_running_config)
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
it "adopts the PostgreSQL host and port from chef-server-running.json when no CLI flag is given" do
|
|
60
|
+
knife.load_config_from_file!
|
|
61
|
+
expect(knife.config[:sql_host]).to eq("db.external.example.com")
|
|
62
|
+
expect(knife.config[:sql_port]).to eq(6432)
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
it "lets an explicit --sql-host / --sql-port win over the autoconfigured value" do
|
|
66
|
+
knife.config[:sql_host] = "cli-host.example.com"
|
|
67
|
+
knife.config[:sql_port] = 2345
|
|
68
|
+
knife.load_config_from_file!
|
|
69
|
+
expect(knife.config[:sql_host]).to eq("cli-host.example.com")
|
|
70
|
+
expect(knife.config[:sql_port]).to eq(2345)
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
# Regression coverage for #181: the configured database name must be written
|
|
75
|
+
# into the PostgreSQL connection URI. It was previously resolved but never
|
|
76
|
+
# applied, so PostgreSQL silently fell back to a database named after the user.
|
|
77
|
+
describe "#db connection URI" do
|
|
78
|
+
before(:each) do
|
|
79
|
+
# Capture the connection string instead of opening a real connection.
|
|
80
|
+
allow(Sequel).to receive(:connect) { |uri, *| uri }
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
it "includes the configured database name in the connection URI" do
|
|
84
|
+
knife.config[:sql_db] = "custom_db"
|
|
85
|
+
expect(knife.db).to include("/custom_db")
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
it "falls back to localhost:5432 when host and port are unset" do
|
|
89
|
+
expect(knife.db).to start_with("postgres://localhost:5432")
|
|
90
|
+
end
|
|
91
|
+
end
|
|
41
92
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: knife-ec-backup
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 3.0.
|
|
4
|
+
version: 3.0.9
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- John Keiser
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-
|
|
11
|
+
date: 2026-06-30 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: sequel
|