2023-12-29 01:36:10 -06:00
|
|
|
package digitalocean
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"golang.org/x/oauth2"
|
|
|
|
|
|
|
|
"github.com/digitalocean/godo"
|
2023-12-30 23:30:14 -06:00
|
|
|
|
|
|
|
"go.wit.com/log"
|
2023-12-29 01:36:10 -06:00
|
|
|
)
|
|
|
|
|
2023-12-30 23:30:14 -06:00
|
|
|
// func (d *DigitalOcean) ListDroplets() bool {
|
|
|
|
func (d *DigitalOcean) ListSSHKeyID() error {
|
|
|
|
tokenSource := oauth2.StaticTokenSource(&oauth2.Token{AccessToken: d.token})
|
2023-12-29 01:36:10 -06:00
|
|
|
oauthClient := oauth2.NewClient(context.Background(), tokenSource)
|
|
|
|
client := godo.NewClient(oauthClient)
|
|
|
|
|
|
|
|
// List all keys.
|
|
|
|
keys, _, err := client.Keys.List(context.Background(), &godo.ListOptions{})
|
|
|
|
if err != nil {
|
2023-12-30 23:30:14 -06:00
|
|
|
return err
|
2023-12-29 01:36:10 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// Find the key by name.
|
2023-12-30 23:30:14 -06:00
|
|
|
for i, key := range keys {
|
|
|
|
log.Info("found ssh i =", i)
|
|
|
|
log.Info("found ssh key.Name =", key.Name)
|
|
|
|
log.Info("found ssh key.Fingerprint =", key.Fingerprint)
|
|
|
|
log.Info("found ssh key:", key)
|
|
|
|
// if key.Name == name {
|
|
|
|
// return key.Fingerprint, nil
|
|
|
|
// }
|
2023-12-29 01:36:10 -06:00
|
|
|
}
|
|
|
|
|
2023-12-30 23:30:14 -06:00
|
|
|
// return fmt.Errorf("SSH Key not found")
|
|
|
|
return nil
|
2023-12-29 01:36:10 -06:00
|
|
|
}
|