From 154a4e56f0bed98d576dc11e3a090d2217958bb6 Mon Sep 17 00:00:00 2001 From: sophia Date: Wed, 11 Aug 2021 12:21:52 -0400 Subject: [PATCH] Use uuid as Target Index identifier --- internal/core/target_index.go | 37 +++++-------------- .../vagrant_plugin_sdk/plugin_services_pb.rb | 3 -- 2 files changed, 10 insertions(+), 30 deletions(-) diff --git a/internal/core/target_index.go b/internal/core/target_index.go index 2637418d0..6831d3718 100644 --- a/internal/core/target_index.go +++ b/internal/core/target_index.go @@ -5,9 +5,9 @@ import ( "github.com/hashicorp/go-hclog" "github.com/hashicorp/vagrant-plugin-sdk/core" + "github.com/hashicorp/vagrant-plugin-sdk/proto/vagrant_plugin_sdk" "github.com/hashicorp/vagrant/internal/server/proto/vagrant_server" "github.com/hashicorp/vagrant/internal/serverclient" - "github.com/mitchellh/mapstructure" ) // TargetIndex represents @@ -21,43 +21,26 @@ type TargetIndex struct { closers []func() error } -func (t *TargetIndex) Delete(ref *core.TargetRef) (err error) { +func (t *TargetIndex) Delete(uuid string) (err error) { _, err = t.client.DeleteTarget( t.ctx, &vagrant_server.DeleteTargetRequest{ - Target: ref.Ref(), + Target: &vagrant_plugin_sdk.Ref_Target{ResourceId: uuid}, }, ) return } -func (t *TargetIndex) Get(ref *core.TargetRef) (entry core.Target, err error) { - entry, err = t.project.Target(ref.Name) - if err != nil { - entry, err = t.project.Target(ref.ResourceId) - return - } - return +func (t *TargetIndex) Get(uuid string) (entry core.Target, err error) { + return t.project.Target(uuid) } -func (t *TargetIndex) Includes(ref *core.TargetRef) (exists bool, err error) { - var req *vagrant_server.Target - mapstructure.Decode(ref, &req) - // TODO: Not sure if this interface is going to change, - // would be neat if FindTarget accepted a Ref_Target - _, err = t.client.FindTarget( - t.ctx, - &vagrant_server.FindTargetRequest{ - Target: req, - }, - ) - // TODO: Not sure what should be returned by the api - // if there is not Target found. For now assuming that - // if a target is not found an error is returned - if err != nil { - return false, err +func (t *TargetIndex) Includes(uuid string) (exists bool, err error) { + _, err = t.project.Target(uuid) + if err == nil { + return true, nil } - return true, err + return false, nil } func (t *TargetIndex) Set(entry core.Target) (updatedEntry core.Target, err error) { diff --git a/lib/vagrant/protobufs/proto/vagrant_plugin_sdk/plugin_services_pb.rb b/lib/vagrant/protobufs/proto/vagrant_plugin_sdk/plugin_services_pb.rb index b9853311a..9fe99a7da 100644 --- a/lib/vagrant/protobufs/proto/vagrant_plugin_sdk/plugin_services_pb.rb +++ b/lib/vagrant/protobufs/proto/vagrant_plugin_sdk/plugin_services_pb.rb @@ -341,7 +341,6 @@ module Hashicorp rpc :VagrantfilePath, ::Google::Protobuf::Empty, ::Hashicorp::Vagrant::Sdk::Target::VagrantfilePathResponse rpc :UpdatedAt, ::Google::Protobuf::Empty, ::Hashicorp::Vagrant::Sdk::Target::UpdatedAtResponse rpc :Communicate, ::Google::Protobuf::Empty, ::Hashicorp::Vagrant::Sdk::Args::Communicator - rpc :Ref, ::Google::Protobuf::Empty, ::Hashicorp::Vagrant::Sdk::Ref::Target rpc :Save, ::Google::Protobuf::Empty, ::Google::Protobuf::Empty end @@ -372,7 +371,6 @@ module Hashicorp rpc :VagrantfilePath, ::Google::Protobuf::Empty, ::Hashicorp::Vagrant::Sdk::Target::VagrantfilePathResponse rpc :UpdatedAt, ::Google::Protobuf::Empty, ::Hashicorp::Vagrant::Sdk::Target::UpdatedAtResponse rpc :Communicate, ::Google::Protobuf::Empty, ::Hashicorp::Vagrant::Sdk::Args::Communicator - rpc :Ref, ::Google::Protobuf::Empty, ::Hashicorp::Vagrant::Sdk::Ref::Target rpc :Save, ::Google::Protobuf::Empty, ::Google::Protobuf::Empty # Machine specific rpc :SetID, ::Hashicorp::Vagrant::Sdk::Target::Machine::SetIDRequest, ::Google::Protobuf::Empty @@ -418,7 +416,6 @@ module Hashicorp rpc :Target, ::Hashicorp::Vagrant::Sdk::Project::TargetRequest, ::Hashicorp::Vagrant::Sdk::Args::Target rpc :TargetNames, ::Google::Protobuf::Empty, ::Hashicorp::Vagrant::Sdk::Project::TargetNamesResponse rpc :TargetIds, ::Google::Protobuf::Empty, ::Hashicorp::Vagrant::Sdk::Project::TargetIdsResponse - rpc :Ref, ::Google::Protobuf::Empty, ::Hashicorp::Vagrant::Sdk::Ref::Project end Stub = Service.rpc_stub_class