Rename root, api and sdk module paths (imports, go.mod, go_package, ldflags, build scripts, buf configs) and regenerate protobuf/gateway code with the project's pinned toolchain. Wire identifiers unchanged. api gets a local replace for sdk; root/api/sdk require v0.1.0. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
76 lines
1.6 KiB
Go
76 lines
1.6 KiB
Go
// Copyright IBM Corp. 2020, 2026
|
|
// SPDX-License-Identifier: BUSL-1.1
|
|
|
|
package host
|
|
|
|
import (
|
|
"context"
|
|
|
|
"repo.anhonesthost.net/CyberCoveLLC/threshold/internal/errors"
|
|
"repo.anhonesthost.net/CyberCoveLLC/threshold/internal/host/store"
|
|
"google.golang.org/protobuf/proto"
|
|
)
|
|
|
|
// NOTE: Tests for this are in the plugin subtype directory in host_address_test.go
|
|
|
|
const defaultDnsNameTableName = "host_dns_name"
|
|
|
|
type DnsName struct {
|
|
*store.DnsName
|
|
tableName string `gorm:"-"`
|
|
}
|
|
|
|
func NewDnsName(ctx context.Context, hostId string, name string) (*DnsName, error) {
|
|
const op = "host.NewDnsName"
|
|
dn := &DnsName{
|
|
DnsName: &store.DnsName{
|
|
HostId: hostId,
|
|
Name: name,
|
|
},
|
|
}
|
|
if err := dn.validate(ctx, op); err != nil {
|
|
return nil, err
|
|
}
|
|
return dn, nil
|
|
}
|
|
|
|
// validate the host dns name. On success, it will return nil.
|
|
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.Name == "" {
|
|
return errors.New(ctx, errors.InvalidParameter, caller, "missing dns name")
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// allocDnsName make an empty one in memory.
|
|
func allocDnsName() DnsName {
|
|
return DnsName{
|
|
DnsName: &store.DnsName{},
|
|
}
|
|
}
|
|
|
|
// Clone an DnsName
|
|
func (dn *DnsName) Clone() *DnsName {
|
|
cp := proto.Clone(dn.DnsName)
|
|
return &DnsName{
|
|
DnsName: cp.(*store.DnsName),
|
|
}
|
|
}
|
|
|
|
// TableName returns the table name.
|
|
func (dn *DnsName) TableName() string {
|
|
if dn.tableName != "" {
|
|
return dn.tableName
|
|
}
|
|
return defaultDnsNameTableName
|
|
}
|
|
|
|
// SetTableName sets the table name.
|
|
func (dn *DnsName) SetTableName(n string) {
|
|
dn.tableName = n
|
|
}
|