Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
15294b8
Update color_print.py
HackGiter Apr 22, 2024
294ae70
Update gadget.py
HackGiter Apr 22, 2024
f97f8a3
Update cnv.py
HackGiter Apr 22, 2024
1ae7a4f
Update cnv.py
HackGiter Apr 22, 2024
9455cfb
Update cnv.py
HackGiter Apr 22, 2024
bd12df5
Update cnv.py
HackGiter Apr 22, 2024
ea20b39
Update gadget.py
HackGiter Apr 22, 2024
08f2045
Update color_print.py
HackGiter Apr 22, 2024
ad657c5
Update installer.py
HackGiter Apr 22, 2024
c6c4f2e
Update internal.py
HackGiter Apr 22, 2024
acf8748
Update cnv.py
HackGiter Apr 22, 2024
d5c7f4c
Update gadget.py
HackGiter Apr 22, 2024
765077b
Update cnv.py
HackGiter Apr 23, 2024
f36ab3b
Update gadget.py
HackGiter Apr 23, 2024
2c3ee19
Update color_print.py
HackGiter Apr 27, 2024
6c21e4a
Update color_print.py
HackGiter Apr 27, 2024
b9e7967
Update cnv.py
HackGiter Apr 27, 2024
02878a7
Update gadget.py
HackGiter Apr 27, 2024
af5e775
Update internal.py
HackGiter Apr 27, 2024
68bdfab
Update internal.py
HackGiter Apr 27, 2024
764963a
Update color_print.py
HackGiter Apr 27, 2024
b9ea7de
Update color_print.py
HackGiter Apr 27, 2024
1616996
Update color_print.py
HackGiter Apr 27, 2024
04ed030
Update checkers.py
HackGiter Apr 27, 2024
99f0e7e
Update gadget.py
HackGiter Apr 27, 2024
3eccb26
Update color_print.py
HackGiter Apr 27, 2024
892bffc
Update cnv.py
HackGiter Apr 27, 2024
9291011
Update gadget.py
HackGiter Apr 27, 2024
2b45e67
Update color_print.py
HackGiter Apr 27, 2024
640d499
Update color_print.py
HackGiter Apr 27, 2024
0769a09
Update color_print.py
HackGiter Apr 27, 2024
5b7db7b
Rename README.md to README-org.md
HackGiter Apr 27, 2024
bee6e12
Create README.md
HackGiter Apr 27, 2024
bb96f44
Update .gitignore
HackGiter Apr 27, 2024
caa48cc
Delete README.md
HackGiter Apr 27, 2024
0f9a6ca
Rename README-org.md to README.md
HackGiter Apr 27, 2024
b0f0e67
Create README-org.md
HackGiter Apr 27, 2024
32b760b
Delete README-org.md
HackGiter Apr 27, 2024
aced0c1
Update .gitignore
HackGiter Apr 27, 2024
357e200
Update README.md
HackGiter Apr 27, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ venv/
# programming languages
*.pyc
*.o

1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
22321268
<p align="center">
<img src="images/metarget-logo.svg" alt="metarget-logo" height="250" />
</p>
Expand Down
34 changes: 17 additions & 17 deletions cmds/cnv.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ def install(args):
if installed_flag:
color_print.debug(
'{vuln} already installed'.format(
vuln=vuln['name']))
vuln=vuln['name']), type=3)
return
color_print.debug(
'{vuln} is going to be installed'.format(
vuln=vuln['name']))
vuln=vuln['name']), type=3)
color_print.debug('uninstalling current docker gadgets if applicable')
DockerInstaller.uninstall(verbose=args.verbose)
if not DockerInstaller.install_by_version(
Expand All @@ -81,14 +81,14 @@ def install(args):
else:
color_print.debug(
'{v} successfully installed'.format(
v=vuln['name']))
v=vuln['name']), type=1)

