Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add deleted property to image #172

Merged
merged 2 commits into from
Jun 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions hcloud/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,19 @@ type Image struct {
Protection ImageProtection
Deprecated time.Time // The zero value denotes the image is not deprecated.
Labels map[string]string
Deleted time.Time
}

// IsDeprecated returns whether the image is deprecated.
func (image *Image) IsDeprecated() bool {
return !image.Deprecated.IsZero()
}

// IsDeleted returns whether the image is deleted.
func (image *Image) IsDeleted() bool {
return !image.Deleted.IsZero()
}

// ImageProtection represents the protection level of an image.
type ImageProtection struct {
Delete bool
Expand Down
1 change: 1 addition & 0 deletions hcloud/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ func ImageFromSchema(s schema.Image) *Image {
Delete: s.Protection.Delete,
},
Deprecated: s.Deprecated,
Deleted: s.Deleted,
}
if s.Name != nil {
i.Name = *s.Name
Expand Down
4 changes: 2 additions & 2 deletions hcloud/schema/firewall.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ type FirewallCreateRequest struct {
// FirewallResource defines the schema of a resource to apply the new Firewall on.
type FirewallResource struct {
Type string `json:"type"`
Server *FirewallResourceServer `json:"server"`
LabelSelector *FirewallResourceLabelSelector `json:"label_selector"`
Server *FirewallResourceServer `json:"server,omitempty"`
LabelSelector *FirewallResourceLabelSelector `json:"label_selector,omitempty"`
}

// FirewallResourceLabelSelector defines the schema of a LabelSelector to apply a Firewall on.
Expand Down
1 change: 1 addition & 0 deletions hcloud/schema/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type Image struct {
RapidDeploy bool `json:"rapid_deploy"`
Protection ImageProtection `json:"protection"`
Deprecated time.Time `json:"deprecated"`
Deleted time.Time `json:"deleted"`
Labels map[string]string `json:"labels"`
}

Expand Down
4 changes: 4 additions & 0 deletions hcloud/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -925,6 +925,7 @@ func TestImageFromSchema(t *testing.T) {
"delete": true
},
"deprecated": "2018-02-28T00:00:00+00:00",
"deleted": "2016-01-30T23:55:01+00:00",
"labels": {
"key": "value",
"key2": "value2"
Expand Down Expand Up @@ -961,6 +962,9 @@ func TestImageFromSchema(t *testing.T) {
if !image.Created.Equal(time.Date(2016, 1, 30, 23, 55, 1, 0, time.UTC)) {
t.Errorf("unexpected Created: %v", image.Created)
}
if !image.Deleted.Equal(time.Date(2016, 1, 30, 23, 55, 1, 0, time.UTC)) {
t.Errorf("unexpected Deleted: %v", image.Deleted)
}
if image.CreatedFrom == nil || image.CreatedFrom.ID != 1 || image.CreatedFrom.Name != "my-server1" {
t.Errorf("unexpected CreatedFrom: %v", image.CreatedFrom)
}
Expand Down