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