Ejemplo n.º 1
0
    def Run(self, args):
        """This is what gets called when the user runs this command.

    Args:
      args: an argparse namespace. All the arguments that were provided to this
        command invocation.

    Raises:
      InvalidImageNameError: If the user specified an invalid image name.
    Returns:
      Some value that we want to have printed later.
    """

        try:
            img_name = util.GetDigestFromName(args.image_name)
            return util.TransformContainerAnalysisData(img_name,
                                                       args.occurrence_filter)
        except docker_http.V2DiagnosticException as err:
            raise util.GcloudifyRecoverableV2Errors(
                err, {
                    403:
                    'Describe failed, access denied: {0}'.format(
                        args.image_name),
                    404:
                    'Describe failed, not found: {0}'.format(args.image_name)
                })
Ejemplo n.º 2
0
  def Run(self, args):
    """This is what gets called when the user runs this command.

    Args:
      args: an argparse namespace. All the arguments that were provided to this
        command invocation.

    Raises:
      InvalidImageNameError: If the user specified an invalid image name.
    Returns:
      Some value that we want to have printed later.
    """

    img_name = util.GetDigestFromName(args.image)

    return util.TransformContainerAnalysisData(
        img_name, args.occurrence_filter)
Ejemplo n.º 3
0
    def Run(self, args):
        """This is what gets called when the user runs this command.

    Args:
      args: an argparse namespace. All the arguments that were provided to this
        command invocation.

    Raises:
      InvalidImageNameError: If the user specified an invalid image name.
    Returns:
      Some value that we want to have printed later.
    """

        filter_kinds = []
        if args.show_build_details:
            filter_kinds.append('BUILD')
        if args.show_package_vulnerability:
            filter_kinds.append('VULNERABILITY')
            filter_kinds.append('DISCOVERY')
        if args.show_image_basis:
            filter_kinds.append('IMAGE')
        if args.show_deployment:
            filter_kinds.append('DEPLOYMENT')

        if args.show_all_metadata:
            filter_kinds = _DEFAULT_KINDS

        if filter_kinds or args.metadata_filter:
            f = filter_util.ContainerAnalysisFilter()
            f.WithKinds(filter_kinds)
            f.WithCustomFilter(args.metadata_filter)
            f.WithResources(['https://{}'.format(args.image_name)])

            with util.WrapExpectedDockerlessErrors(args.image_name):
                img_name = util.GetDigestFromName(args.image_name)
                data = util.TransformContainerAnalysisData(img_name, f)
                # Clear out fields that weren't asked for and have no data.
                if (not data.build_details_summary.build_details
                        and not args.show_build_details
                        and not args.show_all_metadata):
                    del data.build_details_summary
                if (not data.package_vulnerability_summary.vulnerabilities
                        and not args.show_package_vulnerability
                        and not args.show_all_metadata):
                    del data.package_vulnerability_summary
                if (not data.discovery_summary.discovery
                        and not args.show_package_vulnerability
                        and not args.show_all_metadata):
                    del data.discovery_summary
                if (not data.image_basis_summary.base_images
                        and not args.show_image_basis
                        and not args.show_all_metadata):
                    del data.image_basis_summary
                if (not data.deployment_summary.deployments
                        and not args.show_deployment
                        and not args.show_all_metadata):
                    del data.deployment_summary
                return data
        else:
            with util.WrapExpectedDockerlessErrors(args.image_name):
                img_name = util.GetDigestFromName(args.image_name)
                return container_data_util.ContainerData(
                    registry=img_name.registry,
                    repository=img_name.repository,
                    digest=img_name.digest)
Ejemplo n.º 4
0
    def Run(self, args):
        """This is what gets called when the user runs this command.

    Args:
      args: an argparse namespace. All the arguments that were provided to this
        command invocation.

    Raises:
      InvalidImageNameError: If the user specified an invalid image name.
    Returns:
      Some value that we want to have printed later.
    """

        filter_kinds = []
        if args.show_build_details:
            filter_kinds.append('BUILD_DETAILS')
        if args.show_package_vulnerability:
            filter_kinds.append('PACKAGE_VULNERABILITY')
        if args.show_image_basis:
            filter_kinds.append('IMAGE_BASIS')
        if args.show_deployment:
            filter_kinds.append('DEPLOYABLE')

        if args.show_all_metadata:
            filter_kinds = _DEFAULT_KINDS

        if filter_kinds or args.metadata_filter:
            if filter_kinds:
                filter_from_flags = ' OR '.join(
                    ['kind = "{kind}"'.format(kind=fk) for fk in filter_kinds])

                if not args.metadata_filter:
                    occ_filter = filter_from_flags
                else:
                    occ_filter = '({occf}) AND ({flagf})'.format(
                        occf=args.metadata_filter, flagf=filter_from_flags)
            else:
                occ_filter = args.metadata_filter

            with RecoverFromDiagnosticException(args.image_name):
                img_name = util.GetDigestFromName(args.image_name)
                data = util.TransformContainerAnalysisData(
                    img_name,
                    occ_filter,
                    deployments=(args.show_deployment
                                 or args.show_all_metadata))
                # Clear out fields that weren't asked for and have no data.
                if (not data.build_details_summary.build_details
                        and not args.show_build_details
                        and not args.show_all_metadata):
                    del data.build_details_summary
                if (not data.package_vulnerability_summary.vulnerabilities
                        and not args.show_package_vulnerability
                        and not args.show_all_metadata):
                    del data.package_vulnerability_summary
                if (not data.image_basis_summary.base_images
                        and not args.show_image_basis
                        and not args.show_all_metadata):
                    del data.image_basis_summary
                if (not data.deployment_summary.deployments
                        and not args.show_deployment
                        and not args.show_all_metadata):
                    del data.deployment_summary
                return data
        else:
            with RecoverFromDiagnosticException(args.image_name):
                img_name = util.GetDigestFromName(args.image_name)
                return container_data_util.ContainerData(
                    registry=img_name.registry,
                    repository=img_name.repository,
                    digest=img_name.digest)