if vuln['class'] == 'kubernetes':
if checkers.kubernetes_specified_installed(
vuln['dependencies'], verbose=args.verbose):
color_print.debug(
'{vuln} already installed'.format(
vuln=vuln['name']))
vuln=vuln['name']), type=3)
return
if not checkers.docker_installed(verbose=args.verbose):
color_print.error(
Expand All @@ -97,7 +97,7 @@ def install(args):
'you can run `metarget gadget install docker --version 18.03.1` to install one')
color_print.debug(
'{vuln} is going to be installed'.format(
vuln=vuln['name']))
vuln=vuln['name']), type=3)
color_print.debug('uninstalling current kubernetes if applicable')
KubernetesInstaller.uninstall(verbose=args.verbose)
temp_pod_network_cidr = args.pod_network_cidr if args.pod_network_cidr else config.cni_plugin_cidrs[
Expand All @@ -119,18 +119,18 @@ def install(args):
else:
color_print.debug(
'{v} successfully installed'.format(
v=vuln['name']))
v=vuln['name']), type=1)

if vuln['class'] == 'kernel':
if checkers.kernel_specified_installed(
vuln['dependencies'], verbose=args.verbose):
color_print.debug(
'{vuln} already installed'.format(
vuln=vuln['name']))
vuln=vuln['name']), type=3)
return
color_print.debug(
'{vuln} is going to be installed'.format(
vuln=vuln['name']))
vuln=vuln['name']), type=3)

if not KernelInstaller.install_by_version(
gadgets=vuln['dependencies'], verbose=args.verbose):
Expand All @@ -140,9 +140,9 @@ def install(args):
else:
color_print.debug(
'{v} successfully installed'.format(
v=vuln['name']))
v=vuln['name']), type=1)
# reboot
reboot = color_print.debug_input('reboot system now? (y/n) ')
reboot = color_print.debug_input('reboot system now? (y/n) ', type=1)
if reboot == 'y' or reboot == 'Y':
system_func.reboot_system(verbose=args.verbose)

Expand All @@ -153,7 +153,7 @@ def install(args):
verbose=args.verbose):
color_print.debug(
'{vuln} already installed'.format(
vuln=vuln['name']))
vuln=vuln['name']), type=3)
return
if not checkers.docker_installed(verbose=args.verbose):
color_print.error(
Expand All @@ -163,7 +163,7 @@ def install(args):

color_print.debug(
'{vuln} is going to be installed'.format(
vuln=vuln['name']))
vuln=vuln['name']), type=3)

color_print.debug('uninstalling current kata-containers if applicable')
KataContainersInstaller.uninstall(verbose=args.verbose)
Expand All @@ -181,7 +181,7 @@ def install(args):
else:
color_print.debug(
'{v} successfully installed'.format(
v=vuln['name']))
v=vuln['name']), type=1)


def remove(args):
Expand Down Expand Up @@ -217,21 +217,21 @@ def remove(args):

color_print.debug(
'{vuln} is going to be removed'.format(
vuln=vuln['name']))
vuln=vuln['name']), type=3)

if vuln['class'].startswith('docker'):
DockerInstaller.uninstall(verbose=args.verbose)
color_print.debug('{v} successfully removed'.format(v=vuln['name']))
color_print.debug('{v} successfully removed'.format(v=vuln['name']), type=2)

if vuln['class'] == 'kubernetes':
KubernetesInstaller.uninstall(verbose=args.verbose)
color_print.debug('{v} successfully removed'.format(v=vuln['name']))
color_print.debug('{v} successfully removed'.format(v=vuln['name']), type=2)

if vuln['class'] == 'kata-containers':
if KataContainersInstaller.uninstall(verbose=args.verbose):
color_print.debug(
'{v} successfully removed'.format(
v=vuln['name']))
v=vuln['name']), type=2)
else:
color_print.error('failed to remove {v}'.format(v=vuln['name']))

Expand Down
28 changes: 14 additions & 14 deletions cmds/gadget.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def install(args):
if checkers.docker_specified_installed(temp_gadgets):
color_print.debug(
'{gadget} with version {version} already installed'.format(
gadget=args.gadget, version=args.version))
gadget=args.gadget, version=args.version), type=3)
return
color_print.debug('uninstalling current docker if applicable')
DockerInstaller.uninstall(verbose=args.verbose)
Expand All @@ -54,7 +54,7 @@ def install(args):
else:
color_print.debug(
'{gadget} with version {version} successfully installed'.format(
gadget=args.gadget, version=args.version))
gadget=args.gadget, version=args.version), type=1)

