github.com/wallyworld/juju@v0.0.0-20161013125918-6cf1bc9d917a/resource/resourceadapters/apiclient.go (about)

     1  // Copyright 2016 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package resourceadapters
     5  
     6  import (
     7  	"github.com/juju/errors"
     8  
     9  	"github.com/juju/juju/api/base"
    10  	"github.com/juju/juju/resource"
    11  	"github.com/juju/juju/resource/api/client"
    12  	"github.com/juju/juju/resource/api/server"
    13  )
    14  
    15  // NewAPIClient is mostly a copy of the newClient code in
    16  // component/all/resources.go.  It lives here because it simplifies this code
    17  // immensely.
    18  func NewAPIClient(apiCaller base.APICallCloser) (*client.Client, error) {
    19  	caller := base.NewFacadeCallerForVersion(apiCaller, resource.FacadeName, server.Version)
    20  
    21  	httpClient, err := apiCaller.HTTPClient()
    22  	if err != nil {
    23  		return nil, errors.Trace(err)
    24  	}
    25  	// The apiCaller takes care of prepending /environment/<envUUID>.
    26  	apiClient := client.NewClient(caller, httpClient, apiCaller)
    27  	return apiClient, nil
    28  }