crowbar-client 2.4.3 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +11 -0
  3. data/lib/crowbar/client/app/repository.rb +12 -10
  4. data/lib/crowbar/client/app/role.rb +2 -2
  5. data/lib/crowbar/client/command/proposal/create.rb +2 -2
  6. data/lib/crowbar/client/command/repository/list.rb +8 -5
  7. data/lib/crowbar/client/command/role/show.rb +2 -2
  8. data/lib/crowbar/client/config.rb +1 -1
  9. data/lib/crowbar/client/mixin/barclamp.rb +1 -1
  10. data/lib/crowbar/client/request.rb +3 -3
  11. data/lib/crowbar/client/request/backup/create.rb +16 -2
  12. data/lib/crowbar/client/request/backup/delete.rb +15 -1
  13. data/lib/crowbar/client/request/backup/download.rb +3 -3
  14. data/lib/crowbar/client/request/backup/list.rb +15 -1
  15. data/lib/crowbar/client/request/backup/restore.rb +15 -1
  16. data/lib/crowbar/client/request/backup/upload.rb +23 -7
  17. data/lib/crowbar/client/request/base.rb +35 -53
  18. data/lib/crowbar/client/request/batch/build.rb +5 -4
  19. data/lib/crowbar/client/request/proposal/create.rb +1 -1
  20. data/lib/crowbar/client/request/repository/activate.rb +1 -0
  21. data/lib/crowbar/client/request/repository/deactivate.rb +1 -0
  22. data/lib/crowbar/client/request/rest.rb +45 -0
  23. data/lib/crowbar/client/util.rb +3 -0
  24. data/lib/crowbar/client/util/apiversion.rb +36 -0
  25. data/lib/crowbar/client/version.rb +3 -3
  26. data/spec/crowbar/client/command/proposal/create_spec.rb +3 -3
  27. data/spec/crowbar/client/command/proposal/edit_spec.rb +3 -3
  28. data/spec/crowbar/client/request/backup/create_spec.rb +6 -4
  29. data/spec/crowbar/client/request/backup/delete_spec.rb +3 -3
  30. data/spec/crowbar/client/request/backup/download_spec.rb +1 -1
  31. data/spec/crowbar/client/request/backup/list_spec.rb +3 -3
  32. data/spec/crowbar/client/request/backup/restore_spec.rb +3 -3
  33. data/spec/crowbar/client/request/backup/upload_spec.rb +13 -4
  34. data/spec/crowbar/client/request/batch/build_spec.rb +7 -1
  35. data/spec/crowbar/client/request/repository/activate_spec.rb +2 -0
  36. data/spec/crowbar/client/request/repository/deactivate_spec.rb +2 -0
  37. data/spec/support/request_examples.rb +12 -14
  38. metadata +118 -104
  39. data/lib/crowbar/client/request/party.rb +0 -82
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b8c037979c770924039812786201ace63f048b39
4
- data.tar.gz: 5f57c075fede83f6e74a926b16f8cd94a7bed7dc
3
+ metadata.gz: 6b731c1c97fffa975e7984c69201175b40747a6c
4
+ data.tar.gz: eb713da64767ffbd8a11a419b00af7a80ca40fb1
5
5
  SHA512:
6
- metadata.gz: 3701cc65c24bdab44af17b2d0f486b71a84ff83e3d6cb99e32ab6fbbc86dad758b1d1dd14fec914b994ac589fbfc7394c37dbdc28bee24bb035745949d44ff01
7
- data.tar.gz: f72e6174212ea6302e41b453112fb758402d3109380b614c0e29795bcc75e70fab4176e3d4c79aa5e8002198441282e0b72b44f19aaf6fd106a52090ed6722c4
6
+ metadata.gz: d85ccb27fa7428c469d3718205ba2e3012e31461dabc16384545c65ad614f24eab9a478b514a674458cf308fdb67dfb141839fe3f57b9ad1aa8ccedf0a8dc00a
7
+ data.tar.gz: 515d9f42654a8f0cb62b42444d91b1da56760bf6c54df92706ee740f03e5fea51fefd346c08d6c900d84b1fa32d4ff48196661b443d3d0fbca3e71d5ceaabdc3
data/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
1
1
  # Changelog
2
2
 
