Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def get_shell(image_obj, binary):
# set up a notice origin referring to the base command library listing
origin_command_lib = formats.invoking_base_commands
# find the shell to invoke commands in
shell, _ = command_lib.get_image_shell(
command_lib.get_base_listing(binary))
if not shell:
# add a warning notice for no shell in the command library
logger.warning('No shell listing in command library. '
'Using default shell')
no_shell_message = errors.no_shell_listing.format(
binary=binary, default_shell=constants.shell)
image_obj.layers[0].origins.add_notice_to_origins(
origin_command_lib, Notice(no_shell_message, 'warning'))
# add a hint notice to add the shell to the command library
add_shell_message = errors.no_listing_for_base_key.format(
listing_key='shell')
image_obj.layers[0].origins.add_notice_to_origins(
origin_command_lib, Notice(add_shell_message, 'hint'))
shell = constants.shell
def print_base_invoke(key):
'''Given the key in the base library, return a string containing
the command_lib/base.yml'''
info = command_lib.get_base_listing(key)
report = ''
for item in command_lib.base_keys:
if item in info.keys():
report = report + print_invoke_list(info, item)
report = report + '\n'
return report
if dockerfile:
dhelper.set_imported_layers(image_obj)
# add notices for each layer if it is imported
image_setup(image_obj)
shell = ''
# set up empty master list of packages
master_list = []
# find the binary by mounting the base layer
target = rootfs.mount_base_layer(image_obj.layers[0].tar_file)
binary = common.get_base_bin()
# set up a notice origin referring to the base command library listing
origin_command_lib = formats.invoking_base_commands
# set up a notice origin for the first layer
origin_first_layer = 'Layer: ' + image_obj.layers[0].fs_hash[:10]
# find the shell to invoke commands in
shell, _ = command_lib.get_image_shell(
command_lib.get_base_listing(binary))
if not shell:
# add a warning notice for no shell in the command library
logger.warning('No shell listing in command library. '
'Using default shell')
no_shell_message = errors.no_shell_listing.format(
binary=binary, default_shell=constants.shell)
image_obj.layers[0].origins.add_notice_to_origins(
origin_command_lib, Notice(no_shell_message, 'warning'))
# add a hint notice to add the shell to the command library
add_shell_message = errors.no_listing_for_base_key.format(
listing_key='shell')
image_obj.layers[0].origins.add_notice_to_origins(
origin_command_lib, Notice(add_shell_message, 'hint'))
shell = constants.shell
# only extract packages if there is a known binary and the layer is not
def collate_list_metadata(shell, listing):
'''Given the shell and the listing for the package manager, collect
metadata that gets returned as a list'''
pkg_dict = {}
msgs = ''
warnings = ''
for item in command_lib.base_keys:
if item in listing.keys():
items, msg = command_lib.get_pkg_attr_list(shell, listing[item])
msgs = msgs + msg
pkg_dict.update({item: items})
else:
warnings = warnings + errors.no_listing_for_base_key.format(
listing_key=item)
return pkg_dict, msgs, warnings
def fill_package_metadata(pkg_obj, pkg_listing, shell):
'''Given a Package object and the Package listing from the command
library, fill in the attribute value returned from looking up the
data and methods of the package listing.
Fill out: version, license and proj_url
If there are errors, fill out notices'''
# create a NoticeOrigin for the package
origin_str = 'command_lib/snippets.yml'
# version
version_listing, listing_msg = command_lib.check_library_key(
pkg_listing, 'version')
if version_listing:
version_list, invoke_msg = command_lib.get_pkg_attr_list(
shell, version_listing, package_name=pkg_obj.name)
if version_list:
pkg_obj.version = version_list[0]
else:
pkg_obj.origins.add_notice_to_origins(
origin_str, Notice(invoke_msg, 'error'))
else:
pkg_obj.origins.add_notice_to_origins(
origin_str, Notice(listing_msg, 'warning'))
# license
license_listing, listing_msg = command_lib.check_library_key(
pkg_listing, 'license')
if license_listing: