diff --git a/internal/core/box.go b/internal/core/box.go index b41695529..79b79f4f9 100644 --- a/internal/core/box.go +++ b/internal/core/box.go @@ -244,7 +244,7 @@ func (b *Box) HasUpdate(version string) (updateAvailable bool, err error) { return } -func (b *Box) UpdateInfo(version string) (updateAvailable bool, meta core.BoxMetadataMap, newVersion string, newProvider string, err error) { +func (b *Box) UpdateInfo(version string) (updateAvailable bool, meta core.BoxMetadata, newVersion string, newProvider string, err error) { metadata, err := b.loadMetadata() if err != nil { return false, nil, "", "", err @@ -265,7 +265,7 @@ func (b *Box) UpdateInfo(version string) (updateAvailable bool, meta core.BoxMet if result == nil { return false, nil, "", "", nil } - return true, metadata.ToMap(), result.Version, b.box.Provider, nil + return true, metadata, result.Version, b.box.Provider, nil } // Checks if this box is in use according to the given machine diff --git a/lib/vagrant/box/remote.rb b/lib/vagrant/box/remote.rb index b31eafef5..e511f459a 100644 --- a/lib/vagrant/box/remote.rb +++ b/lib/vagrant/box/remote.rb @@ -68,11 +68,11 @@ module Vagrant metadata = update_info[0] new_version = update_info[1] new_provider = update_info[2] - m = downcase_stringify_keys(metadata) + # m = downcase_stringify_keys(metadata) [ - BoxMetadata.new(nil, m), - BoxMetadata::Version.new({"version" => new_version}), - BoxMetadata::Provider.new({"name" => new_provider}), + BoxMetadata.new(nil, client: metadata), + BoxMetadata::Version.new({"version" => new_version}, ver: new_version, client: metadata), + BoxMetadata::Provider.new({"name" => new_provider}, client: metadata), ] end diff --git a/lib/vagrant/box_metadata.rb b/lib/vagrant/box_metadata.rb index ba0e796f3..0f74f4da1 100644 --- a/lib/vagrant/box_metadata.rb +++ b/lib/vagrant/box_metadata.rb @@ -99,7 +99,7 @@ module Vagrant # @return [String] attr_accessor :version - def initialize(raw=nil) + def initialize(raw=nil, **_) return if !raw @version = raw["version"] @@ -149,7 +149,7 @@ module Vagrant # @return [String] attr_accessor :checksum_type - def initialize(raw) + def initialize(raw, **_) @name = raw["name"] @url = raw["url"] @checksum = raw["checksum"] diff --git a/lib/vagrant/box_metadata/remote.rb b/lib/vagrant/box_metadata/remote.rb index 6bb8f0682..208772138 100644 --- a/lib/vagrant/box_metadata/remote.rb +++ b/lib/vagrant/box_metadata/remote.rb @@ -15,15 +15,21 @@ module Vagrant attr_accessor :description # @param [IO] io An IO object to read the metadata from. - def initialize(io, url: nil) + def initialize(io, url: nil, client: nil) @logger = Log4r::Logger.new("vagrant::box") - if url.nil? - raise ArgumentError, - "Metadata URL is required for `#{self.class.name}'" + if !client.nil? + # Use client if available + @client = client + else + # If client is not available, then try to load from url + if url.nil? + raise ArgumentError, + "Metadata URL is required for `#{self.class.name}' if a client is not provided" + end + @client = Vagrant.plugin("2").remote_manager.core_plugin_manager.get_plugin("boxmetadata") + @client.load_metadata(url) end - @client = Vagrant.plugin("2").remote_manager.core_plugin_manager.get_plugin("boxmetadata") - @client.load_metadata(url) @name = @client.name end diff --git a/lib/vagrant/protobufs/proto/vagrant_plugin_sdk/plugin_pb.rb b/lib/vagrant/protobufs/proto/vagrant_plugin_sdk/plugin_pb.rb index 2809099dd..072c684af 100644 --- a/lib/vagrant/protobufs/proto/vagrant_plugin_sdk/plugin_pb.rb +++ b/lib/vagrant/protobufs/proto/vagrant_plugin_sdk/plugin_pb.rb @@ -848,7 +848,7 @@ Google::Protobuf::DescriptorPool.generated_pool.build do end add_message "hashicorp.vagrant.sdk.Box.UpdateInfoResponse" do optional :has_update, :bool, 1 - optional :metadata, :message, 2, "hashicorp.vagrant.sdk.Args.Hash" + optional :metadata, :message, 2, "hashicorp.vagrant.sdk.Args.BoxMetadata" optional :new_version, :string, 3 optional :new_provider, :string, 4 end diff --git a/plugins/commands/serve/client/box.rb b/plugins/commands/serve/client/box.rb index a2187f44e..0b140a500 100644 --- a/plugins/commands/serve/client/box.rb +++ b/plugins/commands/serve/client/box.rb @@ -30,7 +30,7 @@ module VagrantPlugins version: version )) if res.has_update - meta = mapper.map(res.metadata, to: Hash) + meta = mapper.map(res.metadata, to: Client::BoxMetadata) return [meta, res.new_version, res.new_provider] else nil