vagrant_cloud 2.0.1 → 2.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b3fe589f6de0c2adb068af34c80e7e78740fc3ab
4
- data.tar.gz: 6894acccfd45d46a3adcfbeb2ff38fca58e24d2b
3
+ metadata.gz: dce5d7ff120d58a2f5737a09ae6c541638aaa441
4
+ data.tar.gz: 4ec95bf75f996ca9dd11f6c53583af591511034f
5
5
  SHA512:
6
- metadata.gz: 86f7284a726434fcdde1d7dc860912a0c8cfdb8d6fb73181672ce07ec98e2a40028547c36f59fbaa3945c79139c302e610bd27d0a2df68619c1652ca888a0206
7
- data.tar.gz: 1d6615c95f7b4c1864bb220e18c42c71d675468e635975765ec2038ace6abf136dc2983f5b02a4569b2a8d36c7fa2320458fc96df22c0c839e6d646b59f7e3f0
6
+ metadata.gz: 8acc641a56768c54337fff4ff83b27dbf6f613f18238f8dad7a07d27733cb0c86beadc491bd5ad6af17ecf6acd87d268eaa7fe6483b1265ea6e138f98c61ee73
7
+ data.tar.gz: 2e913f1a82a52921483da97c9bf8d63314f5033e997e1923ea9a820bfa0b00f46fee135c509539bf07846a4b133dbbeda8b60b1e44bf168b5038e9f916da5dd8
@@ -1,5 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require 'vagrant_cloud'
4
-
5
- VagrantCloud::Cli.start(ARGV)
3
+ raise 'As of the 2.0.0 release, the vagrant_cloud gem provides library' \
4
+ ' functionality and no longer includes a command line client. For a' \
5
+ ' command line client, use the `vagrant cloud` subcommand from Vagrant.' \
6
+ ' Vagrant can be downloaded from: https://www.vagrantup.com/downloads.html'
@@ -104,10 +104,15 @@ module VagrantCloud
104
104
  def ensure_box(name, *args)
105
105
  params = box_params(*args)
106
106
 
107
+ # try to read the box data
107
108
  begin
108
109
  box = get_box(name)
109
110
  box.data
110
- rescue RestClient::ResourceNotFound
111
+ rescue VagrantCloud::ClientError => err
112
+ # Check if it's a 404 error. If so, then create
113
+ # the missing box
114
+ raise if err.error_code != 404
115
+
111
116
  box = create_box(name, params)
112
117
  # If we've just created the box, we're done.
113
118
  return box
@@ -33,10 +33,15 @@ module VagrantCloud
33
33
  # @param [Hash] args
34
34
  # @param [String] org - organization of the box to read
35
35
  # @param [String] box_name - name of the box to read
36
- # @return [Hash]
36
+ # @return [Hash] @data
37
37
  def update(args = {})
38
38
  # hash arguments kept for backwards compatibility
39
- data = @client.request('put', box_path(args[:organization], args[:name]), box: args)
39
+ return @data if args.empty?
40
+
41
+ org = args[:organization] || account.username
42
+ box_name = args[:name] || @name
43
+
44
+ data = @client.request('put', box_path(org, box_name), box: args)
40
45
 
41
46
  # Update was called on *this* object, so update
42
47
  # objects data locally
@@ -4,21 +4,31 @@ module VagrantCloud
4
4
  attr_accessor :error_code
5
5
 
6
6
  def initialize(msg, http_body, http_code)
7
+ message = msg
8
+
7
9
  begin
8
10
  errors = JSON.parse(http_body)
9
- vagrant_cloud_msg = errors['errors']
10
-
11
- if vagrant_cloud_msg.is_a?(Array)
12
- message = msg + ' - ' + vagrant_cloud_msg.join(', ').to_s
13
- else
14
- message = msg + ' - ' + vagrant_cloud_msg
11
+ if errors.is_a?(Hash)
12
+ vagrant_cloud_msg = errors['errors']
13
+ if vagrant_cloud_msg.is_a?(Array)
14
+ message = msg + ' - ' + vagrant_cloud_msg.map(&:to_s).join(', ').to_s
15
+ elsif !vagrant_cloud_msg.to_s.empty?
16
+ message = msg + ' - ' + vagrant_cloud_msg.to_s
17
+ end
15
18
  end
16
- rescue JSON::ParserError
17
- message = msg
19
+ rescue JSON::ParserError => err
20
+ vagrant_cloud_msg = err.message
18
21
  end
19
22
 
20
23
  @error_arr = vagrant_cloud_msg
21
- @error_code = http_code
24
+ @error_code = http_code.to_i
25
+ super(message)
26
+ end
27
+ end
28
+
29
+ class InvalidVersion < StandardError
30
+ def initialize(version_number)
31
+ message = 'Invalid version given: ' + version_number
22
32
  super(message)
23
33
  end
24
34
  end
@@ -67,6 +67,13 @@ module VagrantCloud
67
67
  # @param [String] version_number
68
68
  # @param [String] description
69
69
  def update(description = nil, username = nil, box_name = nil, version_number = nil)
70
+ # Ensure version given is a 'proper' version
71
+ begin
72
+ Gem::Version.new(version_number) if version_number
73
+ rescue ArgumentError
74
+ raise VagrantCloud::InvalidVersion, version_number
75
+ end
76
+
70
77
  update_data = !(username && box_name && version_number)
71
78
  description ||= @description
72
79
  version = { description: description }
@@ -116,6 +123,13 @@ module VagrantCloud
116
123
  number ||= @number
117
124
  description ||= @description
118
125
 
126
+ # Ensure version given is a 'proper' version
127
+ begin
128
+ Gem::Version.new(number) if number
129
+ rescue ArgumentError
130
+ raise VagrantCloud::InvalidVersion, number
131
+ end
132
+
119
133
  params = { version: number, description: description }
120
134
  data = @client.request('post', create_version_path(org, box_name).to_s, version: params)
121
135
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vagrant_cloud
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 2.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - HashiCorp
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2018-10-17 00:00:00.000000000 Z
12
+ date: 2019-01-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rest-client