vagrant_cloud 2.0.3 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,202 +1,3 @@
1
1
  module VagrantCloud
2
- class Version
3
- attr_accessor :box
4
- attr_accessor :number
5
-
6
- # @param [Box] box
7
- # @param [String] number
8
- # @param [Hash] data
9
- # @param [String] description
10
- # @param [String] access_token
11
- def initialize(box, number, data = nil, description = nil, access_token = nil, custom_server = nil)
12
- @box = box
13
- @number = number
14
- @data = data
15
- @description = description
16
- @client = Client.new(access_token, custom_server)
17
- end
18
-
19
- #--------------------
20
- # Metadata Helpers
21
- #--------------------
22
-
23
- # @return [String]
24
- def version
25
- data['version'].to_s
26
- end
27
-
28
- # @return [String]
29
- def description
30
- data['description_markdown'].to_s
31
- end
32
-
33
- # @return [String]
34
- def status
35
- data['status'].to_s
36
- end
37
-
38
- # @return [Array<Provider>]
39
- def providers
40
- data['providers'].map { |data| Provider.new(self, data['name'], data, nil, nil, nil, @client.access_token, @client.url_base) }
41
- end
42
-
43
- # @return [String]
44
- def to_s
45
- version
46
- end
47
-
48
- #--------------------
49
- # Version API Helpers
50
- #--------------------
51
-
52
- # @return [Hash]
53
- def data
54
- @data ||= @client.request('get', version_path)
55
- end
56
-
57
- # @param [String] username
58
- # @param [String] box_name
59
- # @param [String] version_number
60
- # @return [Hash]
61
- def read(username = nil, box_name = nil, version_number = nil)
62
- @client.request('get', version_path(username, box_name, version_number))
63
- end
64
-
65
- # @param [String] username
66
- # @param [String] box_name
67
- # @param [String] version_number
68
- # @param [String] description
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
-
77
- update_data = !(username && box_name && version_number)
78
- description ||= @description
79
- version = { description: description }
80
- data = @client.request('put',
81
- version_path(username, box_name, version_number),
82
- version: version)
83
-
84
- @data = data if update_data
85
- data
86
- end
87
-
88
- # @param [String] username
89
- # @param [String] box_name
90
- # @param [String] version_number
91
- def delete(username = nil, box_name = nil, version_number = nil)
92
- @client.request('delete', version_path(username, box_name, version_number))
93
- end
94
-
95
- # @param [String] username
96
- # @param [String] box_name
97
- # @param [String] version_number
98
- def release(username = nil, box_name = nil, version_number = nil)
99
- data = @client.request('put', "#{version_path(username, box_name, version_number)}/release")
100
-
101
- @data = data if !(username && box_name && version_number)
102
- data
103
- end
104
-
105
- # @param [String] username
106
- # @param [String] box_name
107
- # @param [String] version_number
108
- def revoke(username = nil, box_name = nil, version_number = nil)
109
- update_data = !(username && box_name && version_number)
110
- data = @client.request('put', "#{version_path(username, box_name, version_number)}/revoke")
111
-
112
- @data = data if update_data
113
- data
114
- end
115
-
116
- # @param [String] number
117
- # @param [String] description
118
- # @param [String] org
119
- # @param [String] box_name
120
- # @return [Hash]
121
- def create_version(number = nil, description = nil, org = nil, box_name = nil)
122
- update_data = !(org && box_name && description && number)
123
- number ||= @number
124
- description ||= @description
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
-
133
- params = { version: number, description: description }
134
- data = @client.request('post', create_version_path(org, box_name).to_s, version: params)
135
-
136
- @data = data if update_data
137
- data
138
- end
139
-
140
- #--------------------
141
- # Old Provider Helpers
142
- #--------------------
143
-
144
- # @param [String] name
145
- # @param [Hash] data
146
- # @return [Provider]
147
- def get_provider(name, data = nil)
148
- Provider.new(self, name, data, nil, nil, nil, @client.access_token, @client.url_base)
149
- end
150
-
151
- # @param [String] name
152
- # @param [String] url
153
- # @return [Provider]
154
- def create_provider(name, url = nil)
155
- params = { name: name, url: url }.delete_if { |_, v| v.nil? }
156
- data = @client.request('post', "#{version_path}/providers", provider: params)
157
- get_provider(name, data)
158
- end
159
-
160
- # @param [String] name
161
- # @param [String] url
162
- # @return [Provider]
163
- def ensure_provider(name, url)
164
- provider = providers.select { |p| p.name == name }.first
165
- provider ||= create_provider(name, url)
166
- provider.update(url) if url != provider.url
167
- provider
168
- end
169
-
170
- private
171
-
172
- # @return [Account]
173
- def account
174
- box.account
175
- end
176
-
177
- # Path used to generate a new version on a box
178
- #
179
- # @param [String] - username
180
- # @param [String] - box_name
181
- # @return [String]
182
- def create_version_path(username = nil, box_name = nil)
183
- if username && box_name
184
- "/box/#{username}/#{box_name}/versions"
185
- else
186
- "/box/#{account.username}/#{box.name}/versions"
187
- end
188
- end
189
-
190
- # @param [String] - username
191
- # @param [String] - box_name
192
- # @param [String] - version_number
193
- # @return [String]
194
- def version_path(username = nil, box_name = nil, version_number = nil)
195
- if username && box_name && version_number
196
- "/box/#{username}/#{box_name}/version/#{version_number}"
197
- else
198
- "/box/#{account.username}/#{box.name}/version/#{number}"
199
- end
200
- end
201
- end
2
+ VERSION = Gem::Version.new(File.read(File.expand_path("../../../version.txt", __FILE__)))
202
3
  end
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.3
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - HashiCorp
@@ -9,64 +9,64 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2019-10-08 00:00:00.000000000 Z
12
+ date: 2020-09-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name: rest-client
15
+ name: excon
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
18
  - - "~>"