if args.gadget == 'k8s':
temp_gadgets = [
Expand All @@ -66,7 +66,7 @@ def install(args):
temp_gadgets, verbose=args.verbose):
color_print.debug(
'{gadget} with version {version} already installed'.format(
gadget=args.gadget, version=args.version))
gadget=args.gadget, version=args.version), type=3)
return
if not checkers.docker_installed(verbose=args.verbose):
color_print.error(
Expand All @@ -92,7 +92,7 @@ def install(args):
else:
color_print.debug(
'{gadget} successfully installed'.format(
gadget=args.gadget))
gadget=args.gadget), type=1)

if args.gadget == 'kata':
temp_gadgets = [
Expand All @@ -102,7 +102,7 @@ def install(args):
temp_gadgets, kata_runtime_type=args.kata_runtime_type, verbose=args.verbose):
color_print.debug(
'{gadget} with version {version} already installed'.format(
gadget=args.gadget, version=args.version))
gadget=args.gadget, version=args.version), type=3)
return
if not checkers.docker_installed(verbose=args.verbose):
color_print.error(
Expand All @@ -119,7 +119,7 @@ def install(args):
else:
color_print.debug(
'{gadget} with version {version} (runtime type: {runtime_type}) successfully installed'.format(
gadget=args.gadget, version=args.version, runtime_type=args.kata_runtime_type))
gadget=args.gadget, version=args.version, runtime_type=args.kata_runtime_type), type=1)

if args.gadget == 'kernel':
temp_gadgets = [
Expand All @@ -129,7 +129,7 @@ def install(args):
temp_gadgets, verbose=args.verbose):
color_print.debug(
'{gadget} with version {version} already installed'.format(
gadget=args.gadget, version=args.version))
gadget=args.gadget, version=args.version), type=3)
return
if not KernelInstaller.install_by_version(
temp_gadgets, verbose=args.verbose):
Expand All @@ -139,9 +139,9 @@ def install(args):
else:
color_print.debug(
'{gadget} successfully installed'.format(
gadget=args.gadget))
gadget=args.gadget), type=1)
# reboot
reboot = color_print.debug_input('reboot system now? (y/n) ')
reboot = color_print.debug_input('reboot system now? (y/n) ', type=1)
if reboot == 'y' or reboot == 'Y':
system_func.reboot_system(verbose=args.verbose)

Expand All @@ -160,17 +160,17 @@ def remove(args):
DockerInstaller.uninstall(verbose=args.verbose)
color_print.debug(
'{gadget} successfully removed'.format(
gadget=args.gadget))
gadget=args.gadget), type=2)
if args.gadget == 'k8s':
KubernetesInstaller.uninstall(verbose=args.verbose)
color_print.debug(
'{gadget} successfully removed'.format(
gadget=args.gadget))
gadget=args.gadget), type=2)
if args.gadget == 'kata':
if KataContainersInstaller.uninstall(verbose=args.verbose):
color_print.debug(
'{gadget} successfully removed'.format(
gadget=args.gadget))
gadget=args.gadget), type=2)
else:
color_print.error(
'failed to remove {gadget}'.format(
Expand All @@ -182,9 +182,9 @@ def remove(args):
if KernelInstaller.uninstall(temp_gadgets, verbose=args.verbose):
color_print.debug(
'{gadget} successfully removed'.format(
gadget=args.gadget))
gadget=args.gadget), type=2)
# reboot
reboot = color_print.debug_input('reboot system now? (y/n) ')
reboot = color_print.debug_input('reboot system now? (y/n) ', type=1)
if reboot == 'y' or reboot == 'Y':
system_func.reboot_system(verbose=args.verbose)
else:
Expand Down
6 changes: 3 additions & 3 deletions cmds/internal.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def deploy_vuln_resources_in_k8s(

color_print.debug(
'{vuln} is going to be installed'.format(
vuln=vuln['name']))
vuln=vuln['name']), type=3)
yamls = [os.path.join(vuln['path'], dependency)
for dependency in vuln['dependencies']['yamls']]
# some appv need hostPath volumes
Expand Down Expand Up @@ -86,7 +86,7 @@ def deploy_vuln_resources_in_k8s(
'failed to install {v}'.format(
v=vuln['name']))
else:
color_print.debug('{v} successfully installed'.format(v=vuln['name']))
color_print.debug('{v} successfully installed'.format(v=vuln['name']), tyype=1)


