vagrant_cloud 3.0.5 → 3.1.0

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
  SHA256:
3
- metadata.gz: 4573b763dfa1cbdfb1070d7b9f5ba9db24f56145ea7ce94cc65ff64748d39bad
4
- data.tar.gz: 3695499ffb77f98444b8435ae48a36a2ac09041c9ffe1fb07ca1447b7eadb179
3
+ metadata.gz: 4768031887b3a27585e8cf55091810654545e2aee475d7e2b2dbff927e8c7d6f
4
+ data.tar.gz: 480e6a69c2eac82185ff3cd9d90a30f00cd26e4a7d45c548ed2ba2785ecef96d
5
5
  SHA512:
6
- metadata.gz: 305dd27dcda8c280620e52d0675aff2a6c3252d0b49a06cd23633aae306a8b1d12e9d1b25da8f2c71b9a2898797201dc60ef6f6a4fb8cdf8d5306e4b40cdd945
7
- data.tar.gz: 8e02785ca219228988b0c77fd07ca06a149c259a263eda3aa70e19f5d9dfa2350af01f7727007c39defe8b392c7809fa0ab339def0113d2acd3dea206b11115c
6
+ metadata.gz: 7343ea8f89e7e4ecb8f9f2e0f1f5478a37382e3c4de44bb61ec40fcebd18b5e65f302365cfa02aead507d28883a3ab561bf3af949f77418e46366043ee7eddea
7
+ data.tar.gz: 50b74d2dcf7f8671afa67bfec5d0fdeebdf40b51206a48f53a35f21b63f65674e1859bcdcaeb2f9d79e940870df50c75b4e6fc9b412b86b1c028bcac9c9f2bcd
@@ -75,7 +75,7 @@ module VagrantCloud
75
75
  #
76
76
  # @return [self]
77
77
  def validate_token
78
- client.request(path: "authenticate")
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.request(path: "authenticate")
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| p.name == pname }
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(version: self, name: pname)
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
@@ -1,8 +1,12 @@
1
1
  module VagrantCloud
2
2
  class Client
3
3
  include Logger
4
- # Base Vagrant Cloud API URL
5
- DEFAULT_URL = 'https://vagrantcloud.com/api/v1'.freeze
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 = DEFAULT_URL if url_base.nil?
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 == 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,10 +97,19 @@ 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
- if !path.start_with?(path_base)
100
+ def request(path:, method: :get, params: {}, api_version: 2)
101
+ if path_base.nil? || !path.start_with?(path_base)
102
+ if !path_base.nil?
103
+ start_path = path_base
104
+ elsif api_version == 1
105
+ start_path = API_V1_PATH
106
+ elsif api_version == 2
107
+ start_path = API_V2_PATH
108
+ else
109
+ raise "Unsupported API version provided"
110
+ end
95
111
  # Build the full path for the request and clean it
96
- path = [path_base, path].compact.join("/").gsub(/\/{2,}/, "/")
112
+ path = [start_path, path].compact.join("/").gsub(/\/{2,}/, "/")
97
113
  end
98
114
  method = method.to_s.downcase.to_sym
99
115
 
@@ -151,15 +167,17 @@ module VagrantCloud
151
167
  # Submit a search on Vagrant Cloud
152
168
  #
153
169
  # @param [String] query Search query
170
+ # @param [String] architecture Limit results to only this architecture
154
171
  # @param [String] provider Limit results to only this provider
155
172
  # @param [String] sort Field to sort results ("downloads", "created", or "updated")
156
173
  # @param [String] order Order to return sorted result ("desc" or "asc")
157
174
  # @param [Integer] limit Number of results to return
158
175
  # @param [Integer] page Page number of results to return
159
176
  # @return [Hash]