19
19
  - !ruby/object:Gem::Version
20
- version: 2.0.2
20
+ version: '0.73'
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
25
  - - "~>"
26
26
  - !ruby/object:Gem::Version
27
- version: 2.0.2
27
+ version: '0.73'
28
28
  - !ruby/object:Gem::Dependency
29
- name: rake
29
+ name: log4r
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
32
  - - "~>"
33
33
  - !ruby/object:Gem::Version
34
- version: '10.4'
35
- type: :development
34
+ version: 1.1.10
35
+ type: :runtime
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
39
  - - "~>"
40
40
  - !ruby/object:Gem::Version
41
- version: '10.4'
41
+ version: 1.1.10
42
42
  - !ruby/object:Gem::Dependency
43
- name: rspec
43
+ name: rake
44
44
  requirement: !ruby/object:Gem::Requirement
45
45
  requirements:
46
46
  - - "~>"
47
47
  - !ruby/object:Gem::Version
48
- version: '3.0'
48
+ version: '12.3'
49
49
  type: :development
50
50
  prerelease: false
51
51
  version_requirements: !ruby/object:Gem::Requirement
52
52
  requirements:
53
53
  - - "~>"
54
54
  - !ruby/object:Gem::Version
55
- version: '3.0'
55
+ version: '12.3'
56
56
  - !ruby/object:Gem::Dependency
57
- name: rubocop
57
+ name: rspec
58
58
  requirement: !ruby/object:Gem::Requirement
59
59
  requirements:
60
60
  - - "~>"
61
61
  - !ruby/object:Gem::Version
62
- version: 0.59.1
62
+ version: '3.0'
63
63
  type: :development
64
64
  prerelease: false
65
65
  version_requirements: !ruby/object:Gem::Requirement
66
66
  requirements:
67
67
  - - "~>"
68
68
  - !ruby/object:Gem::Version
69
- version: 0.59.1
69
+ version: '3.0'
70
70
  - !ruby/object:Gem::Dependency
71
71
  name: webmock
72
72
  requirement: !ruby/object:Gem::Requirement
@@ -89,24 +89,31 @@ extra_rdoc_files: []
89
89
  files:
90
90
  - LICENSE
91
91
  - README.md
