github.com/juju/charm/v11@v11.2.0/bundle.go (about) 1 // Copyright 2014 Canonical Ltd. 2 // Licensed under the LGPLv3, see LICENCE file for details. 3 4 package charm 5 6 import ( 7 "os" 8 "path/filepath" 9 "strings" 10 ) 11 12 // The Bundle interface is implemented by any type that 13 // may be handled as a bundle. It encapsulates all 14 // the data of a bundle. 15 type Bundle interface { 16 // Data returns the contents of the bundle's bundle.yaml file. 17 Data() *BundleData 18 // ReadMe returns the contents of the bundle's README.md file. 19 ReadMe() string 20 // ContainsOverlays returns true if the bundle contains any overlays. 21 ContainsOverlays() bool 22 } 23 24 // ReadBundle reads a Bundle from path, which can point to either a 25 // bundle archive or a bundle directory. 26 func ReadBundle(path string) (Bundle, error) { 27 info, err := os.Stat(path) 28 if err != nil { 29 return nil, err 30 } 31 if info.IsDir() { 32 return ReadBundleDir(path) 33 } 34 return ReadBundleArchive(path) 35 } 36 37 // IsValidLocalCharmOrBundlePath returns true if path is valid for reading a 38 // local charm or bundle. 39 func IsValidLocalCharmOrBundlePath(path string) bool { 40 return strings.HasPrefix(path, ".") || filepath.IsAbs(path) 41 }