From 9caa08b635490615afe88651949e3fb41ea030ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20T=C3=B6lle?= Date: Thu, 12 Oct 2023 15:20:47 +0200 Subject: [PATCH] feat(iso): support deprecation info API (#331) See these changelog entries for the announcement: - https://docs.hetzner.cloud/changelog#2023-10-12-deprecation-info-for-isos - https://docs.hetzner.cloud/changelog#2023-10-12-field-deprecated-on-isos-is-now-deprecated (cherry picked from commit b3a36214b21ab1c5add94c2b1896a995342757b6) --- hcloud/iso.go | 9 +++------ hcloud/iso_test.go | 2 +- hcloud/schema.go | 3 +++ hcloud/schema/iso.go | 1 + 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/hcloud/iso.go b/hcloud/iso.go index a858620b..b4a4855f 100644 --- a/hcloud/iso.go +++ b/hcloud/iso.go @@ -17,12 +17,9 @@ type ISO struct { Description string Type ISOType Architecture *Architecture - Deprecated time.Time -} - -// IsDeprecated returns true if the ISO is deprecated. -func (iso *ISO) IsDeprecated() bool { - return !iso.Deprecated.IsZero() + // Deprecated: Use [ISO.Deprecation] instead. + Deprecated time.Time + DeprecatableResource } // ISOType specifies the type of an ISO image. diff --git a/hcloud/iso_test.go b/hcloud/iso_test.go index 1d010a7c..76e279fd 100644 --- a/hcloud/iso_test.go +++ b/hcloud/iso_test.go @@ -20,7 +20,7 @@ func TestISOIsDeprecated(t *testing.T) { t.Run("deprecated", func(t *testing.T) { iso := &ISO{ - Deprecated: time.Now(), + DeprecatableResource: DeprecatableResource{Deprecation: &DeprecationInfo{Announced: time.Now()}}, } if !iso.IsDeprecated() { t.Errorf("unexpected value for IsDeprecated: %v", iso.IsDeprecated()) diff --git a/hcloud/schema.go b/hcloud/schema.go index f4a93667..09c03864 100644 --- a/hcloud/schema.go +++ b/hcloud/schema.go @@ -124,6 +124,9 @@ func ISOFromSchema(s schema.ISO) *ISO { Description: s.Description, Type: ISOType(s.Type), Deprecated: s.Deprecated, + DeprecatableResource: DeprecatableResource{ + DeprecationFromSchema(s.Deprecation), + }, } if s.Architecture != nil { iso.Architecture = Ptr(Architecture(*s.Architecture)) diff --git a/hcloud/schema/iso.go b/hcloud/schema/iso.go index dfcc4e34..e1f38c10 100644 --- a/hcloud/schema/iso.go +++ b/hcloud/schema/iso.go @@ -10,6 +10,7 @@ type ISO struct { Type string `json:"type"` Architecture *string `json:"architecture"` Deprecated time.Time `json:"deprecated"` + DeprecatableResource } // ISOGetResponse defines the schema of the response when retrieving a single ISO.