92
- - bin/vagrant_cloud
93
92
  - lib/vagrant_cloud.rb
94
93
  - lib/vagrant_cloud/account.rb
95
94
  - lib/vagrant_cloud/box.rb
95
+ - lib/vagrant_cloud/box/provider.rb
96
+ - lib/vagrant_cloud/box/version.rb
96
97
  - lib/vagrant_cloud/client.rb
97
- - lib/vagrant_cloud/errors.rb
98
- - lib/vagrant_cloud/provider.rb
98
+ - lib/vagrant_cloud/data.rb
99
+ - lib/vagrant_cloud/error.rb
100
+ - lib/vagrant_cloud/instrumentor.rb
101
+ - lib/vagrant_cloud/instrumentor/collection.rb
102
+ - lib/vagrant_cloud/instrumentor/core.rb
103
+ - lib/vagrant_cloud/instrumentor/logger.rb
104
+ - lib/vagrant_cloud/logger.rb
105
+ - lib/vagrant_cloud/organization.rb
106
+ - lib/vagrant_cloud/response.rb
107
+ - lib/vagrant_cloud/response/create_token.rb
108
+ - lib/vagrant_cloud/response/request_2fa.rb
109
+ - lib/vagrant_cloud/response/search.rb
99
110
  - lib/vagrant_cloud/search.rb
100
111
  - lib/vagrant_cloud/version.rb
101
112
  homepage: https://github.com/hashicorp/vagrant_cloud
102
113
  licenses:
103
114
  - MIT
104
115
  metadata: {}
105
- post_install_message: |-
106
- NOTICE: As of the 2.0.0 release, the vagrant_cloud gem provides library functionality
107
- and no longer includes a command line client. For a command line client,
108
- use the `vagrant cloud` subcommand from Vagrant. Vagrant can be downloaded
109
- from: https://www.vagrantup.com/downloads.html
116
+ post_install_message:
110
117
  rdoc_options: []
111
118
  require_paths:
112
119
  - lib
@@ -121,8 +128,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
121
128
  - !ruby/object:Gem::Version
122
129
  version: '0'
123
130
  requirements: []
124
- rubyforge_project:
125
- rubygems_version: 2.7.8
131
+ rubygems_version: 3.0.3
126
132
  signing_key:
127
133
  specification_version: 4
128
134
  summary: Vagrant Cloud API Library
