@@ -14,10 +14,13 @@ func (d *Driver) getClient() *hcloud.Client {
14
14
return hcloud .NewClient (hcloud .WithToken (d .AccessToken ), hcloud .WithApplication ("docker-machine-driver" , d .version ))
15
15
}
16
16
17
- func (d * Driver ) getLocation () (* hcloud.Location , error ) {
17
+ func (d * Driver ) getLocationNullable () (* hcloud.Location , error ) {
18
18
if d .cachedLocation != nil {
19
19
return d .cachedLocation , nil
20
20
}
21
+ if d .Location == "" {
22
+ return nil , nil
23
+ }
21
24
22
25
location , _ , err := d .getClient ().Location .GetByName (context .Background (), d .Location )
23
26
if err != nil {
@@ -95,6 +98,17 @@ func (d *Driver) getImageArchitectureForLookup() (hcloud.Architecture, error) {
95
98
}
96
99
97
100
func (d * Driver ) getKey () (* hcloud.SSHKey , error ) {
101
+ key , err := d .getKeyNullable ()
102
+ if err != nil {
103
+ return nil , err
104
+ }
105
+ if key == nil {
106
+ return nil , fmt .Errorf ("key not found: %v" , d .KeyID )
107
+ }
108
+ return key , err
109
+ }
110
+
111
+ func (d * Driver ) getKeyNullable () (* hcloud.SSHKey , error ) {
98
112
if d .cachedKey != nil {
99
113
return d .cachedKey , nil
100
114
}
@@ -103,14 +117,11 @@ func (d *Driver) getKey() (*hcloud.SSHKey, error) {
103
117
if err != nil {
104
118
return nil , errors .Wrap (err , "could not get sshkey by ID" )
105
119
}
106
- if key == nil {
107
- return nil , fmt .Errorf ("key not found: %v" , d .KeyID )
108
- }
109
120
d .cachedKey = key
110
121
return instrumented (key ), nil
111
122
}
112
123
113
- func (d * Driver ) getRemoteKeyWithSameFingerprint (publicKeyBytes []byte ) (* hcloud.SSHKey , error ) {
124
+ func (d * Driver ) getRemoteKeyWithSameFingerprintNullable (publicKeyBytes []byte ) (* hcloud.SSHKey , error ) {
114
125
publicKey , _ , _ , _ , err := ssh .ParseAuthorizedKey (publicKeyBytes )
115
126
if err != nil {
116
127
return nil , errors .Wrap (err , "could not parse ssh public key" )
@@ -122,9 +133,6 @@ func (d *Driver) getRemoteKeyWithSameFingerprint(publicKeyBytes []byte) (*hcloud
122
133
if err != nil {
123
134
return remoteKey , errors .Wrap (err , "could not get sshkey by fingerprint" )
124
135
}
125
- if remoteKey == nil {
126
- return nil , fmt .Errorf ("key not found by fingerprint: %v" , fp )
127
- }
128
136
return instrumented (remoteKey ), nil
129
137
}
130
138
0 commit comments