2018-05-30 22:28:41 +00:00
|
|
|
package egoscale
|
|
|
|
|
2018-09-08 10:09:59 +00:00
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
)
|
|
|
|
|
2018-05-30 22:28:41 +00:00
|
|
|
// SSHKeyPair represents an SSH key pair
|
|
|
|
//
|
|
|
|
// See: http://docs.cloudstack.apache.org/projects/cloudstack-administration/en/stable/virtual_machines.html#creating-the-ssh-keypair
|
|
|
|
type SSHKeyPair struct {
|
2018-09-08 10:09:59 +00:00
|
|
|
Fingerprint string `json:"fingerprint,omitempty" doc:"Fingerprint of the public key"`
|
|
|
|
Name string `json:"name,omitempty" doc:"Name of the keypair"`
|
|
|
|
PrivateKey string `json:"privatekey,omitempty" doc:"Private key"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// Delete removes the given SSH key, by Name
|
|
|
|
func (ssh SSHKeyPair) Delete(ctx context.Context, client *Client) error {
|
|
|
|
if ssh.Name == "" {
|
|
|
|
return fmt.Errorf("an SSH Key Pair may only be deleted using Name")
|
|
|
|
}
|
|
|
|
|
|
|
|
return client.BooleanRequestWithContext(ctx, &DeleteSSHKeyPair{
|
|
|
|
Name: ssh.Name,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// ListRequest builds the ListSSHKeyPairs request
|
|
|
|
func (ssh SSHKeyPair) ListRequest() (ListCommand, error) {
|
|
|
|
req := &ListSSHKeyPairs{
|
|
|
|
Fingerprint: ssh.Fingerprint,
|
|
|
|
Name: ssh.Name,
|
|
|
|
}
|
|
|
|
|
|
|
|
return req, nil
|
2018-05-30 22:28:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// CreateSSHKeyPair represents a new keypair to be created
|
|
|
|
type CreateSSHKeyPair struct {
|
2019-02-18 09:49:41 +00:00
|
|
|
Name string `json:"name" doc:"Name of the keypair"`
|
|
|
|
_ bool `name:"createSSHKeyPair" description:"Create a new keypair and returns the private key"`
|
2018-05-30 22:28:41 +00:00
|
|
|
}
|
|
|
|
|
2019-02-18 09:49:41 +00:00
|
|
|
// Response returns the struct to unmarshal
|
|
|
|
func (CreateSSHKeyPair) Response() interface{} {
|
2018-09-08 10:09:59 +00:00
|
|
|
return new(SSHKeyPair)
|
2018-05-30 22:28:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// DeleteSSHKeyPair represents a new keypair to be created
|
|
|
|
type DeleteSSHKeyPair struct {
|
2019-02-18 09:49:41 +00:00
|
|
|
Name string `json:"name" doc:"Name of the keypair"`
|
|
|
|
_ bool `name:"deleteSSHKeyPair" description:"Deletes a keypair by name"`
|
2018-09-08 10:09:59 +00:00
|
|
|
}
|
|
|
|
|
2019-02-18 09:49:41 +00:00
|
|
|
// Response returns the struct to unmarshal
|
|
|
|
func (DeleteSSHKeyPair) Response() interface{} {
|
|
|
|
return new(BooleanResponse)
|
2018-05-30 22:28:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// RegisterSSHKeyPair represents a new registration of a public key in a keypair
|
|
|
|
type RegisterSSHKeyPair struct {
|
|
|
|
Name string `json:"name" doc:"Name of the keypair"`
|
|
|
|
PublicKey string `json:"publickey" doc:"Public key material of the keypair"`
|
2018-09-08 10:09:59 +00:00
|
|
|
_ bool `name:"registerSSHKeyPair" description:"Register a public key in a keypair under a certain name"`
|
2018-05-30 22:28:41 +00:00
|
|
|
}
|
|
|
|
|
2019-02-18 09:49:41 +00:00
|
|
|
// Response returns the struct to unmarshal
|
|
|
|
func (RegisterSSHKeyPair) Response() interface{} {
|
2018-09-08 10:09:59 +00:00
|
|
|
return new(SSHKeyPair)
|
2018-05-30 22:28:41 +00:00
|
|
|
}
|
|
|
|
|
2019-02-18 09:49:41 +00:00
|
|
|
//go:generate go run generate/main.go -interface=Listable ListSSHKeyPairs
|
|
|
|
|
2018-05-30 22:28:41 +00:00
|
|
|
// ListSSHKeyPairs represents a query for a list of SSH KeyPairs
|
|
|
|
type ListSSHKeyPairs struct {
|
|
|
|
Fingerprint string `json:"fingerprint,omitempty" doc:"A public key fingerprint to look for"`
|
|
|
|
Keyword string `json:"keyword,omitempty" doc:"List by keyword"`
|
|
|
|
Name string `json:"name,omitempty" doc:"A key pair name to look for"`
|
|
|
|
Page int `json:"page,omitempty"`
|
|
|
|
PageSize int `json:"pagesize,omitempty"`
|
2018-09-08 10:09:59 +00:00
|
|
|
_ bool `name:"listSSHKeyPairs" description:"List registered keypairs"`
|
2018-05-30 22:28:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ListSSHKeyPairsResponse represents a list of SSH key pairs
|
|
|
|
type ListSSHKeyPairsResponse struct {
|
|
|
|
Count int `json:"count"`
|
|
|
|
SSHKeyPair []SSHKeyPair `json:"sshkeypair"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// ResetSSHKeyForVirtualMachine (Async) represents a change for the key pairs
|
|
|
|
type ResetSSHKeyForVirtualMachine struct {
|
2019-02-18 09:49:41 +00:00
|
|
|
ID *UUID `json:"id" doc:"The ID of the virtual machine"`
|
|
|
|
KeyPair string `json:"keypair" doc:"Name of the ssh key pair used to login to the virtual machine"`
|
|
|
|
_ bool `name:"resetSSHKeyForVirtualMachine" description:"Resets the SSH Key for virtual machine. The virtual machine must be in a \"Stopped\" state."`
|
2018-05-30 22:28:41 +00:00
|
|
|
}
|
|
|
|
|
2019-02-18 09:49:41 +00:00
|
|
|
// Response returns the struct to unmarshal
|
|
|
|
func (ResetSSHKeyForVirtualMachine) Response() interface{} {
|
2018-09-08 10:09:59 +00:00
|
|
|
return new(AsyncJobResult)
|
|
|
|
}
|
|
|
|
|
2019-02-18 09:49:41 +00:00
|
|
|
// AsyncResponse returns the struct to unmarshal the async job
|
|
|
|
func (ResetSSHKeyForVirtualMachine) AsyncResponse() interface{} {
|
2018-09-08 10:09:59 +00:00
|
|
|
return new(VirtualMachine)
|
|
|
|
}
|