Repository: hetznercloud/hcloud-go
Pull request #123 (2019-10-25 10:46:42)

Add Created field to SSHKey


Patch:
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 688711e..c575bfd 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -6,7 +6,7 @@ jobs:
     runs-on: ubuntu-latest
     strategy:
       matrix:
-        go-version: [1.9, '1.10', 1.11, 1.12, 1.13]
+        go-version: [1.12, 1.13]
     steps:
     - name: Set up Go ${{ matrix.go-version }}
       uses: actions/setup-go@v1
diff --git a/CHANGES.md b/CHANGES.md
index 4e3cf85..b49dd1a 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -1,5 +1,9 @@
 # Changes
 
+## master
+
+* Add `Created` field to `SSHKey`
+
 ## v1.16.0
 
 * Make IP range optional when adding a subnet to a network
diff --git a/hcloud/schema.go b/hcloud/schema.go
index 3cf885b..40f55ed 100644
--- a/hcloud/schema.go
+++ b/hcloud/schema.go
@@ -256,6 +256,7 @@ func SSHKeyFromSchema(s schema.SSHKey) *SSHKey {
 		Name:        s.Name,
 		Fingerprint: s.Fingerprint,
 		PublicKey:   s.PublicKey,
+		Created:     s.Created,
 	}
 	sshKey.Labels = map[string]string{}
 	for key, value := range s.Labels {
diff --git a/hcloud/schema/ssh_key.go b/hcloud/schema/ssh_key.go
index 2f80bac..f230b3d 100644
--- a/hcloud/schema/ssh_key.go
+++ b/hcloud/schema/ssh_key.go
@@ -1,5 +1,7 @@
 package schema
 
+import "time"
+
 // SSHKey defines the schema of a SSH key.
 type SSHKey struct {
 	ID          int               `json:"id"`
@@ -7,6 +9,7 @@ type SSHKey struct {
 	Fingerprint string            `json:"fingerprint"`
 	PublicKey   string            `json:"public_key"`
 	Labels      map[string]string `json:"labels"`
+	Created     time.Time         `json:"created"`
 }
 
 // SSHKeyCreateRequest defines the schema of the request
diff --git a/hcloud/ssh_key.go b/hcloud/ssh_key.go
index 78e74c4..315cc2e 100644
--- a/hcloud/ssh_key.go
+++ b/hcloud/ssh_key.go
@@ -8,6 +8,7 @@ import (
 	"fmt"
 	"net/url"
 	"strconv"
+	"time"
 
 	"github.com/hetznercloud/hcloud-go/hcloud/schema"
 )
@@ -19,6 +20,7 @@ type SSHKey struct {
 	Fingerprint string
 	PublicKey   string
 	Labels      map[string]string
+	Created     time.Time
 }
 
 // SSHKeyClient is a client for the SSH keys API.


Test patch:
diff --git a/hcloud/schema_test.go b/hcloud/schema_test.go
index 8042a7d..9714793 100644
--- a/hcloud/schema_test.go
+++ b/hcloud/schema_test.go
@@ -755,7 +755,8 @@ func TestSSHKeyFromSchema(t *testing.T) {
 		"labels": {
 			"key": "value",
 			"key2": "value2"
-		}
+		},
+		"created":"2017-08-16T17:29:14+00:00"
 	}`)
 
 	var s schema.SSHKey
@@ -779,6 +780,9 @@ func TestSSHKeyFromSchema(t *testing.T) {
 	if sshKey.Labels["key"] != "value" || sshKey.Labels["key2"] != "value2" {
 		t.Errorf("unexpected labels: %v", sshKey.Labels)
 	}
+	if !sshKey.Created.Equal(time.Date(2017, 8, 16, 17, 29, 14, 0, time.UTC)) {
+		t.Errorf("unexpected created date: %v", sshKey.Created)
+	}
 }
 
 func TestErrorFromSchema(t *testing.T) {
diff --git a/hcloud/ssh_key_test.go b/hcloud/ssh_key_test.go
index e54794e..3137040 100644
--- a/hcloud/ssh_key_test.go
+++ b/hcloud/ssh_key_test.go
@@ -20,7 +20,8 @@ func TestSSHKeyClientGetByID(t *testing.T) {
 				"id": 1,
 				"name": "My key",
 				"fingerprint": "b7:2f:30:a0:2f:6c:58:6c:21:04:58:61:ba:06:3b:2c",
-				"public_key": "ssh-rsa AAAjjk76kgf...Xt"
+				"public_key": "ssh-rsa AAAjjk76kgf...Xt",
+				"created": "2017-08-16T17:29:14+00:00"
 			}
 		}`)
 	})
@@ -155,7 +156,8 @@ func TestSSHKeyClientGetByFingerprint(t *testing.T) {
 				"id": 1,
 				"name": "My Key",
 				"fingerprint": "b7:2f:30:a0:2f:6c:58:6c:21:04:58:61:ba:06:3b:2c",
-				"public_key": "ssh-rsa AAAjjk76kgf...Xt"
+				"public_key": "ssh-rsa AAAjjk76kgf...Xt",
+				"created": "2017-08-16T17:29:14+00:00"
 			}]
 		}`)
 	})
@@ -213,13 +215,15 @@ func TestSSHKeyClientList(t *testing.T) {
 					"id": 1,
 					"name": "My key",
 					"fingerprint": "b7:2f:30:a0:2f:6c:58:6c:21:04:58:61:ba:06:3b:2c",
-					"public_key": "ssh-rsa AAAjjk76kgf...Xt"
+					"public_key": "ssh-rsa AAAjjk76kgf...Xt",
+					"created": "2017-08-16T17:29:14+00:00"
 				},
 				{
 					"id": 2,
 					"name": "Another key",
 					"fingerprint": "c7:2f:30:a0:2f:6c:58:6c:21:04:58:61:ba:06:3b:2c",
-					"public_key": "ssh-rsa AAAjjk76kgf...XX"
+					"public_key": "ssh-rsa AAAjjk76kgf...XX",
+					"created": "2017-08-16T17:29:14+00:00"
 				}
 			]
 		}`)