/usr/share/conjure-up/conjure/charm.py is in conjure-up 0.1.0.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | """ Charm utilities
Api for the charmstore:
https://github.com/juju/charmstore/blob/v4/docs/API.md
"""
import yaml
import requests
import os.path as path
from tempfile import NamedTemporaryFile
import shutil
from conjure.utils import spew
cs = 'https://api.jujucharms.com/v4'
class CharmStoreException(Exception):
""" CharmStore exception """
def get_bundle(bundle, to_file=False):
""" Attempts to grab the bundle.yaml
Arguments:
bundle: name of bundle or absolute path to local bundle
to_file: store to a temporary file
Returns:
Dictionary of bundle's yaml unless to_file is True,
then returns the path to the downloaded bundle
"""
if path.isfile(bundle):
if to_file:
with NamedTemporaryFile(mode="w", encoding="utf-8",
delete=False) as tempf:
shutil.copyfile(bundle, tempf.name)
return tempf.name
else:
with open(bundle) as f:
return yaml.safe_load(f.read())
bundle = path.join(cs, bundle, 'archive/bundle.yaml')
req = requests.get(bundle)
if not req.ok:
raise CharmStoreException("Problem getting bundle: {}".format(req))
if to_file:
with NamedTemporaryFile(mode="w", encoding="utf-8",
delete=False) as tempf:
spew(tempf.name, req.text)
return tempf.name
else:
return yaml.safe_load(req.text)
|