Update Box#UpdateInfo to use box metadata client
This commit is contained in:
parent
8f23ce0d84
commit
cddcfef0a1
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
@ -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"]
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user