func (self *BundleStore) GetBundleTemplate(key string) (*BundleTemplate, error) { // TODO: Check for path traversal path := path.Join(self.basedir, key+".yaml") bytes := sources.NewFileByteSource(path) exists, err := bytes.Exists() if err != nil { return nil, fmt.Errorf("Error checking for template", err) } if !exists { log.Warn("Service bundle not found: %v", path) return nil, nil } return NewBundleTemplate(bytes) }
func (self *Client) DownloadCharm(charmKey string) (sources.ByteSource, error) { // Sadly not readable by user charmInfo, err := self.CharmInfo(charmKey) if err != nil { log.Warn("Unable to get charm info: %v", charmKey, err) return nil, err } environment, err := self.client.EnvironmentGet() if err != nil { log.Warn("Unable to get juju environment", err) return nil, err } jujuType := asString(environment["type"]) if jujuType == "" { return nil, fmt.Errorf("Could not fetch environment value 'type'") } rootDir := asString(environment["root-dir"]) if rootDir == "" { return nil, fmt.Errorf("Could not fetch environment value 'type'") } // zipFile := "${HOME}/.juju/local/charmcache/cs_3a__7e_justin-fathomdb_2f_trusty_2f_mongodb-0.charm" escaped := encodeCharmPath(charmInfo.URL) filename := escaped + ".charm" charmPath := filepath.Join(rootDir, "charmcache", filename) if jujuType == "local" { contents := sources.NewFileByteSource(charmPath) exists, err := contents.Exists() if err != nil { return nil, err } if !exists { return nil, fmt.Errorf("Charm file not found: %v", charmPath) } return contents, nil } else { return nil, fmt.Errorf("Unable to handle juju configuration type: %v", jujuType) } }