github.com/wallyworld/juju@v0.0.0-20161013125918-6cf1bc9d917a/api/hostkeyreporter/facade.go (about)

     1  // Copyright 2016 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  // Package hostkeyreporter implements the client-side API facade used
     5  // by the hostkeyreporter worker.
     6  package hostkeyreporter
     7  
     8  import (
     9  	"gopkg.in/juju/names.v2"
    10  
    11  	"github.com/juju/juju/api/base"
    12  	"github.com/juju/juju/apiserver/params"
    13  )
    14  
    15  // Facade provides access to the HostKeyReporter API facade.
    16  type Facade struct {
    17  	caller base.FacadeCaller
    18  }
    19  
    20  // NewFacade creates a new client-side HostKeyReporter facade.
    21  func NewFacade(caller base.APICaller) *Facade {
    22  	return &Facade{
    23  		caller: base.NewFacadeCaller(caller, "HostKeyReporter"),
    24  	}
    25  }
    26  
    27  // ReportKeys reports the public SSH host keys for a machine to the
    28  // controller. The keys should be in the same format as the sshd host
    29  // key files, one entry per key.
    30  func (f *Facade) ReportKeys(machineId string, publicKeys []string) error {
    31  	args := params.SSHHostKeySet{EntityKeys: []params.SSHHostKeys{{
    32  		Tag:        names.NewMachineTag(machineId).String(),
    33  		PublicKeys: publicKeys,
    34  	}}}
    35  	var result params.ErrorResults
    36  	err := f.caller.FacadeCall("ReportKeys", args, &result)
    37  	if err != nil {
    38  		return err
    39  	}
    40  	return result.OneError()
    41  }