160
- def search(query: Data::Nil, provider: Data::Nil, sort: Data::Nil, order: Data::Nil, limit: Data::Nil, page: Data::Nil)
177
+ def search(query: Data::Nil, architecture: Data::Nil, provider: Data::Nil, sort: Data::Nil, order: Data::Nil, limit: Data::Nil, page: Data::Nil)
161
178
  params = {
162
179
  q: query,
180
+ architecture: architecture,
163
181
  provider: provider,
164
182
  sort: sort,
165
183
  order: order,
@@ -189,14 +207,14 @@ module VagrantCloud
189
207
  code: code
190
208
  }
191
209
  }
192
- request(method: :post, path: "authenticate", params: params)
210
+ request(method: :post, path: "authenticate", params: params, api_version: 1)
193
211
  end
194
212
 
195
213
  # Delete the token currently in use
196
214
  #
197
215
  # @return [Hash] empty
198
216
  def authentication_token_delete
199
- request(method: :delete, path: "authenticate")
217
+ request(method: :delete, path: "authenticate", api_version: 1)
200
218
  end
201
219
 
202
220
  # Request a 2FA code is sent
@@ -217,7 +235,7 @@ module VagrantCloud
217
235
  }
218
236
  }
219
237
 
220
- request(method: :post, path: "two-factor/request-code", params: params)
238
+ request(method: :post, path: "two-factor/request-code", params: params, api_version: 1)
221
239
  end
222
240
 
223
241
  # Validate the current token
@@ -367,9 +385,14 @@ module VagrantCloud
367
385
  # @param [String] name Box name
368
386
  # @param [String] version Box version
369
387
  # @param [String] provider Provider name
388
+ # @param [String] architecture Architecture name
370
389
  # @return [Hash] box version provider information
371
- def box_version_provider_get(username:, name:, version:, provider:)
372
- request(method: :get, path: "/box/#{username}/#{name}/version/#{version}/provider/#{provider}")
390
+ def box_version_provider_get(username:, name:, version:, provider:, architecture: nil)
391
+ req_path = ["/box", username, name, "version", version,
392
+ "provider", provider, architecture].compact.join("/")
393
+ api_version = architecture.nil? ? 1 : 2
394
+
395
+ request(method: :get, path: req_path, api_version: api_version)
373
396
  end
374
397
 
375
398
  # Create a new box version provider
@@ -378,17 +401,35 @@ module VagrantCloud
378
401
  # @param [String] name Box name
379
402
  # @param [String] version Box version
380
403
  # @param [String] provider Provider name
404
+ # @param [String] architecture Architecture name
405
+ # @param [Boolean] default_architecture Flag architecture as default in named provider group
381
406
  # @param [String] url Remote URL for box download
382
407
  # @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
- request(method: :post, path: "/box/#{username}/#{name}/version/#{version}/providers", params: {
385
- provider: {
386
- name: provider,
387
- url: url,
388
- checksum: checksum,
389
- checksum_type: checksum_type
390
- }
391
- })
408
+ 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)
409
+ provider_params = {
410
+ name: provider,
411
+ url: url,
412
+ checksum: checksum,
413
+ checksum_type: checksum_type
414
+ }
415
+ if architecture.nil?
416
+ api_version = 1
417
+ else
418
+ api_version = 2
419
+ provider_params.merge!(
420
+ architecture: architecture,
421
+ default_architecture: default_architecture
422
+ )
423
+ end
424
+
425
+ request(
426
+ method: :post,
427
+ path: "/box/#{username}/#{name}/version/#{version}/providers",
428
+ params: {
429
+ provider: provider_params
430
+ },
431
+ api_version: api_version
432
+ )
392
433
  end
393
434
 
394
435
  # Update an existing box version provider
@@ -397,18 +438,31 @@ module VagrantCloud
397
438
  # @param [String] name Box name
398
439
  # @param [String] version Box version
399
440
  # @param [String] provider Provider name
441
+ # @param [String] architecture Current architecture name
442
+ # @param [String] new_architecture New architecture name to apply
400
443
  # @param [String] url Remote URL for box download
401
444
  # @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
