vagrant_cloud 3.0.5 → 3.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/vagrant_cloud/account.rb +2 -2
- data/lib/vagrant_cloud/box/provider.rb +14 -4
- data/lib/vagrant_cloud/box/version.rb +11 -4
- data/lib/vagrant_cloud/client.rb +115 -37
- data/lib/vagrant_cloud/search.rb +2 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 06ac337d41c05fa0ab3f4dba19eb4b48369b7b21e87adea9beaf22c24d7a06ec
|
4
|
+
data.tar.gz: 20c9e7e4c6c6a045a34a5509e05e626a159069d76993d3f70bdf2f333a219083
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0c4fd65d40092ff9161d5330afda571efc2d852b23aedf7f8327d803eb2e096792999ebb3f69dd3cbce4663d5c6b79db121531737258084e18c634f626d25d35
|
7
|
+
data.tar.gz: 69eb59e4a61257533baf2707b998b29a6f88f8b37a4c54f6dea8daca3f19e0c93d479d68ae42a277f1ee3c972622625b380fbd7f5db9bfd8e212a583fa706118
|
@@ -75,7 +75,7 @@ module VagrantCloud
|
|
75
75
|
#
|
76
76
|
# @return [self]
|
77
77
|
def validate_token
|
78
|
-
client.
|
78
|
+
client.authentication_token_validate
|
79
79
|
self
|
80
80
|
end
|
81
81
|
|
@@ -104,7 +104,7 @@ module VagrantCloud
|
|
104
104
|
|
105
105
|
def setup!
|
106
106
|
if client.access_token
|
107
|
-
r = client.
|
107
|
+
r = client.authentication_token_validate
|
108
108
|
@username = r.dig(:user, :username)
|
109
109
|
end
|
110
110
|
end
|
@@ -14,9 +14,9 @@ module VagrantCloud
|
|
14
14
|
attr_required :name
|
15
15
|
attr_optional :hosted, :created_at, :updated_at,
|
16
16
|
:checksum, :checksum_type, :original_url, :download_url,
|
17
|
-
:url
|
17
|
+
:url, :architecture, :default_architecture
|
18
18
|
|
19
|
-
attr_mutable :url, :checksum, :checksum_type
|
19
|
+
attr_mutable :url, :checksum, :checksum_type, :architecture, :default_architecture
|
20
20
|
|
21
21
|
def initialize(version:, **opts)
|
22
22
|
if !version.is_a?(Version)
|
@@ -35,7 +35,8 @@ module VagrantCloud
|
|
35
35
|
username: version.box.username,
|
36
36
|
name: version.box.name,
|
37
37
|
version: version.version,
|
38
|
-
provider: name
|
38
|
+
provider: name,
|
39
|
+
architecture: architecture
|
39
40
|
)
|
40
41
|
pv = version.providers.dup
|
41
42
|
pv.delete(self)
|
@@ -87,7 +88,8 @@ module VagrantCloud
|
|
87
88
|
username: version.box.username,
|
88
89
|
name: version.box.name,
|
89
90
|
version: version.version,
|
90
|
-
provider: name
|
91
|
+
provider: name,
|
92
|
+
architecture: architecture,
|
91
93
|
}
|
92
94
|
if direct
|
93
95
|
r = version.box.organization.account.client.box_version_provider_upload_direct(**req_args)
|
@@ -161,9 +163,17 @@ module VagrantCloud
|
|
161
163
|
provider: name,
|
162
164
|
checksum: checksum,
|
163
165
|
checksum_type: checksum_type,
|
166
|
+
architecture: architecture,
|
167
|
+
default_architecture: default_architecture,
|
164
168
|
url: url
|
165
169
|
}
|
166
170
|
if exist?
|
171
|
+
# If the provider already exists, use the original architecture
|
172
|
+
# value for locating the existing record and use the current
|
173
|
+
# architecture for the new_architecture value so it can be updated
|
174
|
+
# properly
|
175
|
+
req_args[:architecture] = data[:architecture]
|
176
|
+
req_args[:new_architecture] = architecture
|
167
177
|
result = version.box.organization.account.client.box_version_provider_update(**req_args)
|
168
178
|
else
|
169
179
|
result = version.box.organization.account.client.box_version_provider_create(**req_args)
|
@@ -90,12 +90,19 @@ module VagrantCloud
|
|
90
90
|
#
|
91
91
|
# @param [String] pname Name of provider
|
92
92
|
# @return [Provider]
|
93
|
-
def add_provider(pname)
|
94
|
-
if providers.any? { |p|
|
93
|
+
def add_provider(pname, architecture=nil)
|
94
|
+
if providers.any? { |p|
|
95
|
+
p.name == pname &&
|
96
|
+
(architecture.nil? || p.architecture == architecture)
|
97
|
+
}
|
95
98
|
raise Error::BoxError::VersionProviderExistsError,
|
96
|
-
"Provider #{pname} already exists for box #{box.tag} version #{version}"
|
99
|
+
"Provider #{pname} already exists for box #{box.tag} version #{version} (#{architecture})"
|
97
100
|
end
|
98
|
-
pv = Provider.new(
|
101
|
+
pv = Provider.new(
|
102
|
+
version: self,
|
103
|
+
name: pname,
|
104
|
+
)
|
105
|
+
pv.architecture = architecture if architecture
|
99
106
|
clean(data: {providers: providers + [pv]})
|
100
107
|
pv
|
101
108
|
end
|
data/lib/vagrant_cloud/client.rb
CHANGED
@@ -1,8 +1,12 @@
|
|
1
1
|
module VagrantCloud
|
2
2
|
class Client
|
3
3
|
include Logger
|
4
|
-
#
|
5
|
-
|
4
|
+
# Path to the v1 API
|
5
|
+
API_V1_PATH = "/api/v1".freeze
|
6
|
+
# Path to the v2 API
|
7
|
+
API_V2_PATH = "/api/v2".freeze
|
8
|
+
# Default host URL
|
9
|
+
API_DEFAULT_URL = "https://vagrantcloud.com".freeze
|
6
10
|
# Valid methods that can be retried
|
7
11
|
IDEMPOTENT_METHODS = [:get, :head].freeze
|
8
12
|
# Number or allowed retries
|
@@ -41,10 +45,13 @@ module VagrantCloud
|
|
41
45
|
# @param [Instrumentor::Core] instrumentor Instrumentor to use
|
42
46
|
# @return [Client]
|
43
47
|
def initialize(access_token: nil, url_base: nil, retry_count: nil, retry_interval: nil, instrumentor: nil)
|
44
|
-
url_base =
|
48
|
+
url_base = API_DEFAULT_URL if url_base.nil?
|
45
49
|
remote_url = URI.parse(url_base)
|
46
50
|
@url_base = "#{remote_url.scheme}://#{remote_url.host}"
|
47
51
|
@path_base = remote_url.path
|
52
|
+
if @path_base.empty? || @path_base == API_V1_PATH || @path_base == API_V2_PATH
|
53
|
+
@path_base = nil
|
54
|
+
end
|
48
55
|
@access_token = access_token.dup.freeze if access_token
|
49
56
|
if !@access_token && ENV["VAGRANT_CLOUD_TOKEN"]
|
50
57
|
@access_token = ENV["VAGRANT_CLOUD_TOKEN"].dup.freeze
|
@@ -90,11 +97,29 @@ module VagrantCloud
|
|
90
97
|
# @param [String, URI] path Path of request
|
91
98
|
# @param [Hash] params Parameters to send with request
|
92
99
|
# @return [Hash]
|
93
|
-
def request(path:, method: :get, params: {})
|
94
|
-
|
95
|
-
|
96
|
-
path
|
100
|
+
def request(path:, method: :get, params: {}, api_version: 2)
|
101
|
+
# Apply any path modifications that are required
|
102
|
+
catch(:done) do
|
103
|
+
# If a base path is defined, and the provided path
|
104
|
+
# is already properly prefixed with it, do nothing.
|
105
|
+
throw :done if !path_base.nil? && path.start_with?(path_base)
|
106
|
+
|
107
|
+
# If the path does not include an API version
|
108
|
+
# prefix, add it now.
|
109
|
+
if !path.start_with?(API_V1_PATH) && !path.start_with?(API_V2_PATH)
|
110
|
+
case api_version
|
111
|
+
when 1
|
112
|
+
start_path = API_V1_PATH
|
113
|
+
when 2
|
114
|
+
start_path = API_V2_PATH
|
115
|
+
else
|
116
|
+
raise ArgumentError, "Unsupported API version provided"
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
path = [path_base, start_path, path].compact.join("/").gsub(/\/{2,}/, "/")
|
97
121
|
end
|
122
|
+
|
98
123
|
method = method.to_s.downcase.to_sym
|
99
124
|
|
100
125
|
# Build base request parameters
|
@@ -151,15 +176,17 @@ module VagrantCloud
|
|
151
176
|
# Submit a search on Vagrant Cloud
|
152
177
|
#
|
153
178
|
# @param [String] query Search query
|
179
|
+
# @param [String] architecture Limit results to only this architecture
|
154
180
|
# @param [String] provider Limit results to only this provider
|
155
181
|
# @param [String] sort Field to sort results ("downloads", "created", or "updated")
|
156
182
|
# @param [String] order Order to return sorted result ("desc" or "asc")
|
157
183
|
# @param [Integer] limit Number of results to return
|
158
184
|
# @param [Integer] page Page number of results to return
|
159
185
|
# @return [Hash]
|
160
|
-
def search(query: Data::Nil, provider: Data::Nil, sort: Data::Nil, order: Data::Nil, limit: Data::Nil, page: Data::Nil)
|
186
|
+
def search(query: Data::Nil, architecture: Data::Nil, provider: Data::Nil, sort: Data::Nil, order: Data::Nil, limit: Data::Nil, page: Data::Nil)
|
161
187
|
params = {
|
162
188
|
q: query,
|
189
|
+
architecture: architecture,
|
163
190
|
provider: provider,
|
164
191
|
sort: sort,
|
165
192
|
order: order,
|
@@ -189,14 +216,14 @@ module VagrantCloud
|
|
189
216
|
code: code
|
190
217
|
}
|
191
218
|
}
|
192
|
-
request(method: :post, path: "authenticate", params: params)
|
219
|
+
request(method: :post, path: "authenticate", params: params, api_version: 1)
|
193
220
|
end
|
194
221
|
|
195
222
|
# Delete the token currently in use
|
196
223
|
#
|
197
224
|
# @return [Hash] empty
|
198
225
|
def authentication_token_delete
|
199
|
-
request(method: :delete, path: "authenticate")
|
226
|
+
request(method: :delete, path: "authenticate", api_version: 1)
|
200
227
|
end
|
201
228
|
|
202
229
|
# Request a 2FA code is sent
|
@@ -217,7 +244,7 @@ module VagrantCloud
|
|
217
244
|
}
|
218
245
|
}
|
219
246
|
|
220
|
-
request(method: :post, path: "two-factor/request-code", params: params)
|
247
|
+
request(method: :post, path: "two-factor/request-code", params: params, api_version: 1)
|
221
248
|
end
|
222
249
|
|
223
250
|
# Validate the current token
|
@@ -367,9 +394,14 @@ module VagrantCloud
|
|
367
394
|
# @param [String] name Box name
|
368
395
|
# @param [String] version Box version
|
369
396
|
# @param [String] provider Provider name
|
397
|
+
# @param [String] architecture Architecture name
|
370
398
|
# @return [Hash] box version provider information
|
371
|
-
def box_version_provider_get(username:, name:, version:, provider:)
|
372
|
-
|
399
|
+
def box_version_provider_get(username:, name:, version:, provider:, architecture: nil)
|
400
|
+
req_path = ["/box", username, name, "version", version,
|
401
|
+
"provider", provider, architecture].compact.join("/")
|
402
|
+
api_version = architecture.nil? ? 1 : 2
|
403
|
+
|
404
|
+
request(method: :get, path: req_path, api_version: api_version)
|
373
405
|
end
|
374
406
|
|
375
407
|
# Create a new box version provider
|
@@ -378,17 +410,35 @@ module VagrantCloud
|
|
378
410
|
# @param [String] name Box name
|
379
411
|
# @param [String] version Box version
|
380
412
|
# @param [String] provider Provider name
|
413
|
+
# @param [String] architecture Architecture name
|
414
|
+
# @param [Boolean] default_architecture Flag architecture as default in named provider group
|
381
415
|
# @param [String] url Remote URL for box download
|
382
416
|
# @return [Hash] box version provider information
|
383
|
-
def box_version_provider_create(username:, name:, version:, provider:, url: Data::Nil, checksum: Data::Nil, checksum_type: Data::Nil)
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
417
|
+
def box_version_provider_create(username:, name:, version:, provider:, architecture: nil, default_architecture: Data::Nil, url: Data::Nil, checksum: Data::Nil, checksum_type: Data::Nil)
|
418
|
+
provider_params = {
|
419
|
+
name: provider,
|
420
|
+
url: url,
|
421
|
+
checksum: checksum,
|
422
|
+
checksum_type: checksum_type
|
423
|
+
}
|
424
|
+
if architecture.nil?
|
425
|
+
api_version = 1
|
426
|
+
else
|
427
|
+
api_version = 2
|
428
|
+
provider_params.merge!(
|
429
|
+
architecture: architecture,
|
430
|
+
default_architecture: default_architecture
|
431
|
+
)
|
432
|
+
end
|
433
|
+
|
434
|
+
request(
|
435
|
+
method: :post,
|
436
|
+
path: "/box/#{username}/#{name}/version/#{version}/providers",
|
437
|
+
params: {
|
438
|
+
provider: provider_params
|
439
|
+
},
|
440
|
+
api_version: api_version
|
441
|
+
)
|
392
442
|
end
|
393
443
|
|
394
444
|
# Update an existing box version provider
|
@@ -397,18 +447,31 @@ module VagrantCloud
|
|
397
447
|
# @param [String] name Box name
|
398
448
|
# @param [String] version Box version
|
399
449
|
# @param [String] provider Provider name
|
450
|
+
# @param [String] architecture Current architecture name
|
451
|
+
# @param [String] new_architecture New architecture name to apply
|
400
452
|
# @param [String] url Remote URL for box download
|
401
453
|
# @return [Hash] box version provider information
|
402
|
-
def box_version_provider_update(username:, name:, version:, provider:, url: Data::Nil, checksum: Data::Nil, checksum_type: Data::Nil)
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
checksum_type: checksum_type
|
409
|
-
}
|
454
|
+
def box_version_provider_update(username:, name:, version:, provider:, architecture: nil, new_architecture: Data::Nil, default_architecture: Data::Nil, url: Data::Nil, checksum: Data::Nil, checksum_type: Data::Nil)
|
455
|
+
provider_params = {
|
456
|
+
name: provider,
|
457
|
+
url: url,
|
458
|
+
checksum: checksum,
|
459
|
+
checksum_type: checksum_type
|
410
460
|
}
|
411
|
-
|
461
|
+
if architecture.nil?
|
462
|
+
api_version = 1
|
463
|
+
else
|
464
|
+
api_version = 2
|
465
|
+
provider_params.merge!(
|
466
|
+
architecture: new_architecture,
|
467
|
+
default_architecture: default_architecture
|
468
|
+
)
|
469
|
+
end
|
470
|
+
|
471
|
+
req_path = ["/box", username, name, "version", version,
|
472
|
+
"provider", provider, architecture].compact.join("/")
|
473
|
+
|
474
|
+
request(method: :put, path: req_path, params: {provider: provider_params}, api_version: api_version)
|
412
475
|
end
|
413
476
|
|
414
477
|
# Delete an existing box version provider
|
@@ -417,9 +480,14 @@ module VagrantCloud
|
|
417
480
|
# @param [String] name Box name
|
418
481
|
# @param [String] version Box version
|
419
482
|
# @param [String] provider Provider name
|
483
|
+
# @param [String] architecture Architecture name
|
420
484
|
# @return [Hash] box version provider information
|
421
|
-
def box_version_provider_delete(username:, name:, version:, provider:)
|
422
|
-
|
485
|
+
def box_version_provider_delete(username:, name:, version:, provider:, architecture: nil)
|
486
|
+
req_path = ["/box", username, name, "version", version,
|
487
|
+
"provider", provider, architecture].compact.join("/")
|
488
|
+
api_version = architecture.nil? ? 1 : 2
|
489
|
+
|
490
|
+
request(method: :delete, path: req_path, api_version: api_version)
|
423
491
|
end
|
424
492
|
|
425
493
|
# Upload a box asset for an existing box version provider
|
@@ -428,9 +496,14 @@ module VagrantCloud
|
|
428
496
|
# @param [String] name Box name
|
429
497
|
# @param [String] version Box version
|
430
498
|
# @param [String] provider Provider name
|
499
|
+
# @param [String] architecture Architecture name
|
431
500
|
# @return [Hash] box version provider upload information (contains upload_path entry)
|
432
|
-
def box_version_provider_upload(username:, name:, version:, provider:)
|
433
|
-
|
501
|
+
def box_version_provider_upload(username:, name:, version:, provider:, architecture: nil)
|
502
|
+
req_path = ["/box", username, name, "version", version,
|
503
|
+
"provider", provider, architecture, "upload"].compact.join("/")
|
504
|
+
api_version = architecture.nil? ? 1 : 2
|
505
|
+
|
506
|
+
request(method: :get, path: req_path, api_version: api_version)
|
434
507
|
end
|
435
508
|
|
436
509
|
# Upload a box asset directly to the backend storage for an existing box version provider
|
@@ -439,9 +512,14 @@ module VagrantCloud
|
|
439
512
|
# @param [String] name Box name
|
440
513
|
# @param [String] version Box version
|
441
514
|
# @param [String] provider Provider name
|
515
|
+
# @param [String] architecture Architecture name
|
442
516
|
# @return [Hash] box version provider upload information (contains upload_path and callback entries)
|
443
|
-
def box_version_provider_upload_direct(username:, name:, version:, provider:)
|
444
|
-
|
517
|
+
def box_version_provider_upload_direct(username:, name:, version:, provider:, architecture: nil)
|
518
|
+
req_path = ["/box", username, name, "version", version,
|
519
|
+
"provider", provider, architecture, "upload/direct"].compact.join("/")
|
520
|
+
api_version = architecture.nil? ? 1 : 2
|
521
|
+
|
522
|
+
request(method: :get, path: req_path, api_version: api_version)
|
445
523
|
end
|
446
524
|
|
447
525
|
protected
|
data/lib/vagrant_cloud/search.rb
CHANGED
@@ -43,10 +43,11 @@ module VagrantCloud
|
|
43
43
|
# @param [String] limit
|
44
44
|
# @param [String] page
|
45
45
|
# @return [Response::Search]
|
46
|
-
def search(query: Data::Nil, provider: Data::Nil, sort: Data::Nil, order: Data::Nil, limit: Data::Nil, page: Data::Nil)
|
46
|
+
def search(query: Data::Nil, architecture: Data::Nil, provider: Data::Nil, sort: Data::Nil, order: Data::Nil, limit: Data::Nil, page: Data::Nil)
|
47
47
|
@lock.synchronize do
|
48
48
|
@params = {
|
49
49
|
query: query,
|
50
|
+
architecture: architecture,
|
50
51
|
provider: provider,
|
51
52
|
sort: sort,
|
52
53
|
order: order,
|
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: 3.
|
4
|
+
version: 3.1.1
|
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:
|
12
|
+
date: 2024-01-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: excon
|
@@ -142,7 +142,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
142
142
|
- !ruby/object:Gem::Version
|
143
143
|
version: '0'
|
144
144
|
requirements: []
|
145
|
-
rubygems_version: 3.
|
145
|
+
rubygems_version: 3.3.26
|
146
146
|
signing_key:
|
147
147
|
specification_version: 4
|
148
148
|
summary: Vagrant Cloud API Library
|