github.com/altoros/juju-vmware@v0.0.0-20150312064031-f19ae857ccca/api/service/client.go (about) 1 // Copyright 2014 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 // Package service provides access to the service api facade. 5 // This facade contains api calls that are specific to services. 6 // As a rule of thumb, if the argument for an api requries a service name 7 // and affects only that service then the call belongs here. 8 package service 9 10 import ( 11 "github.com/juju/errors" 12 13 "github.com/juju/juju/api" 14 "github.com/juju/juju/api/base" 15 "github.com/juju/juju/apiserver/params" 16 ) 17 18 // Client allows access to the service API end point. 19 type Client struct { 20 base.ClientFacade 21 st *api.State 22 facade base.FacadeCaller 23 } 24 25 // NewClient creates a new client for accessing the service api. 26 func NewClient(st *api.State) *Client { 27 frontend, backend := base.NewClientFacade(st, "Service") 28 return &Client{ClientFacade: frontend, st: st, facade: backend} 29 } 30 31 // SetMetricCredentials sets the metric credentials for the service specified. 32 func (c *Client) SetMetricCredentials(service string, credentials []byte) error { 33 creds := []params.ServiceMetricCredential{ 34 {service, credentials}, 35 } 36 p := params.ServiceMetricCredentials{creds} 37 results := new(params.ErrorResults) 38 err := c.facade.FacadeCall("SetMetricCredentials", p, results) 39 if err != nil { 40 return errors.Trace(err) 41 } 42 return errors.Trace(results.OneError()) 43 }