github.com/mhilton/juju-juju@v0.0.0-20150901100907-a94dd2c73455/api/keymanager/client.go (about) 1 // Copyright 2013 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package keymanager 5 6 import ( 7 "github.com/juju/juju/api/base" 8 "github.com/juju/juju/apiserver/params" 9 "github.com/juju/juju/utils/ssh" 10 ) 11 12 // Client provides access to the keymanager, used to add/delete/list authorised ssh keys. 13 type Client struct { 14 base.ClientFacade 15 facade base.FacadeCaller 16 } 17 18 // NewClient returns a new keymanager client. 19 func NewClient(st base.APICallCloser) *Client { 20 frontend, backend := base.NewClientFacade(st, "KeyManager") 21 return &Client{ClientFacade: frontend, facade: backend} 22 } 23 24 // ListKeys returns the authorised ssh keys for the specified users. 25 func (c *Client) ListKeys(mode ssh.ListMode, users ...string) ([]params.StringsResult, error) { 26 p := params.ListSSHKeys{Mode: mode} 27 p.Entities.Entities = make([]params.Entity, len(users)) 28 for i, userName := range users { 29 p.Entities.Entities[i] = params.Entity{Tag: userName} 30 } 31 results := new(params.StringsResults) 32 err := c.facade.FacadeCall("ListKeys", p, results) 33 return results.Results, err 34 } 35 36 // AddKeys adds the authorised ssh keys for the specified user. 37 func (c *Client) AddKeys(user string, keys ...string) ([]params.ErrorResult, error) { 38 p := params.ModifyUserSSHKeys{User: user, Keys: keys} 39 results := new(params.ErrorResults) 40 err := c.facade.FacadeCall("AddKeys", p, results) 41 return results.Results, err 42 } 43 44 // DeleteKeys deletes the authorised ssh keys for the specified user. 45 func (c *Client) DeleteKeys(user string, keys ...string) ([]params.ErrorResult, error) { 46 p := params.ModifyUserSSHKeys{User: user, Keys: keys} 47 results := new(params.ErrorResults) 48 err := c.facade.FacadeCall("DeleteKeys", p, results) 49 return results.Results, err 50 } 51 52 // ImportKeys imports the authorised ssh keys with the specified key ids for the specified user. 53 func (c *Client) ImportKeys(user string, keyIds ...string) ([]params.ErrorResult, error) { 54 p := params.ModifyUserSSHKeys{User: user, Keys: keyIds} 55 results := new(params.ErrorResults) 56 err := c.facade.FacadeCall("ImportKeys", p, results) 57 return results.Results, err 58 }