@@ -1,6 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
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'
@@ -1,35 +0,0 @@
1
- module VagrantCloud
2
- class ClientError < StandardError
3
- attr_accessor :error_arr
4
- attr_accessor :error_code
5
-
6
- def initialize(msg, http_body, http_code)
7
- message = msg
8
-
9
- begin
10
- errors = JSON.parse(http_body)
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
18
- end
19
- rescue JSON::ParserError => err
20
- vagrant_cloud_msg = err.message
21
- end
22
-
23
- @error_arr = vagrant_cloud_msg
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
32
- super(message)
33
- end
34
- end
35
- end
@@ -1,155 +0,0 @@
1
- module VagrantCloud
2
- class Provider
3
- attr_accessor :version
4
- attr_accessor :name
5
-
6
- # @param [Version] version
7
- # @param [String] name
8
- # @param [Hash] data
9
- # @param [String] access_token
10
- def initialize(version, name, data = nil, url = nil, username = nil, box_name = nil, access_token = nil, custom_server = nil, checksum = nil, checksum_type = nil) # rubocop:disable LineLength
11
- @version = version
12
- @name = name
13
- @data = data
14
- @username = username
15
- @box_name = box_name
16
- @url = url
17
- @checksum = checksum
18
- @checksum_type = checksum_type
19
- @client = Client.new(access_token, custom_server)
20
- end
21
-
22
- #--------------------
23
- # Metadata Helpers
24
- #--------------------
25
-
26
- # @return [String]
27
- def url
28
- data['original_url'].to_s
29
- end
30
-
31
- # @return [String]
32
- def download_url
33
- data['download_url'].to_s
34
- end
35
-
36
- #--------------------
37
- # Provider API Helpers
38
- #--------------------
39
-
40
- # @return [Hash]
41
- def data
42
- @data ||= @client.request('get', provider_path)
43
- end
44
-
45
- # Creates a provider for *this* Provider object, or if all params are given,
46
- # will make a one-off request to create a Provider and return its data
47
- #
48
- # @param [String] name
49
- # @param [String] url
50
- # @param [String] username
51
- # @param [String] box_name
52
- # @param [String] version_number
53
- def create_provider(name = nil, url = nil, username = nil, box_name = nil, version_number = nil)
54
- update_data = !(username && version_number && box_name)
55
- name ||= @name
56
- url ||= @url
57
- username ||= @username
58
- box_name ||= @box_name
59
- version_number ||= @version
60
- checksum = @checksum
61
- checksum_type = @checksum_type
62
-
63
- params = { name: name, url: url, checksum: checksum, checksum_type: checksum_type }.compact
64
- data = @client.request('post', create_provider_path(username, box_name, version_number), provider: params)
65
-
66
- @data = data if update_data
67
- data
68
- end
69
-
70
- # @param [String] url
71
- # @param [String] username
72
- # @param [String] box_name
73
- # @param [String] version_number
74
- # @param [String] provider_name
75
- def update(url = nil, username = nil, box_name = nil, version_number = nil, provider_name = nil)
76
- update_data = !(username && version_number && provider_name && box_name)
77
- provider_name ||= @name
78
- url ||= @url
79
- username ||= @username
80
- box_name ||= @box_name
81
- version_number ||= @version
82
- checksum = @checksum
83
- checksum_type = @checksum_type
84
-
85
- params = { url: url, checksum: checksum, checksum_type: checksum_type }.compact
86
- data = @client.request('put',
87
- provider_path(username, box_name, version_number, provider_name),
88
- provider: params)
89
-
90
- @data = data if update_data
91
- data
92
- end
93
-
94
- # @param [String] username
95
- # @param [String] box_name
96
- # @param [String] version_number
97
- # @param [String] provider_name
98
- def delete(username = nil, box_name = nil, version_number = nil, provider_name = nil)
99
- @client.request('delete', provider_path(username, box_name, version_number, provider_name))
100
- end
101
-
102
- # @param [String] username
103
- # @param [String] box_name
104
- # @param [String] version_number
105
- # @param [String] provider_name
106
- # @return [String]
107
- def upload_url(username = nil, box_name = nil, version_number = nil, provider_name = nil)
108
- @client.request('get', "#{provider_path(username, box_name, version_number, provider_name)}/upload")['upload_path']
109
- end
110
-
111
- # @param [String] username
112
- # @param [String] box_name
113
- # @param [String] version_number
114
- # @param [String] provider_name
115
- # @param [String] file_path
116
- def upload_file(file_path, username = nil, box_name = nil, version_number = nil, provider_name = nil)
117
- url = upload_url(username, box_name, version_number, provider_name)
118
- payload = File.open(file_path, 'r')
119
- RestClient::Request.execute(
120
- method: :put,
121
- url: url,
122
- payload: payload,
123
- ssl_version: 'TLSv1'
124
- )
125
- end
126
-
127
- private
128
-
129
- # @return [Box]
130
- def box
131
- version.box
132
- end
133
-
134
- # @return [Account]
135
- def account
136
- box.account
137
- end
138
-
139
- def create_provider_path(username = nil, box_name = nil, version_number = nil)
140
- if username && box_name && version_number
141
- "/box/#{username}/#{box_name}/version/#{version_number}/providers"
142
- else
143
- "/box/#{account.username}/#{box.name}/version/#{version.number}/providers"
144
- end
145
- end
146
-
147
- def provider_path(username = nil, box_name = nil, version_number = nil, provider_name = nil)
148
- if username && box_name && version_number && name
149
- "/box/#{username}/#{box_name}/version/#{version_number}/provider/#{provider_name}"
150
- else
151
- "/box/#{account.username}/#{box.name}/version/#{version.number}/provider/#{name}"
152
- end
153
- end
154
- end
155
- end