From b5fea38f5d9d62c88af470ba69195a73ee075f09 Mon Sep 17 00:00:00 2001 From: phm07 <22707808+phm07@users.noreply.github.com> Date: Tue, 5 Mar 2024 12:23:19 +0100 Subject: [PATCH] fix: primary ip assignee id not mapped to nil (#395) See https://github.com/hetznercloud/cli/issues/701 Co-authored-by: pauhull <22707808+pauhull@users.noreply.github.com> --- hcloud/schema/primary_ip.go | 2 +- hcloud/schema_gen.go | 8 ++++++++ hcloud/zz_schema.go | 8 ++++++-- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/hcloud/schema/primary_ip.go b/hcloud/schema/primary_ip.go index b685c386..1901ce80 100644 --- a/hcloud/schema/primary_ip.go +++ b/hcloud/schema/primary_ip.go @@ -11,7 +11,7 @@ type PrimaryIP struct { Type string `json:"type"` Protection PrimaryIPProtection `json:"protection"` DNSPtr []PrimaryIPDNSPTR `json:"dns_ptr"` - AssigneeID int64 `json:"assignee_id"` + AssigneeID *int64 `json:"assignee_id"` AssigneeType string `json:"assignee_type"` AutoDelete bool `json:"auto_delete"` Blocked bool `json:"blocked"` diff --git a/hcloud/schema_gen.go b/hcloud/schema_gen.go index 5cb347b5..ea002cce 100644 --- a/hcloud/schema_gen.go +++ b/hcloud/schema_gen.go @@ -105,6 +105,7 @@ type converter interface { PrimaryIPFromSchema(schema.PrimaryIP) *PrimaryIP // goverter:map . IP | primaryIPToIPString + // goverter:map AssigneeID | mapZeroInt64ToNil SchemaFromPrimaryIP(*PrimaryIP) schema.PrimaryIP ISOFromSchema(schema.ISO) *ISO @@ -874,6 +875,13 @@ func stringPtrFromNetworkZone(z NetworkZone) *string { return mapEmptyStringToNil(string(z)) } +func mapZeroInt64ToNil(i int64) *int64 { + if i == 0 { + return nil + } + return &i +} + func mapZeroUint64ToNil(i uint64) *uint64 { if i == 0 { return nil diff --git a/hcloud/zz_schema.go b/hcloud/zz_schema.go index f546a4e3..7c1ea044 100755 --- a/hcloud/zz_schema.go +++ b/hcloud/zz_schema.go @@ -471,7 +471,11 @@ func (c *converterImpl) PrimaryIPFromSchema(source schema.PrimaryIP) *PrimaryIP hcloudPrimaryIP.Type = PrimaryIPType(source.Type) hcloudPrimaryIP.Protection = c.schemaPrimaryIPProtectionToHcloudPrimaryIPProtection(source.Protection) hcloudPrimaryIP.DNSPtr = mapFromPrimaryIPDNSPtrSchema(source.DNSPtr) - hcloudPrimaryIP.AssigneeID = source.AssigneeID + var xint64 int64 + if source.AssigneeID != nil { + xint64 = *source.AssigneeID + } + hcloudPrimaryIP.AssigneeID = xint64 hcloudPrimaryIP.AssigneeType = source.AssigneeType hcloudPrimaryIP.AutoDelete = source.AutoDelete hcloudPrimaryIP.Blocked = source.Blocked @@ -1042,7 +1046,7 @@ func (c *converterImpl) SchemaFromPrimaryIP(source *PrimaryIP) schema.PrimaryIP schemaPrimaryIP2.Type = string((*source).Type) schemaPrimaryIP2.Protection = c.hcloudPrimaryIPProtectionToSchemaPrimaryIPProtection((*source).Protection) schemaPrimaryIP2.DNSPtr = primaryIPDNSPtrSchemaFromMap((*source).DNSPtr) - schemaPrimaryIP2.AssigneeID = (*source).AssigneeID + schemaPrimaryIP2.AssigneeID = mapZeroInt64ToNil((*source).AssigneeID) schemaPrimaryIP2.AssigneeType = (*source).AssigneeType schemaPrimaryIP2.AutoDelete = (*source).AutoDelete schemaPrimaryIP2.Blocked = (*source).Blocked