def run(self): self.delimiter = self.get_opt('delimiter') self.quotechar = self.get_opt('quotechar') log_option('delimiter', self.delimiter) log_option('quotechar', self.quotechar) if not self.args: self.args.append('-') args = uniq_list_ordered(self.args) for arg in args: if arg == '-': continue if not os.path.exists(arg): print("'{0}' not found".format(arg)) sys.exit(ERRORS['CRITICAL']) if os.path.isfile(arg): log_option('file', arg) elif os.path.isdir(arg): log_option('directory', os.path.abspath(arg)) else: die("path '{0}' could not be determined as either a file or directory" .format(arg)) for arg in args: self.check_path(arg) if self.failed: sys.exit(ERRORS['CRITICAL'])
def run(self): if not self.args: self.usage('no git directory args given') self.origin = self.get_opt('origin') args = uniq_list_ordered(self.args) self.branch_prefix = self.get_opt('branch_prefix') if self.branch_prefix is not None: validate_regex(self.branch_prefix, 'branch prefix') self.branch_prefix = re.compile(self.branch_prefix) for arg in args: if not os.path.exists(arg): print("'%s' not found" % arg) sys.exit(ERRORS['WARNING']) if os.path.isfile(arg): log_option('file', arg) elif os.path.isdir(arg): log_option('directory', arg) else: die("path '%s' could not be determined as either a file or directory" % arg) for arg in args: self.check_git_branches_upstream(arg) if self.status == "OK": log.info( 'SUCCESS - All Git branches are tracking the expected upstream origin branches' ) else: log.critical('FAILED') sys.exit(ERRORS['CRITICAL'])
def run(self): if not self.args: self.usage('no git directory args given') self.origin = self.get_opt('origin') args = uniq_list_ordered(self.args) self.branch_prefix = self.get_opt('branch_prefix') if self.branch_prefix is not None: validate_regex(self.branch_prefix, 'branch prefix') self.branch_prefix = re.compile(self.branch_prefix) for arg in args: if not os.path.exists(arg): print("'%s' not found" % arg) sys.exit(ERRORS['WARNING']) if os.path.isfile(arg): log_option('file', arg) elif os.path.isdir(arg): log_option('directory', arg) else: die("path '%s' could not be determined as either a file or directory" % arg) for arg in args: self.check_git_branches_upstream(arg) if self.status == "OK": log.info('SUCCESS - All Git branches are tracking the expected upstream origin branches') else: log.critical('FAILED') sys.exit(ERRORS['CRITICAL'])
def process_args(self): args = uniq_list_ordered(self.args) if not args: self.usage('no directories specified as arguments') log_option('directories', args) self.compare_by_name = self.get_opt('name') self.compare_by_size = self.get_opt('size') self.compare_by_checksum = self.get_opt('checksum') self.regex = self.get_opt('regex') self.quiet = self.get_opt('quiet') self.no_short_circuit = self.get_opt('no_short_circuit') self.include_dot_dirs = self.get_opt('include_dot_dirs') if self.regex: if '(' not in self.regex: log.info('regex no capture brackets specified, will capture entire given regex') self.regex = '(' + self.regex + ')' validate_regex(self.regex) self.re_compiled = re.compile(self.regex, re.I) if not (self.compare_by_name or self.compare_by_size or self.compare_by_checksum or self.regex): self.compare_by_name = True #self.compare_by_size = True self.compare_by_checksum = True log_option('compare by name', self.compare_by_name) log_option('compare by size', self.compare_by_size) log_option('compare by checksum', self.compare_by_checksum) log_option('compare by regex', True if self.regex else False) return args
def process_args(self): args = uniq_list_ordered(self.args) if not args: self.usage('no directories specified as arguments') log_option('directories', args) self.compare_by_name = self.get_opt('name') self.compare_by_size = self.get_opt('size') self.compare_by_checksum = self.get_opt('checksum') self.regex = self.get_opt('regex') self.quiet = self.get_opt('quiet') self.no_short_circuit = self.get_opt('no_short_circuit') self.include_dot_dirs = self.get_opt('include_dot_dirs') if self.regex: if '(' not in self.regex: log.info( 'regex no capture brackets specified, will capture entire given regex' ) self.regex = '(' + self.regex + ')' validate_regex(self.regex) self.re_compiled = re.compile(self.regex, re.I) if not (self.compare_by_name or self.compare_by_size or self.compare_by_checksum or self.regex): self.compare_by_name = True #self.compare_by_size = True self.compare_by_checksum = True log_option('compare by name', self.compare_by_name) log_option('compare by size', self.compare_by_size) log_option('compare by checksum', self.compare_by_checksum) log_option('compare by regex', True if self.regex else False) return args
def run(self): if not self.args: self.usage('no Dockerfile / directory args given') args = uniq_list_ordered(self.args) self.tag_prefix = self.get_opt('tag_prefix') if self.tag_prefix is not None: validate_regex(self.tag_prefix, 'tag prefix') self.tag_prefix = re.compile(self.tag_prefix) for arg in args: if not os.path.exists(arg): print("'%s' not found" % arg) sys.exit(ERRORS['WARNING']) if os.path.isfile(arg): log_option('file', arg) elif os.path.isdir(arg): log_option('directory', arg) else: die("path '%s' could not be determined as either a file or directory" % arg) for arg in args: self.check_git_tags_dockerfiles(arg) if self.failed: log.error('Dockerfile validation FAILED') sys.exit(ERRORS['CRITICAL']) log.info('Dockerfile validation SUCCEEDED')
def run(self): if not self.args: self.usage('no Dockerfile / directory args given') args = uniq_list_ordered(self.args) self.branch_prefix = self.get_opt('branch_prefix') if self.branch_prefix is not None: validate_regex(self.branch_prefix, 'branch prefix') self.branch_prefix = re.compile(self.branch_prefix) for arg in args: if not os.path.exists(arg): print("'%s' not found" % arg) sys.exit(ERRORS['WARNING']) if os.path.isfile(arg): log_option('file', arg) elif os.path.isdir(arg): log_option('directory', arg) else: die("path '%s' could not be determined as either a file or directory" % arg) for arg in args: self.check_git_branches_dockerfiles(arg) log.info('Total Branches: %s', len(self.branches)) log.info('Selected Branches: %s', len(self.selected_branches)) log.info('Branches checked: %s', self.branches_checked) log.info('Branches with Dockerfile checked: %s', len(self.branches_dockerfile_checked)) branches_skipped = len(self.branches_skipped) if branches_skipped > 0: log.warn( '{0} branches skipped for not matching expected naming format'. format(branches_skipped)) branches_not_checked = len(self.selected_branches) - len( self.branches_dockerfile_checked) if branches_not_checked > 1: log.warn( '{0} branches not checked (no matching Dockerfile found?)'. format(branches_not_checked)) if log.isEnabledFor(logging.DEBUG): log.debug( 'Branches with no corresponding Dockerfile found:\n%s', '\n'.join( set(self.selected_branches) - set(self.branches_dockerfile_checked))) log.info('{0} Dockerfiles checked'.format(len( self.dockerfiles_checked))) branches_failed = len(self.branches_failed) _ = '{0} Dockerfiles failed validation across {1} branches'.format( self.dockerfiles_failed, branches_failed) if branches_failed > 0: log.error(_) else: log.info(_) if self.failed: log.error('Dockerfile validation FAILED') sys.exit(ERRORS['CRITICAL']) log.info('Dockerfile validation SUCCEEDED')
def validate_common_opts(self): hosts = self.get_opt('host') self.port = self.get_opt('port') if hosts: self.host_list = [host.strip() for host in hosts.split(',') if host] self.host_list += self.args self.host_list = uniq_list_ordered(self.host_list) if not self.host_list: self.usage('no hosts specified') validate_hostport_list(self.host_list, port_optional=True) validate_port(self.port) self.port = int(self.port) self.validate_protocol_opts() self.validate_misc_opts()
def process_args(self): self.files = self.args self.prefix_length = self.get_opt('key_prefix_length') self.skip_errors = self.get_opt('skip_errors') self.sort_desc = self.get_opt('desc') self.include_timestamps = self.get_opt('include_timestamps') if self.prefix_length is not None: validate_int(self.prefix_length, 'key key prefix length', 1, 100) self.prefix_length = int(self.prefix_length) if not self.files: self.usage('no file(s) specified as arguments') self.files = uniq_list_ordered(self.files) for filename in self.files: if filename == '-': log_option('file', '<stdin>') continue validate_file(filename)
def process_options(self): hosts = self.get_opt('host') self.port = self.get_opt('port') if hosts: self.host_list = [ host.strip() for host in hosts.split(',') if host ] self.host_list += self.args self.host_list = uniq_list_ordered(self.host_list) if self.get_opt('ssl'): self.protocol = 'https' log_option('SSL', 'true') else: log_option('SSL', 'false') self.request_timeout = self.get_opt('request_timeout') validate_int(self.request_timeout, 'request timeout', 1, 60) self.validate_options()
def process_options(self): hosts = self.get_opt('host') self.port = self.get_opt('port') self.url_path = self.get_opt('url') self.regex = self.get_opt('regex') self.num_threads = self.get_opt('num_threads') self.request_timeout = self.get_opt('request_timeout') if hosts: self.host_list = [ host.strip() for host in hosts.split(',') if host ] self.host_list += self.args self.host_list = uniq_list_ordered(self.host_list) if self.get_opt('random'): log_option('random', True) shuffle(self.host_list) if self.get_opt('https'): self.protocol = 'https' # optparse returns string, even though default we gave from __init__ was int # comparison would fail without this cast if str(self.port) == '80': log.info('overriding port 80 => 443 for https') self.port = 443 elif self.get_opt('http'): self.protocol = 'http' if not self.port: self.port = 80 if self.get_opt('ping'): if self.protocol: self.usage( 'cannot specify --ping with --http / --https, mutually exclusive tests!' ) elif self.port != self.default_port: self.usage( 'cannot specify --port with --ping, mutually exclusive options!' ) self.protocol = 'ping' if self.url_path: if self.protocol is None: self.protocol = 'http' elif self.protocol == 'ping': self.usage( 'cannot specify --url-path with --ping, mutually exclusive options!' ) validate_int(self.request_timeout, 'request timeout', 1, 60) self.validate_options()
def run(self): if not self.args: self.usage('no Dockerfile / directory args given') args = uniq_list_ordered(self.args) self.branch_prefix = self.get_opt('branch_prefix') if self.branch_prefix is not None: validate_regex(self.branch_prefix, 'branch prefix') self.branch_prefix = re.compile(self.branch_prefix) for arg in args: if not os.path.exists(arg): print("'%s' not found" % arg) sys.exit(ERRORS['WARNING']) if os.path.isfile(arg): log_option('file', arg) elif os.path.isdir(arg): log_option('directory', arg) else: die("path '%s' could not be determined as either a file or directory" % arg) for arg in args: self.check_git_branches_dockerfiles(arg) log.info('Total Branches: %s', len(self.branches)) log.info('Selected Branches: %s', len(self.selected_branches)) log.info('Branches checked: %s', self.branches_checked) log.info('Branches with Dockerfile checked: %s', len(self.branches_dockerfile_checked)) branches_skipped = len(self.branches_skipped) if branches_skipped > 0: log.warn('{0} branches skipped for not matching expected naming format' .format(branches_skipped)) branches_not_checked = len(self.selected_branches) - len(self.branches_dockerfile_checked) if branches_not_checked > 1: log.warn('{0} branches not checked (no matching Dockerfile found?)'.format(branches_not_checked)) if log.isEnabledFor(logging.DEBUG): log.debug('Branches with no corresponding Dockerfile found:\n%s', '\n'.join(set(self.selected_branches) - set(self.branches_dockerfile_checked))) log.info('{0} Dockerfiles checked'.format(len(self.dockerfiles_checked))) branches_failed = len(self.branches_failed) _ = '{0} Dockerfiles failed validation across {1} branches'.format(self.dockerfiles_failed, branches_failed) if branches_failed > 0: log.error(_) else: log.info(_) if self.failed: log.error('Dockerfile validation FAILED') sys.exit(ERRORS['CRITICAL']) log.info('Dockerfile validation SUCCEEDED')
def run(self): if not self.args: self.args.append("-") args = uniq_list_ordered(self.args) for arg in args: if arg == "-": continue if not os.path.exists(arg): print("'%s' not found" % arg) sys.exit(ERRORS["WARNING"]) if os.path.isfile(arg): log_option("file", arg) elif os.path.isdir(arg): log_option("directory", arg) else: die("path '%s' could not be determined as either a file or directory" % arg) for arg in args: self.check_path(arg)
def run(self): if not self.args: self.args.append('-') args = uniq_list_ordered(self.args) for arg in args: if arg == '-': continue if not os.path.exists(arg): print("'%s' not found" % arg) sys.exit(ERRORS['CRITICAL']) if os.path.isfile(arg): log_option('file', arg) elif os.path.isdir(arg): log_option('directory', os.path.abspath(arg)) else: die("path '%s' could not be determined as either a file or directory" % arg) for arg in args: self.check_path(arg)
def process_args(self): self.skip_errors = self.get_opt('continue') self.quick = self.get_opt('quick') self.regex = self.get_opt('regex') args = uniq_list_ordered(self.args) if not args: self.usage('no files/dirs specified') log_option('files/dirs', args) log_option('regex', self.regex) log_option('quick', self.quick) log_option('continue-on-error', self.skip_errors) if self.regex: validate_regex(self.regex) self.regex = re.compile(self.regex, re.I) if self.quick: self.validate_cmd = 'ffprobe' if not which(self.validate_cmd.split()[0]): die('ffmpeg / ffprobe not found in $PATH') return args
def run(self): self.permit_single_quotes = self.get_opt('permit_single_quotes') self.continue_on_error = self.get_opt('continue_on_error') log_option('permit single quotes', self.permit_single_quotes) log_option('continue on error', self.continue_on_error) if not self.args: self.args.append('-') args = uniq_list_ordered(self.args) # this will given a list of inputs at the start of the program for arg in args: log_option('path', arg) if arg == '-': continue if not os.path.exists(arg): print("'{0}' not found".format(arg)) sys.exit(ERRORS['CRITICAL']) for arg in args: self.process_path(arg) if self.failed: sys.exit(ERRORS['CRITICAL'])
def run(self): if not self.args: self.args.append('-') args = uniq_list_ordered(self.args) for arg in args: if arg == '-': continue if not os.path.exists(arg): print("'%s' not found" % arg) sys.exit(ERRORS['WARNING']) if os.path.isfile(arg): log_option('file', arg) elif os.path.isdir(arg): log_option('directory', arg) else: die("path '%s' could not be determined as either a file or directory" % arg) for arg in args: self.check_path(arg) if self.failed: sys.exit(ERRORS['CRITICAL'])
def run(self): if not self.args: self.usage('no Dockerfile / directory args given') args = uniq_list_ordered(self.args) self.branch_prefix = self.get_opt('branch_prefix') if self.branch_prefix is not None: validate_regex(self.branch_prefix, 'branch prefix') self.branch_prefix = re.compile(self.branch_prefix) for arg in args: if not os.path.exists(arg): print("'%s' not found" % arg) sys.exit(ERRORS['WARNING']) if os.path.isfile(arg): log_option('file', arg) elif os.path.isdir(arg): log_option('directory', arg) else: die("path '%s' could not be determined as either a file or directory" % arg) for arg in args: self.check_git_branches_dockerfiles(arg) branches_skipped = len(self.branches_skipped) if branches_skipped > 0: log.warn( '{0} branches skipped for not matching expected naming format'. format(branches_skipped)) log.info('{0} Dockerfiles checked across {1} branches'.format( len(self.dockerfiles_checked), self.branches_checked)) branches_failed = len(self.branches_failed) _ = '{0} Dockerfiles failed validation across {1} branches'.format( self.dockerfiles_failed, branches_failed) if branches_failed > 0: log.error(_) else: log.info(_) if self.failed: log.error('Dockerfile validation FAILED') sys.exit(ERRORS['CRITICAL']) log.info('Dockerfile validation SUCCEEDED')
def run(self): self.permit_single_quotes = self.get_opt('permit_single_quotes') self.passthru = self.get_opt('passthru') if not self.args: self.args.append('-') args = uniq_list_ordered(self.args) for arg in args: if arg == '-': continue if not os.path.exists(arg): print("'%s' not found" % arg) sys.exit(ERRORS['CRITICAL']) if os.path.isfile(arg): log_option('file', arg) elif os.path.isdir(arg): log_option('directory', arg) else: die("path '%s' could not be determined as either a file or directory" % arg) for arg in args: self.check_path(arg) if self.failed: sys.exit(ERRORS['CRITICAL'])
def process_options(self): hosts = self.get_opt('host') self.port = self.get_opt('port') self.url_path = self.get_opt('url') self.regex = self.get_opt('regex') self.num_threads = self.get_opt('num_threads') self.request_timeout = self.get_opt('request_timeout') if hosts: self.host_list = [host.strip() for host in hosts.split(',') if host] self.host_list += self.args self.host_list = uniq_list_ordered(self.host_list) if self.get_opt('random'): log_option('random', True) shuffle(self.host_list) if self.get_opt('https'): self.protocol = 'https' # optparse returns string, even though default we gave from __init__ was int # comparison would fail without this cast if str(self.port) == '80': log.info('overriding port 80 => 443 for https') self.port = 443 elif self.get_opt('http'): self.protocol = 'http' if not self.port: self.port = 80 if self.get_opt('ping'): if self.protocol: self.usage('cannot specify --ping with --http / --https, mutually exclusive tests!') elif self.port != self.default_port: self.usage('cannot specify --port with --ping, mutually exclusive options!') self.protocol = 'ping' if self.url_path: if self.protocol is None: self.protocol = 'http' elif self.protocol == 'ping': self.usage('cannot specify --url-path with --ping, mutually exclusive options!') self.validate_options()
def run(self): if not self.args: self.usage("no Dockerfile / directory args given") args = uniq_list_ordered(self.args) self.tag_prefix = self.get_opt("tag_prefix") if self.tag_prefix is not None: validate_regex(self.tag_prefix, "tag prefix") self.tag_prefix = re.compile(self.tag_prefix) for arg in args: if not os.path.exists(arg): print("'%s' not found" % arg) sys.exit(ERRORS["WARNING"]) if os.path.isfile(arg): log_option("file", arg) elif os.path.isdir(arg): log_option("directory", arg) else: die("path '%s' could not be determined as either a file or directory" % arg) for arg in args: self.check_git_tags_dockerfiles(arg) if self.failed: log.error("Dockerfile validation FAILED") sys.exit(ERRORS["CRITICAL"]) log.info("Dockerfile validation SUCCEEDED")
def run(self): self.delimiter = self.get_opt('delimiter') self.quotechar = self.get_opt('quotechar') log_option('delimiter', self.delimiter) log_option('quotechar', self.quotechar) if not self.args: self.args.append('-') args = uniq_list_ordered(self.args) for arg in args: if arg == '-': continue if not os.path.exists(arg): print("'{0}' not found".format(arg)) sys.exit(ERRORS['WARNING']) if os.path.isfile(arg): log_option('file', arg) elif os.path.isdir(arg): log_option('directory', arg) else: die("path '{0}' could not be determined as either a file or directory".format(arg)) for arg in args: self.check_path(arg) if self.failed: sys.exit(ERRORS['CRITICAL'])
def run(self): if not self.args: self.usage('no Dockerfile / directory args given') args = uniq_list_ordered(self.args) self.branch_prefix = self.get_opt('branch_prefix') if self.branch_prefix is not None: validate_regex(self.branch_prefix, 'branch prefix') self.branch_prefix = re.compile(self.branch_prefix) for arg in args: if not os.path.exists(arg): print("'%s' not found" % arg) sys.exit(ERRORS['WARNING']) if os.path.isfile(arg): log_option('file', arg) elif os.path.isdir(arg): log_option('directory', arg) else: die("path '%s' could not be determined as either a file or directory" % arg) for arg in args: self.check_git_branches_dockerfiles(arg) branches_skipped = len(self.branches_skipped) if branches_skipped > 0: log.warn('{0} branches skipped for not matching expected naming format' .format(branches_skipped)) log.info('{0} Dockerfiles checked across {1} branches' .format(len(self.dockerfiles_checked), self.branches_checked)) branches_failed = len(self.branches_failed) _ = '{0} Dockerfiles failed validation across {1} branches'.format(self.dockerfiles_failed, branches_failed) if branches_failed > 0: log.error(_) else: log.info(_) if self.failed: log.error('Dockerfile validation FAILED') sys.exit(ERRORS['CRITICAL']) log.info('Dockerfile validation SUCCEEDED')