3
+ ## [3.0.0](https://github.com/crowbar/crowbar-client/releases/tag/v3.0.0) - 2016-08-16
4
+
5
+ * BREAKING
6
+ * Adapt backups subcommand to the new api 2.0 (@MaximilianMeister)
7
+ * BUGFIX
8
+ * Fix repository handling (bsc#993445) (@MaximilianMeister)
9
+ * ENHANCEMENT
10
+ * Added lgtm config (@rsalevsky)
11
+ * Clarify command role show (@itxaka)
12
+ * Replace httparty/httmultiparty with rest-client (@MaximilianMeister)
13
+
3
14
  ## [2.4.3](https://github.com/crowbar/crowbar-client/releases/tag/v2.4.3) - 2016-07-06
4
15
 
5
16
  * BUGFIX
@@ -77,18 +77,19 @@ module Crowbar
77
77
  catch_errors(e)
78
78
  end
79
79
 
80
- desc "activate PLATFORM REPO",
81
- "Activate a repository for a platform"
80
+ desc "activate PLATFORM ARCH REPO",
81
+ "Activate a repository for a platform on a specific architecture"
82
82
 
83
83
  long_desc <<-LONGDESC
84
- `activate PLATFORM REPO` will try to activate the
85
- specified repository for the specified platform.
84
+ `activate PLATFORM ARCH REPO` will try to activate the
85
+ specified repository for the specified platform and architecture.
86
86
  LONGDESC
87
87
 
88
- def activate(platform, repo)
88
+ def activate(platform, arch, repo)
89
89
  Command::Repository::Activate.new(
90
90
  *command_params(
91
91
  platform: platform,
92
+ arch: arch,
92
93
  repo: repo
93
94
  )
94
95
  ).execute
@@ -112,18 +113,19 @@ module Crowbar
112
113
  catch_errors(e)
113
114
  end
114
115
 
115
- desc "deactivate PLATFORM REPO",
116
- "Deactivate a repository for a platform"
116
+ desc "deactivate PLATFORM ARCH REPO",
117
+ "Deactivate a repository for a platform on a specific architecture"
117
118
 
118
119
  long_desc <<-LONGDESC
119
- `deactivate PLATFORM REPO` will try to deactivate the
120
- specified repository for the specified platform.
120
+ `deactivate PLATFORM ARCH REPO` will try to deactivate the
121
+ specified repository for the specified platform and architecture.
121
122
  LONGDESC
122
123
 
123
- def deactivate(platform, repo)
124
+ def deactivate(platform, arch, repo)
124
125
  Command::Repository::Deactivate.new(
125
126
  *command_params(
126
127
  platform: platform,
128
+ arch: arch,
127
129
  repo: repo
128
130
  )
129
131
  ).execute
@@ -83,8 +83,8 @@ module Crowbar
83
83
  "Show details of a specific role"
84
84
 
85
85
  long_desc <<-LONGDESC
86
- `show BARCLAMP ROLE` will print out the details for a specified
87
- role for the specified barclamp. You can display the details in
86
+ `show BARCLAMP ROLE` will print out the nodes available to
87
+ assign the role. You can display the details in
88
88
  different output formats and you can filter the details by any
89
89
  search criteria.
90
90
 
@@ -29,8 +29,8 @@ module Crowbar
29
29
 
30
30
  def request
31
31
  @request ||= Request::Proposal::Create.new(
32
- args.easy_merge(
33
- payload: payload_content
32
+ args.easy_merge!(
33
+ payload: payload_content.to_hash
34
34
  )
35
35
  )
36
36
  end
@@ -37,7 +37,7 @@ module Crowbar
37
37
  when 200
38
38
  formatter = Formatter::Hash.new(
39
39
  format: provide_format,
40
- headings: ["Platform", "Repo"],
40
+ headings: ["Platform", "Architecture", "Repository"],
41
41
  values: Filter::Hash.new(
42
42
  filter: provide_filter,
43
43
  values: content_from(request)
@@ -60,10 +60,13 @@ module Crowbar
60
60
  def content_from(request)
61
61
  [].tap do |row|
62
62
  request.parsed_response.each do |child|
63
- row.push(
64
- platform: child["platform"],
65
- repo: child["id"]
66
- )
63
+ child["repos"].each do |repo|
64
+ row.push(
65
+ platform: repo["platform"],
66
+ arch: repo["arch"],
67
+ repo: repo["id"]
68
+ )
69
+ end
67
70
  end
68
71
  end
69
72
  end
@@ -41,7 +41,7 @@ module Crowbar
41
41
  when 200
42
42
  formatter = Formatter::Array.new(
43
43
  format: provide_format,
44
- headings: ["Node"],
44
+ headings: ["Nodes available to assign the role"],
45
45
  values: Filter::Array.new(
46
46
  filter: provide_filter,
47
47
  values: content_from(request)
@@ -49,7 +49,7 @@ module Crowbar
49
49
  )
50
50
 
51
51
  if formatter.empty?
52
- err "No nodes"
52
+ err "No nodes available to assign the role"
53
53
  else
54
54
  say formatter.result
55
55
  end
@@ -163,7 +163,7 @@ module Crowbar
163
163
  if ENV["CROWBAR_DEBUG"].present?
164
164
  [
165
165
  true, 1, "1", "t", "T", "true", "TRUE"
166
- ].include? ENV["CROWBAR_ANONYMOUS"]
166
+ ].include? ENV["CROWBAR_DEBUG"]
167
167
  else
168
168
  false
169
169
  end
@@ -32,7 +32,7 @@ module Crowbar
32
32
  end
33
33
 
34
34
  def available_barclamps
35
- @available_barclamps ||= Request::Barclamp::List.new.process.keys
35
+ @available_barclamps ||= Request::Barclamp::List.new.process.parsed_response.keys
36
36
  end
37
37
  end
38
38
  end
@@ -44,15 +44,15 @@ module Crowbar
44
44
  autoload :Node,
45
45
  File.expand_path("../request/node", __FILE__)
46
46
 
47
- autoload :Party,
48
- File.expand_path("../request/party", __FILE__)
49
-
50
47
  autoload :Proposal,
51
48
  File.expand_path("../request/proposal", __FILE__)
52
49
 
53
50
  autoload :Repository,
54
51
  File.expand_path("../request/repository", __FILE__)
55
52
 
53
+ autoload :Rest,
54
+ File.expand_path("../request/rest", __FILE__)
55
+
56
56
  autoload :Role,
57
57
  File.expand_path("../request/role", __FILE__)
58
58
 
@@ -24,6 +24,17 @@ module Crowbar
24
24
  # Implementation for the backup create request
25
25
  #
26
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
+
27
38
  #
28
39
  # Override the request content
29
40
  #
@@ -31,7 +42,9 @@ module Crowbar
31
42
  #
32
43
  def content
33
44
  super.easy_merge!(
34
- name: attrs.name
45
+ backup: {
46
+ name: attrs.name
47
+ }
35
48
  )
36
49
  end
37
50
 
@@ -51,7 +64,8 @@ module Crowbar
51
64
  #
52
65
  def url
53
66
  [
54
- "utils",
67
+ "api",
68
+ "crowbar",
55
69
  "backups"
56
70
  ].join("/")
57
71
  end
@@ -14,6 +14,8 @@
14
14
  # limitations under the License.
15
15
  #
16
16
 
17
+ require "easy_diff"
18
+
17
19
  module Crowbar
18
20
  module Client
19
21
  module Request
@@ -22,6 +24,17 @@ module Crowbar
22
24
  # Implementation for the backup delete request
23
25
  #
24
26
  class Delete < 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
+
25
38
  #
26
39
  # HTTP method that gets used by the request
27
40
  #
@@ -38,7 +51,8 @@ module Crowbar
38
51
  #
39
52
  def url
40
53
  [
41
- "utils",
54
+ "api",
55
+ "crowbar",
42
56
  "backups",
43
57
  attrs.name
44
58
  ].join("/")
@@ -26,8 +26,7 @@ module Crowbar
26
26
  class Download < Base
27
27
  def headers
28
28
  super.easy_merge!(
29
- "Content-Type" => "application/octet-stream",
30
- "Accept" => "application/octet-stream"
29
+ Crowbar::Client::Util::ApiVersion.new(2.0).headers
31
30
  )
32
31
  end
33
32
 
@@ -47,7 +46,8 @@ module Crowbar
47
46
  #
48
47
  def url
49
48
  [
50
- "utils",
49
+ "api",
50
+ "crowbar",
51
51
  "backups",
52
52
  attrs.name,
53
53
  "download"
@@ -14,6 +14,8 @@
14
14
  # limitations under the License.
15
15
  #
16
16
 
17
+ require "easy_diff"
18
+
17
19
  module Crowbar
18
20
  module Client
19
21
  module Request
@@ -22,6 +24,17 @@ module Crowbar
22
24
  # Implementation for the backup list request
23
25
  #
24
26
  class List < 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
+
25
38
  #
26
39
  # HTTP method that gets used by the request
27
40
  #
@@ -38,7 +51,8 @@ module Crowbar
38
51
  #
39
52
  def url
40
53
  [
41
- "utils",
54
+ "api",
55
+ "crowbar",
42
56
  "backups"
43
57
  ].join("/")
44
58
  end
@@ -14,6 +14,8 @@
14
14
  # limitations under the License.
15
15
  #
16
16
 
17
+ require "easy_diff"
18
+
17
19
  module Crowbar
18
20
  module Client
19
21
  module Request
@@ -22,6 +24,17 @@ module Crowbar
22
24
  # Implementation for the backup restore request
23
25
  #
24
26
  class Restore < 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
+
25
38
  #
26
39
  # HTTP method that gets used by the request
27
40
  #
@@ -38,7 +51,8 @@ module Crowbar
38
51
  #
39
52
  def url
40
53
  [
41
- "utils",
54
+ "api",
55
+ "crowbar",
42
56
  "backups",
43
57
  attrs.name,
44
58
  "restore"
@@ -14,6 +14,8 @@
14
14
  # limitations under the License.
15
15
  #
16
16
 
17
+ require "easy_diff"
18
+
17
19
  module Crowbar
18
20
  module Client
19
21
  module Request
@@ -22,13 +24,26 @@ module Crowbar
22
24
  # Implementation for the backup upload request
23
25
  #
24
26
  class Upload < Base
25
- def params
26
- {
27
- headers: headers,
28
- query: {
29
- file: attrs.file
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
+ def content
39
+ super.easy_merge!(
40
+ backup: {
41
+ payload: {
42
+ multipart: true,
43
+ file: attrs.file
44
+ }
30
45
  }
31
- }
46
+ )
32
47
  end
33
48
 
34
49
  #
@@ -47,7 +62,8 @@ module Crowbar
47
62
  #
48
63
  def url
49
64
  [
50
- "utils",
65
+ "api",
66
+ "crowbar",
51
67
  "backups",
52
68
  "upload"
53
69
  ].join("/")
@@ -31,7 +31,7 @@ module Crowbar
31
31
  end
32
32
 
33
33
  def request
34
- @request ||= Party.new
34
+ @request ||= Rest.new(url: url)
35
35
  end
36
36
 
37
37
  def content
@@ -46,25 +46,43 @@ module Crowbar
46
46
  end
47
47
 
48
48
  def params
49
- {
50
- body: content.to_json,
51
- headers: headers
52
- }
49
+ case method
50
+ when :post
51
+ [
52
+ method,
53
+ content
54
+ ]
55
+ when :put
56
+ [
57
+ method,
58
+ content.to_json
59
+ ]
60
+ else
61
+ [
62
+ method
63
+ ]
64
+ end
53
65
  end
54
66
 
55
67
  def process
56
- result = request.send(
57
- method,
58
- [
59
- "/",
60
- url
61
- ].join(""),
62
- params
63
- )
64
-
65
- send(
66
- errors[result.code]
67
- ) if errors[result.code]
68
+ result = begin
69
+ request.send(
70
+ *params,
71
+ accept: headers["Accept"],
72
+ content_type: headers["Content-Type"]
73
+ )
74
+ rescue => e
75
+ if e.class.superclass == RestClient::RequestFailed
76
+ Hashie::Mash.new(
77
+ parsed_response: {
78
+ error: e.message
79
+ },
80
+ code: e.http_code
81
+ )
82
+ else
83
+ raise e
84
+ end
85
+ end
68
86
 
69
87
  if block_given?
70
88
  yield result
@@ -72,42 +90,6 @@ module Crowbar
72
90
  result
73
91
  end
74
92
  end
75
-
76
- def errors
77
- {
78
- 401 => :not_authorized,
79
- 403 => :not_authorized,
80
- 500 => :internal_server,
81
- 502 => :bad_gateway,
82
- 503 => :service_unavailable,
83
- 504 => :gateway_timeout
84
- }
85
- end
86
-
87
- def not_authorized
88
- raise NotAuthorizedError,
89
- "User is not authorized"
90
- end
91
-
92
- def internal_server
93
- raise InternalServerError,
94
- "An internal error occured"
95
- end
96
-
97
- def bad_gateway
98
- raise BadGatewayError,
99
- "Received a bad gateway error"
100
- end
101
-
102
- def service_unavailable
103
- raise ServiceUnavailableError,
104
- "Service is not available"
105
- end
106
-
107
- def gateway_timeout
108
- raise GatewayTimeoutError,
109
- "Received a gateway timeout"
110
- end
111
93
  end
112
94
  end
113
95
  end