github.com/juju/juju@v0.0.0-20240430160146-1752b71fcf00/api/agent/uniter/charm.go (about) 1 // Copyright 2013 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package uniter 5 6 import ( 7 "fmt" 8 9 "github.com/juju/errors" 10 11 "github.com/juju/juju/rpc/params" 12 ) 13 14 // This module implements a subset of the interface provided by 15 // state.Charm, as needed by the uniter API. 16 17 // Charm represents the state of a charm in the model. 18 type Charm struct { 19 st *State 20 curl string 21 } 22 23 // URL returns the URL that identifies the charm. 24 func (c *Charm) URL() string { 25 return c.curl 26 } 27 28 // ArchiveSha256 returns the SHA256 digest of the charm archive 29 // (bundle) bytes. 30 // 31 // NOTE: This differs from state.Charm.BundleSha256() by returning an 32 // error as well, because it needs to make an API call. It's also 33 // renamed to avoid confusion with juju deployment bundles. 34 // 35 // TODO(dimitern): 2013-09-06 bug 1221834 36 // Cache the result after getting it once for the same charm URL, 37 // because it's immutable. 38 func (c *Charm) ArchiveSha256() (string, error) { 39 var results params.StringResults 40 args := params.CharmURLs{ 41 URLs: []params.CharmURL{{URL: c.curl}}, 42 } 43 err := c.st.facade.FacadeCall("CharmArchiveSha256", args, &results) 44 if err != nil { 45 return "", err 46 } 47 if len(results.Results) != 1 { 48 return "", fmt.Errorf("expected 1 result, got %d", len(results.Results)) 49 } 50 result := results.Results[0] 51 if result.Error != nil { 52 return "", result.Error 53 } 54 return result.Result, nil 55 } 56 57 // LXDProfileRequired returns true if this charm requires an 58 // lxd profile to be applied. 59 func (c *Charm) LXDProfileRequired() (bool, error) { 60 var results params.BoolResults 61 args := params.CharmURLs{ 62 URLs: []params.CharmURL{{URL: c.curl}}, 63 } 64 err := c.st.facade.FacadeCall("LXDProfileRequired", args, &results) 65 if err != nil { 66 return false, err 67 } 68 if len(results.Results) != 1 { 69 return false, errors.Errorf("expected 1 result, got %d", len(results.Results)) 70 } 71 result := results.Results[0] 72 if result.Error != nil { 73 return false, result.Error 74 } 75 return result.Result, nil 76 }