github.com/juju/juju@v0.0.0-20240430160146-1752b71fcf00/api/client/bundle/client.go (about)

     1  // Copyright 2018 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package bundle
     5  
     6  import (
     7  	"github.com/juju/errors"
     8  
     9  	"github.com/juju/juju/api/base"
    10  	"github.com/juju/juju/rpc/params"
    11  )
    12  
    13  // Client allows access to the bundle API end point.
    14  type Client struct {
    15  	base.ClientFacade
    16  	facade base.FacadeCaller
    17  }
    18  
    19  // NewClient creates a new client for accessing the bundle api.
    20  func NewClient(st base.APICallCloser) *Client {
    21  	frontend, backend := base.NewClientFacade(st, "Bundle")
    22  	return &Client{
    23  		ClientFacade: frontend,
    24  		facade:       backend}
    25  }
    26  
    27  // GetChanges returns back the changes for a given bundle that need to be
    28  // applied.
    29  // GetChanges is superseded by GetChangesMapArgs, use that where possible, by
    30  // detecting the BestAPIVersion to use.
    31  func (c *Client) GetChanges(bundleURL, bundleDataYAML string) (params.BundleChangesResults, error) {
    32  	var result params.BundleChangesResults
    33  	if err := c.facade.FacadeCall("GetChanges", params.BundleChangesParams{
    34  		BundleURL:      bundleURL,
    35  		BundleDataYAML: bundleDataYAML,
    36  	}, &result); err != nil {
    37  		return result, errors.Trace(err)
    38  	}
    39  	return result, nil
    40  }
    41  
    42  // GetChangesMapArgs returns back the changes for a given bundle that need to be
    43  // applied, with the args of a method as a map.
    44  func (c *Client) GetChangesMapArgs(bundleURL, bundleDataYAML string) (params.BundleChangesMapArgsResults, error) {
    45  	var result params.BundleChangesMapArgsResults
    46  	if err := c.facade.FacadeCall("GetChangesMapArgs", params.BundleChangesParams{
    47  		BundleURL:      bundleURL,
    48  		BundleDataYAML: bundleDataYAML,
    49  	}, &result); err != nil {
    50  		return result, errors.Trace(err)
    51  	}
    52  	return result, nil
    53  }
    54  
    55  // ExportBundle exports the current model configuration.
    56  func (c *Client) ExportBundle(includeDefaults bool, includeSeries bool) (string, error) {
    57  	var result params.StringResult
    58  	arg := params.ExportBundleParams{
    59  		IncludeCharmDefaults: includeDefaults,
    60  		IncludeSeries:        includeSeries,
    61  	}
    62  	if err := c.facade.FacadeCall("ExportBundle", arg, &result); err != nil {
    63  		return "", errors.Trace(err)
    64  	}
    65  
    66  	if result.Error != nil {
    67  		return "", errors.Trace(result.Error)
    68  	}
    69  
    70  	return result.Result, nil
    71  }