-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c43300e
commit 0f6a7f8
Showing
6 changed files
with
105 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package api | ||
|
||
import ( | ||
"github.com/maas/gomaasclient/entity" | ||
) | ||
|
||
// SSLKey is an interface defining API behaviour for SSLKey objects | ||
type SSLKey interface { | ||
Get(id int) (*entity.SSLKey, error) | ||
Delete(id int) error | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package api | ||
|
||
import ( | ||
"github.com/maas/gomaasclient/entity" | ||
) | ||
|
||
// SSLKeys is an interface for listing and creating SSLKey objects | ||
type SSLKeys interface { | ||
Get() ([]entity.SSLKey, error) | ||
Create(key string) (*entity.SSLKey, error) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package client | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"net/url" | ||
|
||
"github.com/maas/gomaasclient/entity" | ||
) | ||
|
||
// SSLKey implements api.SSLKey | ||
type SSLKey struct { | ||
APIClient APIClient | ||
} | ||
|
||
func (s *SSLKey) client(id int) APIClient { | ||
return s.APIClient.GetSubObject("account/prefs/sslkeys").GetSubObject(fmt.Sprintf("%v", id)) | ||
} | ||
|
||
// Get fetches a given SSLKey | ||
func (s *SSLKey) Get(id int) (*entity.SSLKey, error) { | ||
sslKey := new(entity.SSLKey) | ||
err := s.client(id).Get("", url.Values{}, func(data []byte) error { | ||
return json.Unmarshal(data, sslKey) | ||
}) | ||
|
||
return sslKey, err | ||
} | ||
|
||
// Delete deletes a given SSLKey | ||
func (s *SSLKey) Delete(id int) error { | ||
return s.client(id).Delete() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package client | ||
|
||
import ( | ||
"encoding/json" | ||
"net/url" | ||
|
||
"github.com/maas/gomaasclient/entity" | ||
) | ||
|
||
// SSLKeys implements api.SSLKeys | ||
type SSLKeys struct { | ||
APIClient APIClient | ||
} | ||
|
||
func (s *SSLKeys) client() APIClient { | ||
return s.APIClient.GetSubObject("account/prefs/sslkeys") | ||
} | ||
|
||
// Get fetches a list of SSLKey objects | ||
func (s *SSLKeys) Get() ([]entity.SSLKey, error) { | ||
sslKeys := make([]entity.SSLKey, 0) | ||
err := s.client().Get("", url.Values{}, func(data []byte) error { | ||
return json.Unmarshal(data, &sslKeys) | ||
}) | ||
|
||
return sslKeys, err | ||
} | ||
|
||
// Create creates a new SSLKey | ||
func (s *SSLKeys) Create(key string) (*entity.SSLKey, error) { | ||
sslKey := new(entity.SSLKey) | ||
qsp := url.Values{} | ||
qsp.Set("key", key) | ||
err := s.client().Post("", qsp, func(data []byte) error { | ||
return json.Unmarshal(data, sslKey) | ||
}) | ||
|
||
return sslKey, err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package entity | ||
|
||
type SSLKey struct { | ||
ID int `json:"id,omitempty"` | ||
Key string `json:"key,omitempty"` | ||
ResourceURI string `json:"resource_uri,omitempty"` | ||
} |