Update Box#UpdateInfo to use box metadata client

This commit is contained in:
sophia 2022-04-06 11:37:47 -05:00 committed by Paul Hinze
parent 8f23ce0d84
commit cddcfef0a1
No known key found for this signature in database
GPG Key ID: B69DEDF2D55501C0
6 changed files with 22 additions and 16 deletions

View File

@ -244,7 +244,7 @@ func (b *Box) HasUpdate(version string) (updateAvailable bool, err error) {
return 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() metadata, err := b.loadMetadata()
if err != nil { if err != nil {
return false, nil, "", "", err return false, nil, "", "", err
@ -265,7 +265,7 @@ func (b *Box) UpdateInfo(version string) (updateAvailable bool, meta core.BoxMet
if result == nil { if result == nil {
return false, nil, "", "", 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 // Checks if this box is in use according to the given machine

View File

@ -68,11 +68,11 @@ module Vagrant
metadata = update_info[0] metadata = update_info[0]
new_version = update_info[1] new_version = update_info[1]
new_provider = update_info[2] new_provider = update_info[2]
m = downcase_stringify_keys(metadata) # m = downcase_stringify_keys(metadata)
[ [
BoxMetadata.new(nil, m), BoxMetadata.new(nil, client: metadata),
BoxMetadata::Version.new({"version" => new_version}), BoxMetadata::Version.new({"version" => new_version}, ver: new_version, client: metadata),
BoxMetadata::Provider.new({"name" => new_provider}), BoxMetadata::Provider.new({"name" => new_provider}, client: metadata),
] ]
end end

View File

@ -99,7 +99,7 @@ module Vagrant
# @return [String] # @return [String]
attr_accessor :version attr_accessor :version
def initialize(raw=nil) def initialize(raw=nil, **_)
return if !raw return if !raw
@version = raw["version"] @version = raw["version"]
@ -149,7 +149,7 @@ module Vagrant
# @return [String] # @return [String]
attr_accessor :checksum_type attr_accessor :checksum_type
def initialize(raw) def initialize(raw, **_)
@name = raw["name"] @name = raw["name"]
@url = raw["url"] @url = raw["url"]
@checksum = raw["checksum"] @checksum = raw["checksum"]

View File

@ -15,15 +15,21 @@ module Vagrant
attr_accessor :description attr_accessor :description
# @param [IO] io An IO object to read the metadata from. # @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") @logger = Log4r::Logger.new("vagrant::box")
if !client.nil?
# Use client if available
@client = client
else
# If client is not available, then try to load from url
if url.nil? if url.nil?
raise ArgumentError, raise ArgumentError,
"Metadata URL is required for `#{self.class.name}'" "Metadata URL is required for `#{self.class.name}' if a client is not provided"
end end
@client = Vagrant.plugin("2").remote_manager.core_plugin_manager.get_plugin("boxmetadata") @client = Vagrant.plugin("2").remote_manager.core_plugin_manager.get_plugin("boxmetadata")
@client.load_metadata(url) @client.load_metadata(url)
end
@name = @client.name @name = @client.name
end end

View File

@ -848,7 +848,7 @@ Google::Protobuf::DescriptorPool.generated_pool.build do
end end
add_message "hashicorp.vagrant.sdk.Box.UpdateInfoResponse" do add_message "hashicorp.vagrant.sdk.Box.UpdateInfoResponse" do
optional :has_update, :bool, 1 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_version, :string, 3
optional :new_provider, :string, 4 optional :new_provider, :string, 4
end end

View File

@ -30,7 +30,7 @@ module VagrantPlugins
version: version version: version
)) ))
if res.has_update 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] return [meta, res.new_version, res.new_provider]
else else
nil nil