Remove priority values from host_ip_address/host_dns_name (#1633)
This commit is contained in:
1 parent
1cf94d0e3e
commit
804cb22699
8 files changed
+95
-320
No files matched your search
@@ -209,15 +209,12 @@ begin;
|
||||
references host(public_id)
|
||||
on delete cascade
|
||||
on update cascade,
|
||||
priority wt_priority,
|
||||
address inet not null,
|
||||
create_time wt_timestamp,
|
||||
primary key (host_id, priority),
|
||||
constraint host_ip_address_host_id_address_uq
|
||||
unique(host_id, address)
|
||||
primary key (host_id, address)
|
||||
);
|
||||
comment on table host_ip_address is
|
||||
'host_ip_address entries are ip addresses set on a host with a preserved order.';
|
||||
'host_ip_address entries are ip addresses set on a host.';
|
||||
|
||||
create trigger default_create_time_column before insert on host_ip_address
|
||||
for each row execute procedure default_create_time();
|
||||
@@ -244,15 +241,12 @@ begin;
|
||||
references host(public_id)
|
||||
on delete cascade
|
||||
on update cascade,
|
||||
priority wt_priority,
|
||||
name wt_dns_name,
|
||||
create_time wt_timestamp,
|
||||
primary key (host_id, priority),
|
||||
constraint host_dns_name_host_id_name_uq
|
||||
unique(host_id, name)
|
||||
primary key (host_id, name)
|
||||
);
|
||||
comment on table host_dns_name is
|
||||
'host_dns_name entries are dns names set on a host with a preserved order.';
|
||||
'host_dns_name entries are dns names set on a host';
|
||||
|
||||
create trigger default_create_time_column before insert on host_dns_name
|
||||
for each row execute procedure default_create_time();
|
||||
@@ -359,8 +353,8 @@ begin;
|
||||
h.create_time,
|
||||
h.update_time,
|
||||
-- the string_agg(..) column will be null if there are no associated value objects
|
||||
string_agg(distinct concat_ws('=', hip.priority, hip.address), '|') as ip_addresses,
|
||||
string_agg(distinct concat_ws('=', hdns.priority, hdns.name), '|') as dns_names
|
||||
string_agg(distinct host(hip.address), '|') as ip_addresses,
|
||||
string_agg(distinct hdns.name, '|') as dns_names
|
||||
from
|
||||
host_plugin_host h
|
||||
join host_plugin_catalog hc on h.catalog_id = hc.public_id
|
||||
|
||||
@@ -17,13 +17,12 @@ type DnsName struct {
|
||||
tableName string `gorm:"-"`
|
||||
}
|
||||
|
||||
func NewDnsName(ctx context.Context, hostId string, priority uint32, name string) (*DnsName, error) {
|
||||
func NewDnsName(ctx context.Context, hostId string, name string) (*DnsName, error) {
|
||||
const op = "host.NewDnsName"
|
||||
dn := &DnsName{
|
||||
DnsName: &store.DnsName{
|
||||
HostId: hostId,
|
||||
Name: name,
|
||||
Priority: priority,
|
||||
HostId: hostId,
|
||||
Name: name,
|
||||
},
|
||||
}
|
||||
if err := dn.validate(ctx, op); err != nil {
|
||||
@@ -37,9 +36,6 @@ func (dn *DnsName) validate(ctx context.Context, caller errors.Op) error {
|
||||
if dn.HostId == "" {
|
||||
return errors.New(ctx, errors.InvalidParameter, caller, "missing host id")
|
||||
}
|
||||
if dn.Priority < 1 {
|
||||
return errors.New(ctx, errors.InvalidParameter, caller, "invalid priority value")
|
||||
}
|
||||
if dn.Name == "" {
|
||||
return errors.New(ctx, errors.InvalidParameter, caller, "missing dns name")
|
||||
}
|
||||
|
||||
@@ -18,14 +18,13 @@ type IpAddress struct {
|
||||
tableName string `gorm:"-"`
|
||||
}
|
||||
|
||||
func NewIpAddress(ctx context.Context, hostId string, priority uint32, address string) (*IpAddress, error) {
|
||||
func NewIpAddress(ctx context.Context, hostId string, address string) (*IpAddress, error) {
|
||||
const op = "host.NewIpAddress"
|
||||
|
||||
ia := &IpAddress{
|
||||
IpAddress: &store.IpAddress{
|
||||
HostId: hostId,
|
||||
Address: address,
|
||||
Priority: priority,
|
||||
HostId: hostId,
|
||||
Address: address,
|
||||
},
|
||||
}
|
||||
if err := ia.validate(ctx, op); err != nil {
|
||||
@@ -39,9 +38,6 @@ func (ia *IpAddress) validate(ctx context.Context, caller errors.Op) error {
|
||||
if ia.HostId == "" {
|
||||
return errors.New(ctx, errors.InvalidParameter, caller, "missing host id")
|
||||
}
|
||||
if ia.Priority < 1 {
|
||||
return errors.New(ctx, errors.InvalidParameter, caller, "invalid priority value")
|
||||
}
|
||||
if ia.Address == "" {
|
||||
return errors.New(ctx, errors.InvalidParameter, caller, "missing ip address")
|
||||
}
|
||||
|
||||
@@ -2,13 +2,10 @@ package plugin
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/hashicorp/boundary/internal/db/timestamp"
|
||||
"github.com/hashicorp/boundary/internal/errors"
|
||||
"github.com/hashicorp/boundary/internal/host/plugin/store"
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
@@ -101,7 +98,6 @@ type hostAgg struct {
|
||||
func (agg *hostAgg) toHost(ctx context.Context) (*Host, error) {
|
||||
const op = "plugin.(hostAgg).toHost"
|
||||
const aggregateDelimiter = "|"
|
||||
const priorityDelimiter = "="
|
||||
h := allocHost()
|
||||
h.PublicId = agg.PublicId
|
||||
h.CatalogId = agg.CatalogId
|
||||
@@ -112,64 +108,14 @@ func (agg *hostAgg) toHost(ctx context.Context) (*Host, error) {
|
||||
h.CreateTime = agg.CreateTime
|
||||
h.UpdateTime = agg.UpdateTime
|
||||
|
||||
// This function is used to protect against someone messing with the order
|
||||
// in the DB by doing some validation
|
||||
prioritySortFunc := func(in []string) error {
|
||||
var sortErr error
|
||||
sort.Slice(in, func(i, j int) bool {
|
||||
ini := strings.Split(in[i], priorityDelimiter)
|
||||
if len(ini) != 2 {
|
||||
sortErr = errors.New(ctx, errors.NotSpecificIntegrity, op, fmt.Sprintf("value %s had unexpected fields", in[i]))
|
||||
return false
|
||||
}
|
||||
inj := strings.Split(in[j], priorityDelimiter)
|
||||
if len(inj) != 2 {
|
||||
sortErr = errors.New(ctx, errors.NotSpecificIntegrity, op, fmt.Sprintf("value %s had unexpected fields", in[j]))
|
||||
return false
|
||||
}
|
||||
indexi, err := strconv.Atoi(ini[0])
|
||||
if err != nil {
|
||||
sortErr = errors.Wrap(ctx, err, op)
|
||||
return false
|
||||
}
|
||||
indexj, err := strconv.Atoi(inj[0])
|
||||
if err != nil {
|
||||
sortErr = errors.Wrap(ctx, err, op)
|
||||
return false
|
||||
}
|
||||
return indexi < indexj
|
||||
})
|
||||
return sortErr
|
||||
}
|
||||
|
||||
if agg.IpAddresses != "" {
|
||||
ips := strings.Split(agg.IpAddresses, aggregateDelimiter)
|
||||
if len(ips) > 0 {
|
||||
if err := prioritySortFunc(ips); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for i, ip := range ips {
|
||||
// At this point they're in the correct order, but we still
|
||||
// have to strip off the priority
|
||||
ips[i] = strings.Split(ip, priorityDelimiter)[1]
|
||||
}
|
||||
h.IpAddresses = ips
|
||||
}
|
||||
h.IpAddresses = strings.Split(agg.IpAddresses, aggregateDelimiter)
|
||||
sort.Strings(h.IpAddresses)
|
||||
}
|
||||
|
||||
if agg.DnsNames != "" {
|
||||
names := strings.Split(agg.DnsNames, aggregateDelimiter)
|
||||
if len(names) > 0 {
|
||||
if err := prioritySortFunc(names); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for i, name := range names {
|
||||
// At this point they're in the correct order, but we still
|
||||
// have to strip off the priority
|
||||
names[i] = strings.Split(name, priorityDelimiter)[1]
|
||||
}
|
||||
h.DnsNames = names
|
||||
}
|
||||
h.DnsNames = strings.Split(agg.DnsNames, aggregateDelimiter)
|
||||
sort.Strings(h.DnsNames)
|
||||
}
|
||||
|
||||
return h, nil
|
||||
|
||||
@@ -24,9 +24,8 @@ func TestHostDnsName_Create(t *testing.T) {
|
||||
host1 := testHost(t, conn, cat.GetPublicId(), "external")
|
||||
|
||||
type args struct {
|
||||
hostId string
|
||||
name string
|
||||
priority uint32
|
||||
hostId string
|
||||
name string
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
@@ -40,52 +39,31 @@ func TestHostDnsName_Create(t *testing.T) {
|
||||
{
|
||||
name: "blank-host-id-validate",
|
||||
args: args{
|
||||
hostId: "",
|
||||
name: "foo.bar.com",
|
||||
priority: 1,
|
||||
hostId: "",
|
||||
name: "foo.bar.com",
|
||||
},
|
||||
wantNewErr: true,
|
||||
},
|
||||
{
|
||||
name: "blank-name-validate",
|
||||
args: args{
|
||||
hostId: host1.GetPublicId(),
|
||||
name: "",
|
||||
priority: 1,
|
||||
},
|
||||
wantNewErr: true,
|
||||
},
|
||||
{
|
||||
name: "blank-priority-validate",
|
||||
args: args{
|
||||
hostId: host1.GetPublicId(),
|
||||
name: "foo.bar.com",
|
||||
name: "",
|
||||
},
|
||||
wantNewErr: true,
|
||||
},
|
||||
{
|
||||
name: "blank-host-id-db",
|
||||
args: args{
|
||||
name: "foo.bar.com",
|
||||
priority: 1,
|
||||
name: "foo.bar.com",
|
||||
},
|
||||
skipNewFunc: true,
|
||||
wantDbErr: true,
|
||||
},
|
||||
{
|
||||
name: "blank-name-db",
|
||||
args: args{
|
||||
hostId: host1.GetPublicId(),
|
||||
priority: 1,
|
||||
},
|
||||
skipNewFunc: true,
|
||||
wantDbErr: true,
|
||||
},
|
||||
{
|
||||
name: "blank-priority-db",
|
||||
args: args{
|
||||
hostId: host1.GetPublicId(),
|
||||
name: "foo.bar.com",
|
||||
},
|
||||
skipNewFunc: true,
|
||||
wantDbErr: true,
|
||||
@@ -93,46 +71,26 @@ func TestHostDnsName_Create(t *testing.T) {
|
||||
{
|
||||
name: "valid",
|
||||
args: args{
|
||||
hostId: host1.GetPublicId(),
|
||||
name: "foo.bar.com",
|
||||
priority: 1,
|
||||
hostId: host1.GetPublicId(),
|
||||
name: "foo.bar.com",
|
||||
},
|
||||
want: &host.DnsName{
|
||||
DnsName: &store.DnsName{
|
||||
HostId: host1.GetPublicId(),
|
||||
Name: "foo.bar.com",
|
||||
Priority: 1,
|
||||
HostId: host1.GetPublicId(),
|
||||
Name: "foo.bar.com",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "duplicate-name",
|
||||
args: args{
|
||||
hostId: host1.GetPublicId(),
|
||||
name: "foo.bar.com",
|
||||
priority: 2,
|
||||
hostId: host1.GetPublicId(),
|
||||
name: "foo.bar.com",
|
||||
},
|
||||
want: &host.DnsName{
|
||||
DnsName: &store.DnsName{
|
||||
HostId: host1.GetPublicId(),
|
||||
Name: "foo.bar.com",
|
||||
Priority: 2,
|
||||
},
|
||||
},
|
||||
wantDbErr: true,
|
||||
},
|
||||
{
|
||||
name: "duplicate-priority",
|
||||
args: args{
|
||||
hostId: host1.GetPublicId(),
|
||||
name: "baz.bar.com",
|
||||
priority: 1,
|
||||
},
|
||||
want: &host.DnsName{
|
||||
DnsName: &store.DnsName{
|
||||
HostId: host1.GetPublicId(),
|
||||
Name: "baz.bar.com",
|
||||
Priority: 1,
|
||||
HostId: host1.GetPublicId(),
|
||||
Name: "foo.bar.com",
|
||||
},
|
||||
},
|
||||
wantDbErr: true,
|
||||
@@ -140,15 +98,13 @@ func TestHostDnsName_Create(t *testing.T) {
|
||||
{
|
||||
name: "valid-second",
|
||||
args: args{
|
||||
hostId: host1.GetPublicId(),
|
||||
name: "baz.bar.com",
|
||||
priority: 2,
|
||||
hostId: host1.GetPublicId(),
|
||||
name: "baz.bar.com",
|
||||
},
|
||||
want: &host.DnsName{
|
||||
DnsName: &store.DnsName{
|
||||
HostId: host1.GetPublicId(),
|
||||
Name: "baz.bar.com",
|
||||
Priority: 2,
|
||||
HostId: host1.GetPublicId(),
|
||||
Name: "baz.bar.com",
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -161,7 +117,7 @@ func TestHostDnsName_Create(t *testing.T) {
|
||||
var got *host.DnsName
|
||||
var err error
|
||||
if !tt.skipNewFunc {
|
||||
got, err = host.NewDnsName(ctx, tt.args.hostId, tt.args.priority, tt.args.name)
|
||||
got, err = host.NewDnsName(ctx, tt.args.hostId, tt.args.name)
|
||||
if tt.wantNewErr {
|
||||
require.Error(err)
|
||||
return
|
||||
@@ -171,9 +127,8 @@ func TestHostDnsName_Create(t *testing.T) {
|
||||
} else {
|
||||
got = &host.DnsName{
|
||||
DnsName: &store.DnsName{
|
||||
HostId: tt.args.hostId,
|
||||
Name: tt.args.name,
|
||||
Priority: tt.args.priority,
|
||||
HostId: tt.args.hostId,
|
||||
Name: tt.args.name,
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -200,9 +155,8 @@ func TestHostIpAddress_Create(t *testing.T) {
|
||||
host1 := testHost(t, conn, cat.GetPublicId(), "external")
|
||||
|
||||
type args struct {
|
||||
hostId string
|
||||
address string
|
||||
priority uint32
|
||||
hostId string
|
||||
address string
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
@@ -216,26 +170,16 @@ func TestHostIpAddress_Create(t *testing.T) {
|
||||
{
|
||||
name: "blank-host-id-validate",
|
||||
args: args{
|
||||
hostId: "",
|
||||
address: "1.2.3.4",
|
||||
priority: 1,
|
||||
hostId: "",
|
||||
address: "1.2.3.4",
|
||||
},
|
||||
wantNewErr: true,
|
||||
},
|
||||
{
|
||||
name: "blank-name-validate",
|
||||
args: args{
|
||||
hostId: host1.GetPublicId(),
|
||||
address: "",
|
||||
priority: 1,
|
||||
},
|
||||
wantNewErr: true,
|
||||
},
|
||||
{
|
||||
name: "blank-priority-validate",
|
||||
args: args{
|
||||
hostId: host1.GetPublicId(),
|
||||
address: "1.2.3.4",
|
||||
address: "",
|
||||
},
|
||||
wantNewErr: true,
|
||||
},
|
||||
@@ -250,8 +194,7 @@ func TestHostIpAddress_Create(t *testing.T) {
|
||||
{
|
||||
name: "blank-host-id-db",
|
||||
args: args{
|
||||
address: "1.2.3.4",
|
||||
priority: 1,
|
||||
address: "1.2.3.4",
|
||||
},
|
||||
skipNewFunc: true,
|
||||
wantDbErr: true,
|
||||
@@ -259,17 +202,7 @@ func TestHostIpAddress_Create(t *testing.T) {
|
||||
{
|
||||
name: "blank-address-db",
|
||||
args: args{
|
||||
hostId: host1.GetPublicId(),
|
||||
priority: 1,
|
||||
},
|
||||
skipNewFunc: true,
|
||||
wantDbErr: true,
|
||||
},
|
||||
{
|
||||
name: "blank-priority-db",
|
||||
args: args{
|
||||
hostId: host1.GetPublicId(),
|
||||
address: "1.2.3.4",
|
||||
hostId: host1.GetPublicId(),
|
||||
},
|
||||
skipNewFunc: true,
|
||||
wantDbErr: true,
|
||||
@@ -277,46 +210,26 @@ func TestHostIpAddress_Create(t *testing.T) {
|
||||
{
|
||||
name: "valid",
|
||||
args: args{
|
||||
hostId: host1.GetPublicId(),
|
||||
address: "1.2.3.4",
|
||||
priority: 1,
|
||||
hostId: host1.GetPublicId(),
|
||||
address: "1.2.3.4",
|
||||
},
|
||||
want: &host.IpAddress{
|
||||
IpAddress: &store.IpAddress{
|
||||
HostId: host1.GetPublicId(),
|
||||
Address: "1.2.3.4",
|
||||
Priority: 1,
|
||||
HostId: host1.GetPublicId(),
|
||||
Address: "1.2.3.4",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "duplicate-name",
|
||||
args: args{
|
||||
hostId: host1.GetPublicId(),
|
||||
address: "1.2.3.4",
|
||||
priority: 2,
|
||||
hostId: host1.GetPublicId(),
|
||||
address: "1.2.3.4",
|
||||
},
|
||||
want: &host.IpAddress{
|
||||
IpAddress: &store.IpAddress{
|
||||
HostId: host1.GetPublicId(),
|
||||
Address: "1.2.3.4",
|
||||
Priority: 2,
|
||||
},
|
||||
},
|
||||
wantDbErr: true,
|
||||
},
|
||||
{
|
||||
name: "duplicate-priority",
|
||||
args: args{
|
||||
hostId: host1.GetPublicId(),
|
||||
address: "2.3.4.5",
|
||||
priority: 1,
|
||||
},
|
||||
want: &host.IpAddress{
|
||||
IpAddress: &store.IpAddress{
|
||||
HostId: host1.GetPublicId(),
|
||||
Address: "2.3.4.5",
|
||||
Priority: 1,
|
||||
HostId: host1.GetPublicId(),
|
||||
Address: "1.2.3.4",
|
||||
},
|
||||
},
|
||||
wantDbErr: true,
|
||||
@@ -324,15 +237,13 @@ func TestHostIpAddress_Create(t *testing.T) {
|
||||
{
|
||||
name: "valid-second",
|
||||
args: args{
|
||||
hostId: host1.GetPublicId(),
|
||||
address: "2.3.4.5",
|
||||
priority: 2,
|
||||
hostId: host1.GetPublicId(),
|
||||
address: "2.3.4.5",
|
||||
},
|
||||
want: &host.IpAddress{
|
||||
IpAddress: &store.IpAddress{
|
||||
HostId: host1.GetPublicId(),
|
||||
Address: "2.3.4.5",
|
||||
Priority: 2,
|
||||
HostId: host1.GetPublicId(),
|
||||
Address: "2.3.4.5",
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -345,7 +256,7 @@ func TestHostIpAddress_Create(t *testing.T) {
|
||||
var got *host.IpAddress
|
||||
var err error
|
||||
if !tt.skipNewFunc {
|
||||
got, err = host.NewIpAddress(ctx, tt.args.hostId, tt.args.priority, tt.args.address)
|
||||
got, err = host.NewIpAddress(ctx, tt.args.hostId, tt.args.address)
|
||||
if tt.wantNewErr {
|
||||
require.Error(err)
|
||||
return
|
||||
@@ -355,9 +266,8 @@ func TestHostIpAddress_Create(t *testing.T) {
|
||||
} else {
|
||||
got = &host.IpAddress{
|
||||
IpAddress: &store.IpAddress{
|
||||
HostId: tt.args.hostId,
|
||||
Address: tt.args.address,
|
||||
Priority: tt.args.priority,
|
||||
HostId: tt.args.hostId,
|
||||
Address: tt.args.address,
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -382,14 +292,13 @@ func TestHostDnsName_Delete(t *testing.T) {
|
||||
plg := hostplugin.TestPlugin(t, conn, "test")
|
||||
cat := TestCatalog(t, conn, prj.PublicId, plg.GetPublicId())
|
||||
host1 := testHost(t, conn, cat.GetPublicId(), "external")
|
||||
addr1, err := host.NewDnsName(ctx, host1.GetPublicId(), 1, "addr1.foo.com")
|
||||
addr1, err := host.NewDnsName(ctx, host1.GetPublicId(), "addr1.foo.com")
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, w.Create(ctx, addr1))
|
||||
|
||||
type args struct {
|
||||
hostId string
|
||||
name string
|
||||
priority uint32
|
||||
hostId string
|
||||
name string
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
@@ -401,33 +310,15 @@ func TestHostDnsName_Delete(t *testing.T) {
|
||||
{
|
||||
name: "wrong_host_id",
|
||||
args: args{
|
||||
hostId: "something",
|
||||
name: addr1.GetName(),
|
||||
priority: 1,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "missing_priority",
|
||||
args: args{
|
||||
hostId: addr1.GetHostId(),
|
||||
hostId: "something",
|
||||
name: addr1.GetName(),
|
||||
},
|
||||
wantError: true,
|
||||
},
|
||||
{
|
||||
name: "wrong_priority",
|
||||
args: args{
|
||||
hostId: addr1.GetHostId(),
|
||||
name: addr1.GetName(),
|
||||
priority: 2,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "valid",
|
||||
args: args{
|
||||
hostId: addr1.GetHostId(),
|
||||
name: addr1.GetName(),
|
||||
priority: 1,
|
||||
hostId: addr1.GetHostId(),
|
||||
name: addr1.GetName(),
|
||||
},
|
||||
wantDelete: true,
|
||||
},
|
||||
@@ -438,9 +329,8 @@ func TestHostDnsName_Delete(t *testing.T) {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
got := &host.DnsName{
|
||||
DnsName: &store.DnsName{
|
||||
HostId: tt.args.hostId,
|
||||
Name: tt.args.name,
|
||||
Priority: tt.args.priority,
|
||||
HostId: tt.args.hostId,
|
||||
Name: tt.args.name,
|
||||
},
|
||||
}
|
||||
require.NoError(t, err)
|
||||
@@ -469,14 +359,13 @@ func TestHostIpAddress_Delete(t *testing.T) {
|
||||
plg := hostplugin.TestPlugin(t, conn, "test")
|
||||
cat := TestCatalog(t, conn, prj.PublicId, plg.GetPublicId())
|
||||
host1 := testHost(t, conn, cat.GetPublicId(), "external")
|
||||
addr1, err := host.NewIpAddress(ctx, host1.GetPublicId(), 1, "1.2.3.4")
|
||||
addr1, err := host.NewIpAddress(ctx, host1.GetPublicId(), "1.2.3.4")
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, w.Create(ctx, addr1))
|
||||
|
||||
type args struct {
|
||||
hostId string
|
||||
address string
|
||||
priority uint32
|
||||
hostId string
|
||||
address string
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
@@ -488,33 +377,15 @@ func TestHostIpAddress_Delete(t *testing.T) {
|
||||
{
|
||||
name: "wrong_host_id",
|
||||
args: args{
|
||||
hostId: "something",
|
||||
address: addr1.GetAddress(),
|
||||
priority: 1,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "missing_priority",
|
||||
args: args{
|
||||
hostId: addr1.GetHostId(),
|
||||
hostId: "something",
|
||||
address: addr1.GetAddress(),
|
||||
},
|
||||
wantError: true,
|
||||
},
|
||||
{
|
||||
name: "wrong_priority",
|
||||
args: args{
|
||||
hostId: addr1.GetHostId(),
|
||||
address: addr1.GetAddress(),
|
||||
priority: 2,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "valid",
|
||||
args: args{
|
||||
hostId: addr1.GetHostId(),
|
||||
address: addr1.GetAddress(),
|
||||
priority: 1,
|
||||
hostId: addr1.GetHostId(),
|
||||
address: addr1.GetAddress(),
|
||||
},
|
||||
wantDelete: true,
|
||||
},
|
||||
@@ -525,9 +396,8 @@ func TestHostIpAddress_Delete(t *testing.T) {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
got := &host.IpAddress{
|
||||
IpAddress: &store.IpAddress{
|
||||
HostId: tt.args.hostId,
|
||||
Address: tt.args.address,
|
||||
Priority: tt.args.priority,
|
||||
HostId: tt.args.hostId,
|
||||
Address: tt.args.address,
|
||||
},
|
||||
}
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -83,8 +83,8 @@ func (r *Repository) UpsertHosts(
|
||||
if len(h.GetIpAddresses()) > 0 {
|
||||
sort.Strings(h.IpAddresses)
|
||||
ipAddresses = make([]interface{}, 0, len(h.GetIpAddresses()))
|
||||
for i, a := range h.GetIpAddresses() {
|
||||
obj, err := host.NewIpAddress(ctx, h.PublicId, uint32(i+1), a)
|
||||
for _, a := range h.GetIpAddresses() {
|
||||
obj, err := host.NewIpAddress(ctx, h.PublicId, a)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(ctx, err, op)
|
||||
}
|
||||
@@ -96,8 +96,8 @@ func (r *Repository) UpsertHosts(
|
||||
if len(h.GetDnsNames()) > 0 {
|
||||
sort.Strings(h.DnsNames)
|
||||
dnsNames = make([]interface{}, 0, len(h.GetDnsNames()))
|
||||
for i, n := range h.GetDnsNames() {
|
||||
obj, err := host.NewDnsName(ctx, h.PublicId, uint32(i+1), n)
|
||||
for _, n := range h.GetDnsNames() {
|
||||
obj, err := host.NewDnsName(ctx, h.PublicId, n)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(ctx, err, op)
|
||||
}
|
||||
|
||||
@@ -276,9 +276,7 @@ type IpAddress struct {
|
||||
// @inject_tag: `gorm:"primary_key"`
|
||||
HostId string `protobuf:"bytes,1,opt,name=host_id,json=hostId,proto3" json:"host_id,omitempty" gorm:"primary_key"`
|
||||
// @inject_tag: `gorm:"primary_key"`
|
||||
Priority uint32 `protobuf:"varint,2,opt,name=priority,proto3" json:"priority,omitempty" gorm:"primary_key"`
|
||||
// @inject_tag: `gorm:"not_null`
|
||||
Address string `protobuf:"bytes,3,opt,name=address,proto3" json:"address,omitempty"`
|
||||
Address string `protobuf:"bytes,2,opt,name=address,proto3" json:"address,omitempty" gorm:"primary_key"`
|
||||
}
|
||||
|
||||
func (x *IpAddress) Reset() {
|
||||
@@ -320,13 +318,6 @@ func (x *IpAddress) GetHostId() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *IpAddress) GetPriority() uint32 {
|
||||
if x != nil {
|
||||
return x.Priority
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (x *IpAddress) GetAddress() string {
|
||||
if x != nil {
|
||||
return x.Address
|
||||
@@ -342,9 +333,7 @@ type DnsName struct {
|
||||
// @inject_tag: `gorm:"primary_key"`
|
||||
HostId string `protobuf:"bytes,1,opt,name=host_id,json=hostId,proto3" json:"host_id,omitempty" gorm:"primary_key"`
|
||||
// @inject_tag: `gorm:"primary_key"`
|
||||
Priority uint32 `protobuf:"varint,2,opt,name=priority,proto3" json:"priority,omitempty" gorm:"primary_key"`
|
||||
// @inject_tag: `gorm:"not_null`
|
||||
Name string `protobuf:"bytes,3,opt,name=name,proto3" json:"name,omitempty"`
|
||||
Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty" gorm:"primary_key"`
|
||||
}
|
||||
|
||||
func (x *DnsName) Reset() {
|
||||
@@ -386,13 +375,6 @@ func (x *DnsName) GetHostId() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *DnsName) GetPriority() uint32 {
|
||||
if x != nil {
|
||||
return x.Priority
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (x *DnsName) GetName() string {
|
||||
if x != nil {
|
||||
return x.Name
|
||||
@@ -427,22 +409,19 @@ var file_controller_storage_host_store_v1_host_proto_rawDesc = []byte{
|
||||
0x0a, 0x08, 0x70, 0x72, 0x69, 0x6f, 0x72, 0x69, 0x74, 0x79, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0d,
|
||||
0x52, 0x08, 0x70, 0x72, 0x69, 0x6f, 0x72, 0x69, 0x74, 0x79, 0x12, 0x1c, 0x0a, 0x09, 0x63, 0x6f,
|
||||
0x6e, 0x64, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x63,
|
||||
0x6f, 0x6e, 0x64, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x22, 0x5a, 0x0a, 0x09, 0x49, 0x70, 0x41, 0x64,
|
||||
0x6f, 0x6e, 0x64, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x22, 0x3e, 0x0a, 0x09, 0x49, 0x70, 0x41, 0x64,
|
||||
0x64, 0x72, 0x65, 0x73, 0x73, 0x12, 0x17, 0x0a, 0x07, 0x68, 0x6f, 0x73, 0x74, 0x5f, 0x69, 0x64,
|
||||
0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x68, 0x6f, 0x73, 0x74, 0x49, 0x64, 0x12, 0x1a,
|
||||
0x0a, 0x08, 0x70, 0x72, 0x69, 0x6f, 0x72, 0x69, 0x74, 0x79, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0d,
|
||||
0x52, 0x08, 0x70, 0x72, 0x69, 0x6f, 0x72, 0x69, 0x74, 0x79, 0x12, 0x18, 0x0a, 0x07, 0x61, 0x64,
|
||||
0x64, 0x72, 0x65, 0x73, 0x73, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x61, 0x64, 0x64,
|
||||
0x72, 0x65, 0x73, 0x73, 0x22, 0x52, 0x0a, 0x07, 0x44, 0x6e, 0x73, 0x4e, 0x61, 0x6d, 0x65, 0x12,
|
||||
0x17, 0x0a, 0x07, 0x68, 0x6f, 0x73, 0x74, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09,
|
||||
0x52, 0x06, 0x68, 0x6f, 0x73, 0x74, 0x49, 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x70, 0x72, 0x69, 0x6f,
|
||||
0x72, 0x69, 0x74, 0x79, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x08, 0x70, 0x72, 0x69, 0x6f,
|
||||
0x72, 0x69, 0x74, 0x79, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x03, 0x20, 0x01,
|
||||
0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x42, 0x39, 0x5a, 0x37, 0x67, 0x69, 0x74, 0x68,
|
||||
0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x68, 0x61, 0x73, 0x68, 0x69, 0x63, 0x6f, 0x72, 0x70,
|
||||
0x2f, 0x62, 0x6f, 0x75, 0x6e, 0x64, 0x61, 0x72, 0x79, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e,
|
||||
0x61, 0x6c, 0x2f, 0x68, 0x6f, 0x73, 0x74, 0x2f, 0x73, 0x74, 0x6f, 0x72, 0x65, 0x3b, 0x73, 0x74,
|
||||
0x6f, 0x72, 0x65, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
||||
0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x68, 0x6f, 0x73, 0x74, 0x49, 0x64, 0x12, 0x18,
|
||||
0x0a, 0x07, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52,
|
||||
0x07, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x22, 0x36, 0x0a, 0x07, 0x44, 0x6e, 0x73, 0x4e,
|
||||
0x61, 0x6d, 0x65, 0x12, 0x17, 0x0a, 0x07, 0x68, 0x6f, 0x73, 0x74, 0x5f, 0x69, 0x64, 0x18, 0x01,
|
||||
0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x68, 0x6f, 0x73, 0x74, 0x49, 0x64, 0x12, 0x12, 0x0a, 0x04,
|
||||
0x6e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65,
|
||||
0x42, 0x39, 0x5a, 0x37, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x68,
|
||||
0x61, 0x73, 0x68, 0x69, 0x63, 0x6f, 0x72, 0x70, 0x2f, 0x62, 0x6f, 0x75, 0x6e, 0x64, 0x61, 0x72,
|
||||
0x79, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2f, 0x68, 0x6f, 0x73, 0x74, 0x2f,
|
||||
0x73, 0x74, 0x6f, 0x72, 0x65, 0x3b, 0x73, 0x74, 0x6f, 0x72, 0x65, 0x62, 0x06, 0x70, 0x72, 0x6f,
|
||||
0x74, 0x6f, 0x33,
|
||||
}
|
||||
|
||||
var (
|
||||
|
||||
@@ -53,10 +53,7 @@ message IpAddress {
|
||||
string host_id = 1;
|
||||
|
||||
// @inject_tag: `gorm:"primary_key"`
|
||||
uint32 priority = 2;
|
||||
|
||||
// @inject_tag: `gorm:"not_null`
|
||||
string address = 3;
|
||||
string address = 2;
|
||||
}
|
||||
|
||||
message DnsName {
|
||||
@@ -64,8 +61,5 @@ message DnsName {
|
||||
string host_id = 1;
|
||||
|
||||
// @inject_tag: `gorm:"primary_key"`
|
||||
uint32 priority = 2;
|
||||
|
||||
// @inject_tag: `gorm:"not_null`
|
||||
string name = 3;
|
||||
string name = 2;
|
||||
}
|
||||
Reference in new issue
Block a user