Skip to content
This repository has been archived by the owner on Feb 15, 2024. It is now read-only.

Commit

Permalink
Merge pull request #270 from RedHatProductSecurity/various-improvements
Browse files Browse the repository at this point in the history
Various improvements
  • Loading branch information
JakubFrejlach authored Nov 22, 2023
2 parents caf278a + 85dae72 commit 26324d8
Show file tree
Hide file tree
Showing 31 changed files with 837 additions and 488 deletions.
33 changes: 26 additions & 7 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,22 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased
### changed
* existing --search-upstreams changed to --search-all-upstreams in
### Changed
* existing --search-upstreams changed to --search-all-upstreams in
service products-contain-component
* OSIDB_API_URL environment variable changed to OSIDB_SERVER_URL
* CORGI_API_URL environment variable changed to CORGI_SERVER_URL

### Added
* --search-provides in service products-contain-component which
will search name of components that are provide dependencies
* --search-upstreams in service products-contain-component which
will search name of components that are upstream dependencies
* example plugin introduced

### Fixed
* standardized progress bar accross whole Griffon which fixes
no_progress_bar functionality

## [0.3.8] - 2023-10-18
### Added
Expand Down Expand Up @@ -76,6 +84,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [0.2.20] - 2023-08-11
### Changed
* make 'new' default for -a (when generating affects)

### Added
* --no-upstream-affects which will exclude upstream components when generating affects

Expand Down Expand Up @@ -121,19 +130,21 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [0.2.10] - 2023-06-30
### Changed
* return components in active product streams for products-contains-component operation

### Added
* --include-inactive-product-streams option for products-contains-component operation
*

## [0.2.9] - 2023-06-29
### Changed
* pin osidb-bindings 3.3.0
* update crypto python module
* fix generation of affects
* fix generation of affects

## [0.2.8] - 2023-06-28
### Added
- CRUD operations for OSIDB entities Flaw Comment (create, retreive, list),
Flaw Reference (create, retrieve, list, update, delete)

## [0.2.7] - 2023-06-14
### Changed
- ensure we choose latest version of component using products-contains-component
Expand All @@ -142,32 +153,35 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [0.2.6] - 2023-05-29
### Added
- add terminal --width flag

### Changed
- bumped python requests module in tests, dev and lint requirements to address vuln

## [0.2.5] - 2023-05-26
### Added
- minimal middleware support to products-contains-component, requires Requires GRIFFON_MIDDLEWARE_CLI to be set.

### Changed
- bumped python requests module to address vuln
- fixed products-contains-component when used with --purl

## [0.2.4] - 2023-05-25
### Added
- add --no-wrap flag

### Changed
- enhanced error handling when retrieving product streams and manifests
- fixed regex display
- fixed regex display

## [0.2.3] - 2023-05-24
### Changed
- fixed summary counts

## [0.2.2] - 2023-05-24
### Changed
- fix --search-upstreams
- fix --search-upstreams
- add summary count of sources

### Added
- bugzilla bzowner plugin

Expand All @@ -192,6 +206,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed
- allow -v at the end of CLI invoke
- prefer nvr for component name in text output

### Added
- added entities component-registry components tree which displays dependency tree

Expand All @@ -208,6 +223,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed
- deactivate progress bar when performing entity CRUD
- enabled community searching when using --search-all

### Added
- added --search-redhat

Expand Down Expand Up @@ -258,6 +274,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- simple griffon plugins semgrep
- products, product-versions, product-variants, channels to corgi entities

### Changed
- minor plugin enhancements
- minor docs updates
Expand All @@ -272,6 +289,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed
- enable OSIDB local development instances to be used with Griffon
- added editor option to .griffonrc

### Added
- CRUD operations for OSIDB entitites. Flaws (create, update, get, list),
Affects (create, update, delete, get, list), Trackers (get, list)
Expand All @@ -292,6 +310,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [0.1.8] - 2023-03-31
### Changed
- shortern sha256 versions in service product-components

### Added
- added type,latest and download_url to service component-summary operation

Expand Down
8 changes: 4 additions & 4 deletions Containerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ LABEL maintainer="Red Hat Product Security Dev - Red Hat, Inc." \
ARG PIP_INDEX_URL
ARG ROOT_CA_URL
ARG REQUESTS_CA_BUNDLE
ARG CORGI_API_URL
ARG OSIDB_API_URL
ARG CORGI_SERVER_URL
ARG OSIDB_SERVER_URL
ENV PYTHONUNBUFFERED=1 \
PIP_NO_CACHE_DIR=off \
PIP_INDEX_URL="${PIP_INDEX_URL}" \
REQUESTS_CA_BUNDLE="${REQUESTS_CA_BUNDLE}" \
ROOT_CA_URL="${ROOT_CA_URL}" \
CORGI_API_URL="${CORGI_API_URL}" \
OSIDB_API_URL="${OSIDB_API_URL}"
CORGI_SERVER_URL="${CORGI_SERVER_URL}" \
OSIDB_SERVER_URL="${OSIDB_SERVER_URL}"

