crowbar-client 3.1.3 → 3.1.4
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 +5 -13
- data/CHANGELOG.md +7 -0
- data/lib/crowbar/client/app.rb +3 -0
- data/lib/crowbar/client/app/database.rb +220 -0
- data/lib/crowbar/client/app/entry.rb +4 -0
- data/lib/crowbar/client/app/upgrade.rb +4 -4
- data/lib/crowbar/client/command.rb +3 -0
- data/lib/crowbar/client/command/database.rb +35 -0
- data/lib/crowbar/client/command/database/connect.rb +59 -0
- data/lib/crowbar/client/command/database/create.rb +56 -0
- data/lib/crowbar/client/command/database/test.rb +59 -0
- data/lib/crowbar/client/command/upgrade/prechecks.rb +28 -4
- data/lib/crowbar/client/mixin/database.rb +1 -1
- data/lib/crowbar/client/request.rb +3 -0
- data/lib/crowbar/client/request/database.rb +35 -0
- data/lib/crowbar/client/request/database/connect.rb +78 -0
- data/lib/crowbar/client/request/database/create.rb +75 -0
- data/lib/crowbar/client/request/database/test.rb +78 -0
- data/lib/crowbar/client/request/upgrade/backup.rb +2 -2
- data/lib/crowbar/client/version.rb +1 -1
- data/spec/crowbar/client/command/database/connect_spec.rb +31 -0
- data/spec/crowbar/client/command/database/create_spec.rb +31 -0
- data/spec/crowbar/client/command/database/test_spec.rb +31 -0
- data/spec/crowbar/client/request/database/connect_spec.rb +62 -0
- data/spec/crowbar/client/request/database/create_spec.rb +56 -0
- data/spec/crowbar/client/request/database/test_spec.rb +62 -0
- data/spec/spec_helper.rb +0 -1
- metadata +55 -35
@@ -0,0 +1,59 @@
|
|
1
|
+
#
|
2
|
+
# Copyright 2016, SUSE Linux GmbH
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
#
|
16
|
+
|
17
|
+
require "easy_diff"
|
18
|
+
|
19
|
+
module Crowbar
|
20
|
+
module Client
|
21
|
+
module Command
|
22
|
+
module Database
|
23
|
+
#
|
24
|
+
# Implementation for the database test command
|
25
|
+
#
|
26
|
+
class Test < Base
|
27
|
+
include Mixin::Database
|
28
|
+
|
29
|
+
def args_with_options
|
30
|
+
args.easy_merge!(
|
31
|
+
username: options.db_username,
|
32
|
+
password: options.db_password,
|
33
|
+
database: options.database,
|
34
|
+
host: options.host,
|
35
|
+
port: options.port
|
36
|
+
)
|
37
|
+
end
|
38
|
+
|
39
|
+
def request
|
40
|
+
@request ||= Request::Database::Test.new(
|
41
|
+
args_with_options
|
42
|
+
)
|
43
|
+
end
|
44
|
+
|
45
|
+
def execute
|
46
|
+
request.process do |request|
|
47
|
+
case request.code
|
48
|
+
when 200
|
49
|
+
say "Successfully tested connection to database"
|
50
|
+
else
|
51
|
+
err request.parsed_response["error"]
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -35,12 +35,12 @@ module Crowbar
|
|
35
35
|
request.process do |request|
|
36
36
|
case request.code
|
37
37
|
when 200
|
38
|
-
formatter = Formatter::
|
38
|
+
formatter = Formatter::Hash.new(
|
39
39
|
format: provide_format,
|
40
|
-
headings: ["Check", "
|
41
|
-
values: Filter::
|
40
|
+
headings: ["Check ID", "Passed", "Required", "Errors", "Help"],
|
41
|
+
values: Filter::Hash.new(
|
42
42
|
filter: provide_filter,
|
43
|
-
values: request
|
43
|
+
values: content_from(request)
|
44
44
|
).result
|
45
45
|
)
|
46
46
|
|
@@ -54,6 +54,30 @@ module Crowbar
|
|
54
54
|
end
|
55
55
|
end
|
56
56
|
end
|
57
|
+
|
58
|
+
protected
|
59
|
+
|
60
|
+
def content_from(request)
|
61
|
+
[].tap do |row|
|
62
|
+
request.parsed_response["checks"].each do |check_id, values|
|
63
|
+
row.push(
|
64
|
+
check_id: check_id,
|
65
|
+
passed: values["passed"],
|
66
|
+
required: values["required"],
|
67
|
+
errors: if values["errors"].key?(check_id)
|
68
|
+
values["errors"][check_id]["data"].inspect
|
69
|
+
else
|
70
|
+
nil
|
71
|
+
end,
|
72
|
+
help: if values["errors"].key?(check_id)
|
73
|
+
values["errors"][check_id]["help"].inspect
|
74
|
+
else
|
75
|
+
nil
|
76
|
+
end
|
77
|
+
)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
57
81
|
end
|
58
82
|
end
|
59
83
|
end
|
@@ -29,7 +29,7 @@ module Crowbar
|
|
29
29
|
REGEX_IPV4 = "^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$".freeze
|
30
30
|
REGEX_USERNAME = "(?=^.{4,63}$)(?=^[a-zA-Z0-9_]*$)".freeze
|
31
31
|
REGEX_PASSWORD = "(?=^.{4,63}$)(?=^[a-zA-Z0-9_]*$)(?=[a-zA-Z0-9_$&+,:;=?@#|'<>.^*()%!-]*$)".freeze
|
32
|
-
REGEX_DATABASE = "(?=^.{
|
32
|
+
REGEX_DATABASE = "(?=^.{4,253}$)(?=^[a-zA-Z0-9_]*$)(?=[a-zA-Z0-9_$&+,:;=?@#|'<>.^*()%!-]*$)".freeze
|
33
33
|
REGEX_PORT = "(?=^.{1,5}$)(?=^[0-9]*$)(?=^([1-9][0-9]{0,3}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5])$)".freeze
|
34
34
|
|
35
35
|
included do
|
@@ -0,0 +1,35 @@
|
|
1
|
+
#
|
2
|
+
# Copyright 2016, SUSE Linux GmbH
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
#
|
16
|
+
|
17
|
+
module Crowbar
|
18
|
+
module Client
|
19
|
+
module Request
|
20
|
+
#
|
21
|
+
# Module for the database request implementations
|
22
|
+
#
|
23
|
+
module Database
|
24
|
+
autoload :Connect,
|
25
|
+
File.expand_path("../database/connect", __FILE__)
|
26
|
+
|
27
|
+
autoload :Create,
|
28
|
+
File.expand_path("../database/create", __FILE__)
|
29
|
+
|
30
|
+
autoload :Test,
|
31
|
+
File.expand_path("../database/test", __FILE__)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
#
|
2
|
+
# Copyright 2016, SUSE Linux GmbH
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
#
|
16
|
+
|
17
|
+
require "easy_diff"
|
18
|
+
|
19
|
+
module Crowbar
|
20
|
+
module Client
|
21
|
+
module Request
|
22
|
+
module Database
|
23
|
+
#
|
24
|
+
# Implementation for the database connect request
|
25
|
+
#
|
26
|
+
class Connect < Base
|
27
|
+
#
|
28
|
+
# Override the request headers
|
29
|
+
#
|
30
|
+
# @return [Hash] the headers for the request
|
31
|
+
#
|
32
|
+
def headers
|
33
|
+
super.easy_merge!(
|
34
|
+
::Crowbar::Client::Util::ApiVersion.new(2.0).headers
|
35
|
+
)
|
36
|
+
end
|
37
|
+
|
38
|
+
#
|
39
|
+
# Override the request content
|
40
|
+
#
|
41
|
+
# @return [Hash] the content for the request
|
42
|
+
#
|
43
|
+
def content
|
44
|
+
super.easy_merge!(
|
45
|
+
username: attrs.db_username,
|
46
|
+
password: attrs.db_password,
|
47
|
+
database: attrs.database,
|
48
|
+
host: attrs.host,
|
49
|
+
port: attrs.port
|
50
|
+
)
|
51
|
+
end
|
52
|
+
|
53
|
+
#
|
54
|
+
# HTTP method that gets used by the request
|
55
|
+
#
|
56
|
+
# @return [Symbol] the method for the request
|
57
|
+
#
|
58
|
+
def method
|
59
|
+
:post
|
60
|
+
end
|
61
|
+
|
62
|
+
#
|
63
|
+
# Path to the API endpoint for the request
|
64
|
+
#
|
65
|
+
# @return [String] path to the API endpoint
|
66
|
+
#
|
67
|
+
def url
|
68
|
+
[
|
69
|
+
"api",
|
70
|
+
"database",
|
71
|
+
"connect"
|
72
|
+
].join("/")
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
#
|
2
|
+
# Copyright 2016, SUSE Linux GmbH
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
#
|
16
|
+
|
17
|
+
require "easy_diff"
|
18
|
+
|
19
|
+
module Crowbar
|
20
|
+
module Client
|
21
|
+
module Request
|
22
|
+
module Database
|
23
|
+
#
|
24
|
+
# Implementation for the database create request
|
25
|
+
#
|
26
|
+
class Create < Base
|
27
|
+
#
|
28
|
+
# Override the request headers
|
29
|
+
#
|
30
|
+
# @return [Hash] the headers for the request
|
31
|
+
#
|
32
|
+
def headers
|
33
|
+
super.easy_merge!(
|
34
|
+
::Crowbar::Client::Util::ApiVersion.new(2.0).headers
|
35
|
+
)
|
36
|
+
end
|
37
|
+
|
38
|
+
#
|
39
|
+
# Override the request content
|
40
|
+
#
|
41
|
+
# @return [Hash] the content for the request
|
42
|
+
#
|
43
|
+
def content
|
44
|
+
super.easy_merge!(
|
45
|
+
username: attrs.db_username,
|
46
|
+
password: attrs.db_password
|
47
|
+
)
|
48
|
+
end
|
49
|
+
|
50
|
+
#
|
51
|
+
# HTTP method that gets used by the request
|
52
|
+
#
|
53
|
+
# @return [Symbol] the method for the request
|
54
|
+
#
|
55
|
+
def method
|
56
|
+
:post
|
57
|
+
end
|
58
|
+
|
59
|
+
#
|
60
|
+
# Path to the API endpoint for the request
|
61
|
+
#
|
62
|
+
# @return [String] path to the API endpoint
|
63
|
+
#
|
64
|
+
def url
|
65
|
+
[
|
66
|
+
"api",
|
67
|
+
"database",
|
68
|
+
"new"
|
69
|
+
].join("/")
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
#
|
2
|
+
# Copyright 2016, SUSE Linux GmbH
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
#
|
16
|
+
|
17
|
+
require "easy_diff"
|
18
|
+
|
19
|
+
module Crowbar
|
20
|
+
module Client
|
21
|
+
module Request
|
22
|
+
module Database
|
23
|
+
#
|
24
|
+
# Implementation for the database test request
|
25
|
+
#
|
26
|
+
class Test < Base
|
27
|
+
#
|
28
|
+
# Override the request headers
|
29
|
+
#
|
30
|
+
# @return [Hash] the headers for the request
|
31
|
+
#
|
32
|
+
def headers
|
33
|
+
super.easy_merge!(
|
34
|
+
::Crowbar::Client::Util::ApiVersion.new(2.0).headers
|
35
|
+
)
|
36
|
+
end
|
37
|
+
|
38
|
+
#
|
39
|
+
# Override the request content
|
40
|
+
#
|
41
|
+
# @return [Hash] the content for the request
|
42
|
+
#
|
43
|
+
def content
|
44
|
+
super.easy_merge!(
|
45
|
+
username: attrs.db_username,
|
46
|
+
password: attrs.db_password,
|
47
|
+
database: attrs.database,
|
48
|
+
host: attrs.host,
|
49
|
+
port: attrs.port
|
50
|
+
)
|
51
|
+
end
|
52
|
+
|
53
|
+
#
|
54
|
+
# HTTP method that gets used by the request
|
55
|
+
#
|
56
|
+
# @return [Symbol] the method for the request
|
57
|
+
#
|
58
|
+
def method
|
59
|
+
:post
|
60
|
+
end
|
61
|
+
|
62
|
+
#
|
63
|
+
# Path to the API endpoint for the request
|
64
|
+
#
|
65
|
+
# @return [String] path to the API endpoint
|
66
|
+
#
|
67
|
+
def url
|
68
|
+
[
|
69
|
+
"api",
|
70
|
+
"database",
|
71
|
+
"test"
|
72
|
+
].join("/")
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
#
|
2
|
+
# Copyright 2016, SUSE Linux GmbH
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
#
|
16
|
+
|
17
|
+
require_relative "../../../../spec_helper"
|
18
|
+
|
19
|
+
describe "Crowbar::Client::Command::Database::Connect" do
|
20
|
+
include_context "command_context"
|
21
|
+
|
22
|
+
it_behaves_like "a command class", true do
|
23
|
+
subject do
|
24
|
+
::Crowbar::Client::Command::Database::Connect.new(
|
25
|
+
stdin,
|
26
|
+
stdout,
|
27
|
+
stderr
|
28
|
+
)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|