Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def setup(dockerfile=None, image_tag_string=None):
'''Any initial setup'''
# generate random names for image, container, and tag
general.initialize_names()
# load the cache
cache.load()
# load dockerfile if present
if dockerfile:
dhelper.load_docker_commands(dockerfile)
# check if the docker image is present
if image_tag_string:
if not container.check_image(image_tag_string):
# if no docker image is present, try to pull it
if not container.pull_image(image_tag_string):
logger.fatal("%s", errors.cannot_find_image.format(
imagetag=image_tag_string))
sys.exit()
# create temporary working directory
if not os.path.exists(constants.temp_folder):
os.mkdir(constants.temp_folder)
def generate_yaml(images):
'''Generate a yaml report'''
logger.debug('Creating YAML report...')
report = formats.disclaimer_yaml.format(
version_info=general.get_git_rev_or_version())
for image in images:
report = report + content.print_yaml_report(image)
return report
def get_version():
'''Return the version string for the --version command line option'''
ver_type, commit_or_ver = general.get_git_rev_or_version()
message = ''
if ver_type == "package":
message = "Tern version {}".format(commit_or_ver)
else:
message = "Tern at commit {}".format(commit_or_ver)
return message
def create_top_dir():
'''Create the top level working directory'''
top_dir = general.get_top_dir()
if not os.path.isdir(top_dir):
os.mkdir(top_dir)
def get_shell_commands(shell_command_line):
'''Given a shell command line, get a list of Command objects'''
comm_list = general.split_command(shell_command_line)
cleaned_list = []
for comm in comm_list:
cleaned_list.append(Command(general.clean_command(comm)))
return cleaned_list
def get_shell_commands(shell_command_line):
'''Given a shell command line, get a list of Command objects'''
comm_list = general.split_command(shell_command_line)
cleaned_list = []
for comm in comm_list:
cleaned_list.append(Command(general.clean_command(comm)))
return cleaned_list
def extract_image_metadata(image_tag_string):
'''Run docker save and extract the files in a temporary directory'''
temp_path = rootfs.get_working_dir()
placeholder = os.path.join(general.get_top_dir(), temp_tarfile)
try:
if common.check_tar(image_tag_string) is True:
# image_tag_string is the path to the tar file for raw images
rootfs.extract_tarfile(image_tag_string, temp_path)
else:
image = client.images.get(image_tag_string)
result = image.save(chunk_size=2097152, named=True)
# write all of the tar byte stream into temporary tar file
with open(placeholder, 'wb') as f:
for chunk in result:
f.write(chunk)
# extract tarfile into folder
rootfs.extract_tarfile(placeholder, temp_path)
# remove temporary tar file
os.remove(placeholder)
if not os.listdir(temp_path):