-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wip: migrating Jake to use cyclonedx-python-lib and ossindex-lib
Signed-off-by: Paul Horton <phorton@sonatype.com>
- Loading branch information
Showing
32 changed files
with
1,203 additions
and
2,041 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -161,3 +161,6 @@ dmypy.json | |
/.circleci/local-config.yml | ||
|
||
.DS_Store | ||
|
||
# .sonatype-config for VS Code plugin | ||
.sonatype-config |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
#!/usr/bin/env python | ||
# encoding: utf-8 | ||
|
||
# | ||
# Copyright 2019-Present Sonatype Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
import argparse | ||
import os | ||
import sys | ||
from datetime import datetime | ||
from typing import Dict | ||
|
||
import pkg_resources | ||
from pyfiglet import figlet_format | ||
from termcolor import cprint | ||
|
||
from command import BaseCommand | ||
from command.config import ConfigCommand | ||
from command.iq import IqCommand | ||
from command.oss import OssCommand | ||
from command.sbom import SbomCommand | ||
|
||
|
||
class JakeCmd: | ||
# Whether debug output is enabled | ||
_DEBUG_ENABLED: bool = False | ||
|
||
# Argument Parser | ||
_arg_parser: argparse.ArgumentParser | ||
|
||
# Parsed Arguments | ||
_arguments: argparse.Namespace | ||
|
||
# Sub Commands | ||
_subcommands: Dict[str, BaseCommand] = [] | ||
|
||
def __init__(self): | ||
# Build and parse command arguments | ||
self._load_subcommands() | ||
self._build_arg_parser() | ||
self._parse_arguments() | ||
|
||
if self._arguments.debug_enabled: | ||
self._DEBUG_ENABLED = True | ||
self._debug_message('!!! DEBUG MODE ENABLED !!!') | ||
self._debug_message('Parsed Arguments: {}'.format(self._arguments)) | ||
|
||
def execute(self): | ||
# Show the Jake header | ||
JakeCmd._print_jake_header() | ||
|
||
# Determine primary command and then hand off to that Command handler | ||
command = self._subcommands[self._arguments.cmd] | ||
command.execute(arguments=self._arguments) | ||
|
||
def _load_subcommands(self): | ||
self._subcommands = { | ||
# 'config': ConfigCommand(), | ||
'iq': IqCommand(), | ||
'oss': OssCommand(), | ||
'sbom': SbomCommand() | ||
} | ||
|
||
def _build_arg_parser(self): | ||
self._arg_parser = argparse.ArgumentParser(description='CycloneDX SBOM Generator') | ||
|
||
# Add global options | ||
self._arg_parser.add_argument('-v', '--version', help='show which version of jake you are running', | ||
action='version', | ||
version='%{prog}s 1.0-dev') | ||
self._arg_parser.add_argument('-X', action='store_true', help='enable debug output', dest='debug_enabled') | ||
|
||
subparsers = self._arg_parser.add_subparsers(title='Jake sub-commands', dest='cmd', metavar='') | ||
for subcommand in self._subcommands.keys(): | ||
self._subcommands[subcommand].setup_argument_parser(subparsers=subparsers) | ||
|
||
def _debug_message(self, message: str): | ||
if self._DEBUG_ENABLED: | ||
print('[DEBUG] - {} - {}'.format(datetime.now(), message)) | ||
|
||
@staticmethod | ||
def _get_jake_version(): | ||
return pkg_resources.get_distribution('jake').version | ||
|
||
@staticmethod | ||
def _print_jake_header(): | ||
""" Prints the banner, most of the user facing commands start with this """ | ||
cprint(figlet_format('Jake', font='isometric4'), 'green', attrs=[]) | ||
cprint(figlet_format('..the snake..', font='invita'), 'blue', attrs=['dark']) | ||
print("Jake version: v{}".format(JakeCmd._get_jake_version())) | ||
print('Put your python dependencies in a chokehold.') | ||
print('') | ||
|
||
@staticmethod | ||
def _error_and_exit(message: str, exit_code: int = 1): | ||
print('[ERROR] - {} - {}'.format(datetime.now(), message)) | ||
exit(exit_code) | ||
|
||
def _parse_arguments(self): | ||
self._arguments = self._arg_parser.parse_args() | ||
|
||
|
||
def main(): | ||
JakeCmd().execute() | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import argparse | ||
from abc import ABC, abstractmethod | ||
|
||
|
||
class BaseCommand(ABC): | ||
# Parsed Arguments | ||
_arguments: argparse.Namespace | ||
|
||
@abstractmethod | ||
def handle_args(self): | ||
pass | ||
|
||
def execute(self, arguments: argparse.Namespace): | ||
self._arguments = arguments | ||
self.handle_args() | ||
|
||
@abstractmethod | ||
def setup_argument_parser(self, subparsers: argparse._SubParsersAction): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import argparse | ||
from . import BaseCommand | ||
|
||
|
||
class ConfigCommand(BaseCommand): | ||
|
||
def setup_argument_parser(self, subparsers: argparse._SubParsersAction): | ||
parser_config: argparse.ArgumentParser = subparsers.add_parser( | ||
'config', | ||
help='configure jake for OSS Index or Nexus Lifecycle access' | ||
) | ||
|
||
parser_config.add_argument('oss', help='configure Nexus IQ Server or OSSIndex', nargs='?', | ||
choices=('iq', 'oss')) | ||
|
||
# iq_group = parser_config.add_argument_group('iq') | ||
# iq_group. | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import argparse | ||
from . import BaseCommand | ||
|
||
|
||
class IqCommand(BaseCommand): | ||
|
||
def handle_args(self): | ||
pass | ||
|
||
def setup_argument_parser(self, subparsers: argparse._SubParsersAction): | ||
parser: argparse.ArgumentParser = subparsers.add_parser('iq', help='perform a scan backed by Nexus Lifecycle') | ||
|
||
parser.add_argument('-s', '--server-url', help='Full http(s):// URL to your Nexus Lifecycle server', | ||
metavar='https://localhost:8070', required=True, dest='iq_server_url') | ||
|
||
parser.add_argument('-i', '--application-id', help='Public Application ID in Nexus Lifecycle', | ||
metavar='APP_ID', required=True, dest='iq_application_id') | ||
|
||
parser.add_argument('-u', '--username', help='Username for authentication to Nexus Lifecycle', | ||
metavar='USER_ID', required=True, dest='iq_username') | ||
|
||
parser.add_argument('-p', '--password', help='Password for authentication to Nexus Lifecycle', | ||
metavar='PASSWORD', required=True, dest='iq_password') | ||
|
Oops, something went wrong.