Skip to content

Commit

Permalink
Add Created field to SSHKey (#123)
Browse files Browse the repository at this point in the history
  • Loading branch information
LKaemmerling authored and thcyron committed Nov 11, 2019
1 parent 6b1b486 commit 67338ae
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 1 addition & 0 deletions hcloud/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 3 additions & 0 deletions hcloud/schema/ssh_key.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package schema

import "time"

// SSHKey defines the schema of a SSH key.
type SSHKey struct {
ID int `json:"id"`
Name string `json:"name"`
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
Expand Down
6 changes: 5 additions & 1 deletion hcloud/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) {
Expand Down
2 changes: 2 additions & 0 deletions hcloud/ssh_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"fmt"
"net/url"
"strconv"
"time"

"github.com/hetznercloud/hcloud-go/hcloud/schema"
)
Expand All @@ -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.
Expand Down
12 changes: 8 additions & 4 deletions hcloud/ssh_key_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}`)
})
Expand Down Expand Up @@ -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"
}]
}`)
})
Expand Down Expand Up @@ -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"
}
]
}`)
Expand Down

0 comments on commit 67338ae

Please sign in to comment.