def delete_vuln_resources_in_k8s(vuln, verbose=False):
Expand All @@ -104,7 +104,7 @@ def delete_vuln_resources_in_k8s(vuln, verbose=False):
"""
color_print.debug(
'{vuln} is going to be removed'.format(
vuln=vuln['name']))
vuln=vuln['name']), type=3)
yamls = [os.path.join(vuln['path'], dependency)
for dependency in vuln['dependencies']['yamls']]

Expand Down
4 changes: 2 additions & 2 deletions core/env_managers/installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ def _pull_image(cls, image, mappings=None, verbose=False):
except subprocess.CalledProcessError:
return False
else:
color_print.debug('%s already pulled' % image)
color_print.debug('%s already pulled' % image, 3)

@classmethod
def _pull_domestic_images(cls, images, ori_prefix,
Expand Down Expand Up @@ -209,7 +209,7 @@ def _pull_domestic_image(cls, image, ori_prefix,
cls._pull_image(temp_image, verbose=verbose)
cls._tag_image(temp_image, image)
else:
color_print.debug('%s already pulled' % image)
color_print.debug('%s already pulled' % image, 3)

@classmethod
def _tag_images(cls, old_names, new_names):
Expand Down
4 changes: 2 additions & 2 deletions utils/checkers.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def kubernetes_installed(verbose=False):
stdout=subprocess.PIPE,
stderr=stderr,
check=True)
color_print.debug('kubernetes already installed')
color_print.debug('kubernetes already installed', type=3)
return True
except (FileNotFoundError, AttributeError, IndexError, subprocess.CalledProcessError):
return False
Expand All @@ -74,7 +74,7 @@ def docker_installed(verbose=False):
stdout=subprocess.PIPE,
stderr=stderr,
check=True)
color_print.debug('docker already installed')
color_print.debug('docker already installed', type=3)
return True
except (FileNotFoundError, AttributeError, IndexError, subprocess.CalledProcessError):
return False
Expand Down
37 changes: 32 additions & 5 deletions utils/color_print.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,33 @@
GREEN_STR = "\033[32m%s\033[0m"
YELLOW_STR = "\033[33mwarning: %s\033[0m"

# Add some new color print
BLUE_PROMPT = "\033[34m[\033[0m%s\033[34m]\033[0m"
TYPE_PLUS_ = "\033[32m%s\033[0m"
TYPE_RMVS_ = "\033[31m%s\033[0m"
TYPE_USED_ = "\033[33m%s\033[0m"
TYPE_IMPR_ = "\033[95m%s\033[0m"

def debug(message, mode=0):

# Add some prompts related the info
def debug(message, mode=0, type=0):
if mode == 0:
print(GREEN_STR % message)
if type == 0:
# TYPE:0 default mode without any prompt message
print(GREEN_STR % message)
elif type == 1:
# TYPE:1 with prompt message +
# Prompt: successfully installed
print(BLUE_PROMPT % (TYPE_PLUS_ % '+') + GREEN_STR % message)
elif type == 2:
# TYPE:2 with prompt message -
# Prompt: successfully uninstalled/remove
print(BLUE_PROMPT % (TYPE_RMVS_ % '-') + GREEN_STR % message)
elif type == 3:
# TYPE:3 with prompt message *
# Prompt: message about already installed
# Prompt: going to install/remove
print(BLUE_PROMPT % (TYPE_USED_ % '*') + GREEN_STR % message)
elif mode == 1:
print(RED_STR % message)
elif mode == 2:
Expand All @@ -21,10 +44,13 @@ def debug(message, mode=0):
print(message)
return


def debug_input(message, mode=0):
# Add prompts related to important confirmations
def debug_input(message, mode=0, type=0):
if mode == 0:
res = input(GREEN_STR % message)
if type == 0:
res = input(GREEN_STR % message)
elif type == 1:
res = input(BLUE_PROMPT % (TYPE_IMPR_ % "!") + GREEN_STR % message)
elif mode == 1:
res = input(RED_STR % message)
elif mode == 2:
Expand All @@ -50,3 +76,4 @@ def warning(message):
if __name__ == '__main__':
debug('hello, world')
debug_input('ready to reboot system? (y/n) ')
debug_input('ready to reboot system? (y/n) ', type=1)