RUN cd /etc/pki/ca-trust/source/anchors/ && \
# The '| true' skips this step if the ROOT_CA_URL is unset or fails in another way
Expand Down
8 changes: 4 additions & 4 deletions Containerfile-dev
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ LABEL maintainer="Red Hat Product Security Dev - Red Hat, Inc." \
ARG PIP_INDEX_URL
ARG ROOT_CA_URL
ARG REQUESTS_CA_BUNDLE
ARG CORGI_API_URL
ARG OSIDB_API_URL
ARG CORGI_SERVER_URL
ARG OSIDB_SERVER_URL
ENV PYTHONUNBUFFERED=1 \
PIP_NO_CACHE_DIR=off \
PIP_INDEX_URL="${PIP_INDEX_URL}" \
REQUESTS_CA_BUNDLE="${REQUESTS_CA_BUNDLE}" \
ROOT_CA_URL="${ROOT_CA_URL}" \
CORGI_API_URL="${CORGI_API_URL}" \
OSIDB_API_URL="${OSIDB_API_URL}"
CORGI_SERVER_URL="${CORGI_SERVER_URL}" \
OSIDB_SERVER_URL="${OSIDB_SERVER_URL}"

RUN cd /etc/pki/ca-trust/source/anchors/ && \
# The '| true' skips this step if the ROOT_CA_URL is unset or fails in another way
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ openssl=`which openssl`
# container targets
############################################################################
build-container: Containerfile
$(podman) build --build-arg CORGI_API_URL="${CORGI_API_URL}" \
--build-arg OSIDB_API_URL="${OSIDB_API_URL}" \
$(podman) build --build-arg CORGI_SERVER_URL="${CORGI_SERVER_URL}" \
--build-arg OSIDB_SERVER_URL="${OSIDB_SERVER_URL}" \
--build-arg REQUESTS_CA_BUNDLE="${REQUESTS_CA_BUNDLE}" \
--build-arg PIP_INDEX_URL="${PIP_INDEX_URL}" \
--build-arg ROOT_CA_URL="${ROOT_CA_URL}" \
Expand Down
8 changes: 4 additions & 4 deletions docs/user_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ export REQUESTS_CA_BUNDLE=/etc/pki/tls/certs/ca-bundle.crt

Set service urls.
```commandline
export OSIDB_API_URL="https://<INSERT OSIDB API URL>"
export CORGI_API_URL="https://<INSERT COMPONENT REGISTRY API URL>"
export OSIDB_SERVER_URL="https://<INSERT OSIDB API URL>"
export CORGI_SERVER_URL="https://<INSERT COMPONENT REGISTRY API URL>"
```

and the following is set to enable searching community components:
Expand Down Expand Up @@ -113,8 +113,8 @@ The container is unsupported.
First set some env vars

