Add DB changes for host, set members, and host addresses for plugins. (#1584)

* Add DB changes for host, set members, and host addresses for plugins.

* Add priority, address review feedback, update tests, naming, protos

Co-authored-by: Jeff Mitchell <jeffrey.mitchell@gmail.com>
Co-authored-by: Michael Gaffney <mgaffney@users.noreply.github.com>
This commit is contained in:
authored and GitHub committed 2021-10-20 12:20:28 -07:00
1 parent e8313146f6
commit 23baaac36b
26 files changed
+2341 -352

No files matched your search

+65
View File
@@ -2,12 +2,18 @@ package plugin
import (
"context"
"crypto/rand"
"fmt"
"io"
"net"
"testing"
"github.com/hashicorp/boundary/internal/db"
"github.com/hashicorp/boundary/internal/host/plugin/store"
"github.com/hashicorp/boundary/internal/kms"
"github.com/hashicorp/boundary/internal/plugin/host"
plgpb "github.com/hashicorp/boundary/sdk/pbs/plugin"
"github.com/hashicorp/go-secure-stdlib/base62"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
@@ -67,6 +73,65 @@ func TestSet(t *testing.T, conn *db.DB, kmsCache *kms.Kms, hc *HostCatalog, plgm
return set
}
func TestExternalHosts(t *testing.T, catalog *HostCatalog, setIds []string, count int) ([]*plgpb.ListHostsResponseHost, []*Host) {
t.Helper()
require := require.New(t)
retRH := make([]*plgpb.ListHostsResponseHost, 0, count)
retH := make([]*Host, 0, count)
for i := 0; i < count; i++ {
externalId, err := base62.Random(10)
require.NoError(err)
ipStr := testGetIpAddress(t)
dnsName := testGetDnsName(t)
retRH = append(retRH, &plgpb.ListHostsResponseHost{
ExternalId: externalId,
SetIds: setIds,
IpAddresses: []string{ipStr},
DnsNames: []string{dnsName},
})
publicId, err := newHostId(context.Background(), catalog.PublicId, externalId)
require.NoError(err)
retH = append(retH, &Host{
PluginId: catalog.PluginId,
Host: &store.Host{
CatalogId: catalog.PublicId,
PublicId: publicId,
ExternalId: externalId,
IpAddresses: []string{ipStr},
DnsNames: []string{dnsName},
},
})
}
return retRH, retH
}
func testGetDnsName(t *testing.T) string {
dnsName, err := base62.Random(10)
require.NoError(t, err)
return fmt.Sprintf("%s.example.com", dnsName)
}
func testGetIpAddress(t *testing.T) string {
ipBytes := make([]byte, 4)
for {
lr := io.LimitReader(rand.Reader, 4)
n, err := lr.Read(ipBytes)
require.NoError(t, err)
require.Equal(t, n, 4)
ip := net.IP(ipBytes)
v4 := ip.To4()
if v4 != nil {
return v4.String()
}
}
}
var _ plgpb.HostPluginServiceServer = (*TestPluginServer)(nil)
// TestPluginServer provides a host plugin service server where each method can be overwritten for tests.