- params = {
404
- provider: {
405
- name: provider,
406
- url: url,
407
- checksum: checksum,
408
- checksum_type: checksum_type
409
- }
445
+ 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)
446
+ provider_params = {
447
+ name: provider,
448
+ url: url,
449
+ checksum: checksum,
450
+ checksum_type: checksum_type
410
451
  }
411
- request(method: :put, path: "/box/#{username}/#{name}/version/#{version}/provider/#{provider}", params: params)
452
+ if architecture.nil?
453
+ api_version = 1
454
+ else
455
+ api_version = 2
456
+ provider_params.merge!(
457
+ architecture: new_architecture,
458
+ default_architecture: default_architecture
459
+ )
460
+ end
461
+
462
+ req_path = ["/box", username, name, "version", version,
463
+ "provider", provider, architecture].compact.join("/")
464
+
465
+ request(method: :put, path: req_path, params: {provider: provider_params}, api_version: api_version)
412
466
  end
413
467
 
414
468
  # Delete an existing box version provider
@@ -417,9 +471,14 @@ module VagrantCloud
417
471
  # @param [String] name Box name
418
472
  # @param [String] version Box version
419
473
  # @param [String] provider Provider name
474
+ # @param [String] architecture Architecture name
420
475
  # @return [Hash] box version provider information
421
- def box_version_provider_delete(username:, name:, version:, provider:)
422
- request(method: :delete, path: "/box/#{username}/#{name}/version/#{version}/provider/#{provider}")
476
+ def box_version_provider_delete(username:, name:, version:, provider:, architecture: nil)
477
+ req_path = ["/box", username, name, "version", version,
478
+ "provider", provider, architecture].compact.join("/")
479
+ api_version = architecture.nil? ? 1 : 2
480
+
481
+ request(method: :delete, path: req_path, api_version: api_version)
423
482
  end
424
483
 
425
484
  # Upload a box asset for an existing box version provider
@@ -428,9 +487,14 @@ module VagrantCloud
428
487
  # @param [String] name Box name
429
488
  # @param [String] version Box version
430
489
  # @param [String] provider Provider name
490
+ # @param [String] architecture Architecture name
431
491
  # @return [Hash] box version provider upload information (contains upload_path entry)
432
- def box_version_provider_upload(username:, name:, version:, provider:)
433
- request(method: :get, path: "/box/#{username}/#{name}/version/#{version}/provider/#{provider}/upload")
492
+ def box_version_provider_upload(username:, name:, version:, provider:, architecture: nil)
493
+ req_path = ["/box", username, name, "version", version,
494
+ "provider", provider, architecture, "upload"].compact.join("/")
495
+ api_version = architecture.nil? ? 1 : 2
496
+
497
+ request(method: :get, path: req_path, api_version: api_version)
434
498
  end
435
499
 
436
500
  # Upload a box asset directly to the backend storage for an existing box version provider
@@ -439,9 +503,14 @@ module VagrantCloud
439
503
  # @param [String] name Box name
440
504
  # @param [String] version Box version
441
505
  # @param [String] provider Provider name
506
+ # @param [String] architecture Architecture name
442
507
  # @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
- request(method: :get, path: "/box/#{username}/#{name}/version/#{version}/provider/#{provider}/upload/direct")
508
+ def box_version_provider_upload_direct(username:, name:, version:, provider:, architecture: nil)
509
+ req_path = ["/box", username, name, "version", version,
510
+ "provider", provider, architecture, "upload/direct"].compact.join("/")
511
+ api_version = architecture.nil? ? 1 : 2
512
+
513
+ request(method: :get, path: req_path, api_version: api_version)
445
514
  end
446
515
 
447
516
  protected
@@ -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.0.5
4
+ version: 3.1.0
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: 2021-07-22 00:00:00.000000000 Z
12
+ date: 2023-09-25 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.2.22
145
+ rubygems_version: 3.3.26
146
146
  signing_key:
147
147
  specification_version: 4
148
148
  summary: Vagrant Cloud API Library