```commandline
export CORGI_API_URL=<INSERT COMPONENT REGISTRY URL>
export OSIDB_API_URL=<INESRT OSIDB URL>
export CORGI_SERVER_URL=<INSERT COMPONENT REGISTRY URL>
export OSIDB_SERVER_URL=<INESRT OSIDB URL>
export REQUESTS_CA_BUNDLE=<INSERT CA BUNDLE PATH>
export PIP_INDEX_URL=<INSERT PIP INDEX URL>
export ROOT_CA_URL=<INSERT ROOT CA URL >
Expand Down
98 changes: 76 additions & 22 deletions griffon/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,49 @@
import logging
import os
from configparser import ConfigParser
from contextlib import contextmanager
from functools import partial, wraps

import component_registry_bindings
import osidb_bindings
from osidb_bindings.bindings.python_client.models import Affect, Flaw, Tracker
from pkg_resources import resource_filename # type: ignore
from pkg_resources import resource_filename
from rich.logging import RichHandler

from griffon.helpers import Color, Style
from griffon.output import console

__version__ = "0.3.8"

if "CORGI_API_URL" not in os.environ:
print("Must set CORGI_API_URL environment variable.")
exit(1)
CORGI_API_URL = os.environ["CORGI_API_URL"]
# TODO: Deprecate CORGI_API_URL completely in the next version or two
if "CORGI_API_URL" in os.environ:
print(
(
f"{Style.BOLD}{Color.YELLOW}WARNING: CORGI_API_URL will be deprecated "
"in the next version of Griffon in favour of CORGI_SERVER_URL, please "
f"switch to the new environment variable.{Style.RESET}"
)
)

if "OSIDB_API_URL" not in os.environ:
print("Must set OSIDB_API_URL environment variable.")
if "CORGI_SERVER_URL" not in os.environ and "CORGI_API_URL" not in os.environ:
print("Must set CORGI_SERVER_URL environment variable.")
exit(1)
CORGI_SERVER_URL = os.getenv("CORGI_SERVER_URL", os.getenv("CORGI_API_URL"))

# TODO: Deprecate CORGI_API_URL completely in the next version or two
if "OSIDB_API_URL" in os.environ:
print(
(
f"{Style.BOLD}{Color.YELLOW}WARNING: OSIDB_API_URL will be deprecated "
"in the next version of Griffon in favour of OSIDB_SERVER_URL, please "
f"switch to the new environment variable.{Style.RESET}"
)
)
if "OSIDB_SERVER_URL" not in os.environ and "OSIDB_API_URL" not in os.environ:
print("Must set OSIDB_SERVER_URL environment variable.")
exit(1)
OSIDB_API_URL = os.environ["OSIDB_API_URL"]
OSIDB_SERVER_URL = os.getenv("OSIDB_SERVER_URL", os.getenv("OSIDB_API_URL"))

OSIDB_USERNAME = os.getenv("OSIDB_USERNAME", "")
OSIDB_PASSWORD = os.getenv("OSIDB_PASSWORD", "")
OSIDB_AUTH_METHOD = os.getenv("OSIDB_AUTH_METHOD", "kerberos")
Expand All @@ -51,11 +73,8 @@
def config_logging(level="INFO"):
# if set to 'DEBUG' then we want all the http conversation
if level == "DEBUG":
try:
import http.client as http_client
except ImportError:
# Python 2
import httplib as http_client
import http.client as http_client

http_client.HTTPConnection.debuglevel = 1

message_format = "%(asctime)s %(name)s %(levelname)s %(message)s"
Expand Down Expand Up @@ -99,10 +118,10 @@ def create_session():
"""init corgi session"""
try:
return component_registry_bindings.new_session(
component_registry_server_uri=CORGI_API_URL,
component_registry_server_uri=CORGI_SERVER_URL,
)
except: # noqa
console.log(f"{CORGI_API_URL} is not accessible.")
console.log(f"{CORGI_SERVER_URL} is not accessible.")
exit(1)

@staticmethod
Expand Down Expand Up @@ -166,9 +185,9 @@ def create_session():
if OSIDB_AUTH_METHOD == "credentials":
credentials["username"] = OSIDB_USERNAME
credentials["password"] = OSIDB_PASSWORD
return osidb_bindings.new_session(osidb_server_uri=OSIDB_API_URL, **credentials)
return osidb_bindings.new_session(osidb_server_uri=OSIDB_SERVER_URL, **credentials)
except: # noqa
console.log(f"{OSIDB_API_URL} is not accessible (or krb ticket has expired).")
console.log(f"{OSIDB_SERVER_URL} is not accessible (or krb ticket has expired).")
exit(1)

@staticmethod
Expand Down Expand Up @@ -322,6 +341,44 @@ def get_fields(model, prefix=""):
return fields


@contextmanager
def console_status(no_progress_bar):
"""updatable console status progress bar"""

class DisabledStatusObject:
"""
Dummy disabled status object for graceful handle of
no progress bar option
"""

def __getattr__(self, attr):
def dummy_method(*args, **kwargs):
pass # Do nothing when any method is called

return dummy_method

class StatusObject:
"""
Status object for default Griffon status handling
"""

def __init__(self, status):
self.status = status

def update(self, status, *args, **kwargs):
self.status.update(
status=f"[magenta b]griffoning:[/magenta b] [bold]{status}[/bold]", *args, **kwargs
)

if no_progress_bar:
yield DisabledStatusObject()
else:
with console.status(
"[magenta b]griffoning[/magenta b]", spinner="line"
) as operation_status:
yield StatusObject(operation_status)


def progress_bar(
func=None,
):
Expand All @@ -332,11 +389,8 @@ def progress_bar(
@wraps(func)
def wrapper(*args, **kwargs):
obj: dict = args[0].obj
if obj.get("NO_PROGRESS_BAR"):
func(*args, **kwargs)
else:
with console.status("griffoning", spinner="line"):
func(*args, **kwargs)
with console_status(obj.get("NO_PROGRESS_BAR")) as operation_status:
func(*args, operation_status=operation_status, **kwargs)

return wrapper

Expand Down
Loading

0 comments on commit 26324d8

Please sign in to comment.