1
0
mirror of https://github.com/checktheroads/hyperglass synced 2024-05-11 05:55:08 +00:00

style improvements

This commit is contained in:
checktheroads
2020-02-03 02:35:11 -07:00
parent 7ff8fa317d
commit edf0803a62
34 changed files with 250 additions and 266 deletions

View File

@@ -3,7 +3,7 @@ max-line-length=88
count=True
show-source=False
statistics=True
exclude=.git, __pycache__,
exclude=.git, __pycache__, hyperglass/api/examples/*.py
filename=*.py
per-file-ignores=
# Disable redefinition warning for exception handlers

View File

@@ -1,7 +1,13 @@
[settings]
skip_glob = hyperglass/api/examples/*.py
line_length = 88
indent = ' '
force_single_line = true
import_heading_stdlib = Standard Library Imports
import_heading_thirdparty = Third Party Imports
import_heading_firstparty = Project Imports
include_trailing_comma = True
multi_line_output = 3
balanced_wrapping = True
length_sort = True
force_single_line = False
import_heading_stdlib = Standard Library
import_heading_thirdparty = Third Party
import_heading_firstparty = Project
known_third_party = starlette,fastapi

View File

@@ -1,12 +1,9 @@
"""hyperglass cli module."""
# Third Party
import stackprinter
# Project Imports
from cli import commands
from cli import echo # noqa: F401
from cli import formatting # noqa: F401
from cli import static # noqa: F401
from cli import util # noqa: F401
# Project
from cli import echo, util, static, commands, formatting # noqa: F401
stackprinter.set_excepthook(style="darkbg2")

View File

@@ -1,28 +1,24 @@
#!/usr/bin/env python3
"""CLI Command definitions."""
# Standard Library Imports
# Standard Library
from pathlib import Path
# Third Party Imports
# Third Party
import click
# Project Imports
from cli.echo import cmd_help
from cli.echo import error
from cli.echo import value
from cli.formatting import HelpColorsCommand
from cli.formatting import HelpColorsGroup
from cli.formatting import random_colors
from cli.static import CLI_HELP
from cli.static import LABEL
from cli.static import E
from cli.util import build_ui
from cli.util import fix_ownership
from cli.util import fix_permissions
from cli.util import migrate_config
from cli.util import migrate_systemd
from cli.util import start_web_server
# Project
from cli.echo import error, value, cmd_help
from cli.util import (
build_ui,
fix_ownership,
migrate_config,
fix_permissions,
migrate_systemd,
start_web_server,
)
from cli.static import LABEL, CLI_HELP, E
from cli.formatting import HelpColorsGroup, HelpColorsCommand, random_colors
# Define working directory
WORKING_DIR = Path(__file__).parent

View File

@@ -1,19 +1,21 @@
"""Helper functions for CLI message printing."""
# Third Party Imports
# Third Party
import click
# Project Imports
from cli.static import CL
from cli.static import CMD_HELP
from cli.static import ERROR
from cli.static import INFO
from cli.static import LABEL
from cli.static import NL
from cli.static import STATUS
from cli.static import SUCCESS
from cli.static import VALUE
from cli.static import WS
from cli.static import E
# Project
from cli.static import (
CL,
NL,
WS,
INFO,
ERROR,
LABEL,
VALUE,
STATUS,
SUCCESS,
CMD_HELP,
E,
)
def cmd_help(emoji="", help_text=""):

View File

@@ -24,10 +24,10 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
"""
# Standard Library Imports
# Standard Library
import random
# Third Party Imports
# Third Party
import click

View File

@@ -1,5 +1,5 @@
"""Static string definitions."""
# Third Party Imports
# Third Party
import click

View File

@@ -1,21 +1,13 @@
"""CLI utility functions."""
# Standard Library Imports
# Standard Library
from pathlib import Path
# Third Party Imports
# Third Party
import click
# Project Imports
from cli.echo import error
from cli.echo import info
from cli.echo import status
from cli.echo import success
from cli.static import CL
from cli.static import NL
from cli.static import SUCCESS
from cli.static import VALUE
from cli.static import WS
from cli.static import E
# Project
from cli.echo import info, error, status, success
from cli.static import CL, NL, WS, VALUE, SUCCESS, E
PROJECT_ROOT = Path(__file__).parent.parent

View File

@@ -36,22 +36,20 @@ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
"""
# Standard Library
# Standard Library Imports
import sys
from datetime import datetime
# Third Party
import uvloop
# Third Party Imports
import stackprinter
import uvloop
# Project
# Project Imports
# flake8: noqa: F401
from hyperglass import api
from hyperglass import configuration
from hyperglass import constants
from hyperglass import exceptions
from hyperglass import execution
from hyperglass import util
from hyperglass import api, util, constants, execution, exceptions, configuration
stackprinter.set_excepthook()

View File

@@ -1,37 +1,36 @@
"""Import configuration files and returns default values if undefined."""
# Standard Library Imports
import asyncio
import copy
import getpass
import math
# Standard Library
import os
import copy
import math
import asyncio
import getpass
from pathlib import Path
# Third Party Imports
import ujson as json
# Third Party
import yaml
import ujson as json
from aiofile import AIOFile
from pydantic import ValidationError
# Project Imports
from hyperglass.configuration.markdown import get_markdown
from hyperglass.configuration.models import commands as _commands
# Project
from hyperglass.util import log, check_path
from hyperglass.constants import (
CREDIT,
LOG_LEVELS,
LOG_HANDLER,
DEFAULT_HELP,
DEFAULT_TERMS,
DEFAULT_DETAILS,
LOG_HANDLER_FILE,
SUPPORTED_QUERY_TYPES,
)
from hyperglass.exceptions import ConfigError, ConfigInvalid, ConfigMissing
from hyperglass.configuration.models import params as _params
from hyperglass.configuration.models import routers as _routers
from hyperglass.constants import CREDIT
from hyperglass.constants import DEFAULT_DETAILS
from hyperglass.constants import DEFAULT_HELP
from hyperglass.constants import DEFAULT_TERMS
from hyperglass.constants import LOG_HANDLER
from hyperglass.constants import LOG_HANDLER_FILE
from hyperglass.constants import LOG_LEVELS
from hyperglass.constants import SUPPORTED_QUERY_TYPES
from hyperglass.exceptions import ConfigError
from hyperglass.exceptions import ConfigInvalid
from hyperglass.exceptions import ConfigMissing
from hyperglass.util import check_path
from hyperglass.util import log
from hyperglass.configuration.models import commands as _commands
from hyperglass.configuration.markdown import get_markdown
# Project Directories
WORKING_DIR = Path(__file__).resolve().parent

View File

@@ -1,9 +1,9 @@
"""Markdown processing utility functions."""
# Third Party Imports
# Third Party
from aiofile import AIOFile
# Project Imports
# Project
from hyperglass.util import log

View File

@@ -1,9 +1,9 @@
"""Utility Functions for Pydantic Models."""
# Standard Library Imports
# Standard Library
import re
# Third Party Imports
# Third Party
from pydantic import BaseModel

View File

@@ -1,16 +1,12 @@
"""Validation model for Redis cache config."""
# Standard Library Imports
# Standard Library
from typing import Union
# Third Party Imports
from pydantic import Field
from pydantic import IPvAnyAddress
from pydantic import StrictBool
from pydantic import StrictInt
from pydantic import StrictStr
# Third Party
from pydantic import Field, StrictInt, StrictStr, StrictBool, IPvAnyAddress
# Project Imports
# Project
from hyperglass.configuration.models._utils import HyperglassModel

View File

@@ -1,9 +1,9 @@
"""Validate command configuration variables."""
# Third Party Imports
# Third Party
from pydantic import StrictStr
# Project Imports
# Project
from hyperglass.configuration.models._utils import HyperglassModel

View File

@@ -1,11 +1,10 @@
"""Validate credential configuration variables."""
# Third Party Imports
# Third Party
from pydantic import SecretStr
# Project Imports
from hyperglass.configuration.models._utils import HyperglassModel
from hyperglass.configuration.models._utils import clean_name
# Project
from hyperglass.configuration.models._utils import HyperglassModel, clean_name
class Credential(HyperglassModel):

View File

@@ -1,13 +1,9 @@
"""Configuration for API docs feature."""
# Third Party Imports
from pydantic import Field
from pydantic import StrictBool
from pydantic import StrictStr
from pydantic import constr
# Third Party
from pydantic import Field, HttpUrl, StrictStr, StrictBool, constr
# Project Imports
from hyperglass.configuration.models._utils import AnyUri
from hyperglass.configuration.models._utils import HyperglassModel
# Project
from hyperglass.configuration.models._utils import AnyUri, HyperglassModel
class EndpointConfig(HyperglassModel):
@@ -37,10 +33,15 @@ class Docs(HyperglassModel):
True, title="Enable", description="Enable or disable API documentation."
)
mode: constr(regex=r"(swagger|redoc)") = Field(
"swagger",
"redoc",
title="Docs Mode",
description="OpenAPI UI library to use for the hyperglass API docs. Currently, the options are [Swagger UI](/fixme) and [Redoc](/fixme).",
)
base_url: HttpUrl = Field(
"https://lg.example.net",
title="Base URL",
description="Base URL used in request samples.",
)
uri: AnyUri = Field(
"/api/docs",
title="URI",
@@ -51,6 +52,16 @@ class Docs(HyperglassModel):
title="OpenAPI URI",
description="Path to the automatically generated `openapi.json` file.",
)
title: StrictStr = Field(
"{site_title} API Documentation",
title="Title",
description="API documentation title. `{site_title}` may be used to display the `site_title` parameter.",
)
description: StrictStr = Field(
"",
title="Description",
description="API documentation description appearing below the title.",
)
query: EndpointConfig = EndpointConfig(
title="Submit Query",
description="Request a query response per-location.",

View File

@@ -1,9 +1,10 @@
"""Validate error message configuration variables."""
# Third Party
# Third Party Imports
from pydantic import Field
from pydantic import StrictStr
from pydantic import Field, StrictStr
# Project
# Project Imports
from hyperglass.configuration.models._utils import HyperglassModel

View File

@@ -1,12 +1,12 @@
"""Validate network configuration variables."""
# Third Party
# Third Party Imports
from pydantic import Field
from pydantic import StrictStr
from pydantic import Field, StrictStr
# Project
# Project Imports
from hyperglass.configuration.models._utils import HyperglassModel
from hyperglass.configuration.models._utils import clean_name
from hyperglass.configuration.models._utils import HyperglassModel, clean_name
class Network(HyperglassModel):

View File

@@ -1,14 +1,14 @@
# Standard Library Imports
from pathlib import Path
"""Validate OpenGraph Configuration Parameters."""
# Standard Library
from typing import Optional
from pathlib import Path
# Third Party Imports
# Third Party
import PIL.Image as PilImage
from pydantic import FilePath
from pydantic import StrictInt
from pydantic import root_validator
from pydantic import FilePath, StrictInt, root_validator
# Project Imports
# Project
from hyperglass.configuration.models._utils import HyperglassModel
@@ -31,8 +31,8 @@ class OpenGraph(HyperglassModel):
"""
supported_extensions = (".jpg", ".jpeg", ".png")
if (
values["image"].suffix is not None
and values["image"] not in supported_extensions
values["image"] is not None
and values["image"].suffix not in supported_extensions
):
raise ValueError(
"OpenGraph image must be one of {e}".format(

View File

@@ -1,29 +1,29 @@
"""Configuration validation entry point."""
# Standard Library Imports
# Standard Library
from typing import List, Union, Optional
from pathlib import Path
from datetime import datetime
from ipaddress import ip_address
from pathlib import Path
from typing import List
from typing import Optional
from typing import Union
# Third Party Imports
from pydantic import Field
from pydantic import FilePath
from pydantic import IPvAnyAddress
from pydantic import StrictBool
from pydantic import StrictInt
from pydantic import StrictStr
from pydantic import validator
# Third Party
from pydantic import (
Field,
FilePath,
StrictInt,
StrictStr,
StrictBool,
IPvAnyAddress,
validator,
)
# Project Imports
from hyperglass.configuration.models._utils import HyperglassModel
from hyperglass.configuration.models.cache import Cache
from hyperglass.configuration.models.docs import Docs
from hyperglass.configuration.models.messages import Messages
from hyperglass.configuration.models.queries import Queries
# Project
from hyperglass.configuration.models.web import Web
from hyperglass.configuration.models.docs import Docs
from hyperglass.configuration.models.cache import Cache
from hyperglass.configuration.models._utils import HyperglassModel
from hyperglass.configuration.models.queries import Queries
from hyperglass.configuration.models.messages import Messages
class Params(HyperglassModel):

View File

@@ -1,15 +1,12 @@
"""Validate SSH proxy configuration variables."""
# Third Party Imports
from pydantic import StrictInt
from pydantic import StrictStr
from pydantic import validator
# Third Party
from pydantic import StrictInt, StrictStr, validator
# Project Imports
from hyperglass.configuration.models._utils import HyperglassModel
from hyperglass.configuration.models._utils import clean_name
from hyperglass.configuration.models.credentials import Credential
# Project
from hyperglass.exceptions import UnsupportedDevice
from hyperglass.configuration.models._utils import HyperglassModel, clean_name
from hyperglass.configuration.models.credentials import Credential
class Proxy(HyperglassModel):

View File

@@ -1,14 +1,11 @@
"""Validate query configuration parameters."""
# Third Party Imports
from pydantic import Field
from pydantic import StrictBool
from pydantic import StrictStr
from pydantic import constr
# Third Party
from pydantic import Field, StrictStr, StrictBool, constr
# Project Imports
from hyperglass.configuration.models._utils import HyperglassModel
# Project
from hyperglass.constants import SUPPORTED_QUERY_TYPES
from hyperglass.configuration.models._utils import HyperglassModel
class BgpCommunityPattern(HyperglassModel):

View File

@@ -1,30 +1,27 @@
"""Validate router configuration variables."""
# Standard Library Imports
# Standard Library
import re
from typing import List
from typing import Optional
from typing import List, Optional
# Third Party Imports
from pydantic import StrictInt
from pydantic import StrictStr
from pydantic import validator
# Third Party
from pydantic import StrictInt, StrictStr, validator
# Project Imports
from hyperglass.configuration.models._utils import HyperglassModel
from hyperglass.configuration.models._utils import HyperglassModelExtra
from hyperglass.configuration.models._utils import clean_name
from hyperglass.configuration.models.commands import Command
from hyperglass.configuration.models.credentials import Credential
from hyperglass.configuration.models.networks import Network
from hyperglass.configuration.models.proxies import Proxy
from hyperglass.configuration.models.ssl import Ssl
from hyperglass.configuration.models.vrfs import Info
from hyperglass.configuration.models.vrfs import Vrf
from hyperglass.constants import Supported
from hyperglass.exceptions import ConfigError
from hyperglass.exceptions import UnsupportedDevice
# Project
from hyperglass.util import log
from hyperglass.constants import Supported
from hyperglass.exceptions import ConfigError, UnsupportedDevice
from hyperglass.configuration.models.ssl import Ssl
from hyperglass.configuration.models.vrfs import Vrf, Info
from hyperglass.configuration.models._utils import (
HyperglassModel,
HyperglassModelExtra,
clean_name,
)
from hyperglass.configuration.models.proxies import Proxy
from hyperglass.configuration.models.commands import Command
from hyperglass.configuration.models.networks import Network
from hyperglass.configuration.models.credentials import Credential
_default_vrf = {
"name": "default",

View File

@@ -1,14 +1,12 @@
"""Validate SSL configuration variables."""
# Standard Library Imports
# Standard Library
from typing import Optional
# Third Party Imports
from pydantic import Field
from pydantic import FilePath
from pydantic import StrictBool
# Third Party
from pydantic import Field, FilePath, StrictBool
# Project Imports
# Project
from hyperglass.configuration.models._utils import HyperglassModel

View File

@@ -1,26 +1,23 @@
"""Validate VRF configuration variables."""
# Standard Library Imports
from ipaddress import IPv4Address
from ipaddress import IPv4Network
from ipaddress import IPv6Address
from ipaddress import IPv6Network
from typing import List
from typing import Optional
# Standard Library
from typing import List, Optional
from ipaddress import IPv4Address, IPv4Network, IPv6Address, IPv6Network
# Third Party Imports
from pydantic import Field
from pydantic import FilePath
from pydantic import StrictBool
from pydantic import StrictStr
from pydantic import conint
from pydantic import constr
from pydantic import root_validator
from pydantic import validator
# Third Party
from pydantic import (
Field,
FilePath,
StrictStr,
StrictBool,
conint,
constr,
validator,
root_validator,
)
# Project Imports
from hyperglass.configuration.models._utils import HyperglassModel
from hyperglass.configuration.models._utils import HyperglassModelExtra
# Project
from hyperglass.configuration.models._utils import HyperglassModel, HyperglassModelExtra
class AccessList4(HyperglassModel):

View File

@@ -1,25 +1,26 @@
"""Validate branding configuration variables."""
# Standard Library Imports
from pathlib import Path
# Standard Library
from typing import Optional
from pathlib import Path
# Third Party Imports
from pydantic import FilePath
from pydantic import HttpUrl
from pydantic import StrictBool
from pydantic import StrictInt
from pydantic import StrictStr
from pydantic import constr
from pydantic import root_validator
from pydantic import validator
# Third Party
from pydantic import (
HttpUrl,
FilePath,
StrictInt,
StrictStr,
StrictBool,
constr,
validator,
root_validator,
)
from pydantic.color import Color
# Project Imports
# Project
from hyperglass.constants import DNS_OVER_HTTPS, FUNC_COLOR_MAP
from hyperglass.configuration.models._utils import HyperglassModel
from hyperglass.configuration.models.opengraph import OpenGraph
from hyperglass.constants import DNS_OVER_HTTPS
from hyperglass.constants import FUNC_COLOR_MAP
class Analytics(HyperglassModel):
@@ -118,10 +119,10 @@ class Logo(HyperglassModel):
logo_light = values.get("light")
logo_dark = values.get("dark")
default_logo_light = (
Path(__file__).parent.parent.parent / "static/images/hyperglass-light.png"
Path(__file__).parent.parent.parent / "static/images/hyperglass-dark.png"
)
default_logo_dark = (
Path(__file__).parent.parent.parent / "static/images/hyperglass-dark.png"
Path(__file__).parent.parent.parent / "static/images/hyperglass-light.png"
)
# Use light logo as dark logo if dark logo is undefined.

View File

@@ -1,5 +1,5 @@
"""Constant definitions used throughout the application."""
# Standard Library Imports
# Standard Library
import sys
from datetime import datetime

View File

@@ -1,11 +1,11 @@
"""Custom exceptions for hyperglass."""
# Third Party Imports
# Third Party
import ujson as _json
# Project Imports
from hyperglass.constants import STATUS_CODE_MAP
# Project
from hyperglass.util import log
from hyperglass.constants import STATUS_CODE_MAP
class HyperglassError(Exception):

View File

@@ -4,7 +4,6 @@ Constructs SSH commands or API call parameters based on front end
input, executes the commands/calls, returns the output to front end.
"""
# Project Imports
# Project
# flake8: noqa: F401
from hyperglass.execution import construct
from hyperglass.execution import execute
from hyperglass.execution import execute, construct

View File

@@ -5,18 +5,17 @@ command for Netmiko library or API call parameters for supported
hyperglass API modules.
"""
# Standard Library Imports
import operator
# Standard Library
import re
import operator
# Third Party Imports
# Third Party
import ujson
# Project Imports
from hyperglass.configuration import commands
from hyperglass.constants import TARGET_FORMAT_SPACE
from hyperglass.constants import TRANSPORT_REST
# Project
from hyperglass.util import log
from hyperglass.constants import TRANSPORT_REST, TARGET_FORMAT_SPACE
from hyperglass.configuration import commands
class Construct:

View File

@@ -1,12 +1,12 @@
"""Handle JSON Web Token Encoding & Decoding."""
# Standard Library Imports
# Standard Library
import datetime
# Third Party Imports
# Third Party
import jwt
# Project Imports
# Project
from hyperglass.exceptions import RestError

View File

@@ -6,32 +6,34 @@ construct.py, which is used to build & run the Netmiko connectoins or
hyperglass-frr API calls, returns the output back to the front end.
"""
# Standard Library Imports
# Standard Library
import re
import signal
# Third Party Imports
# Third Party
import httpx
import sshtunnel
from netmiko import ConnectHandler
from netmiko import NetMikoAuthenticationException
from netmiko import NetmikoAuthError
from netmiko import NetmikoTimeoutError
from netmiko import NetMikoTimeoutException
from netmiko import (
ConnectHandler,
NetmikoAuthError,
NetmikoTimeoutError,
NetMikoTimeoutException,
NetMikoAuthenticationException,
)
# Project Imports
from hyperglass.configuration import devices
from hyperglass.configuration import params
from hyperglass.constants import Supported
from hyperglass.exceptions import AuthError
from hyperglass.exceptions import DeviceTimeout
from hyperglass.exceptions import ResponseEmpty
from hyperglass.exceptions import RestError
from hyperglass.exceptions import ScrapeError
from hyperglass.execution.construct import Construct
from hyperglass.execution.encode import jwt_decode
from hyperglass.execution.encode import jwt_encode
# Project
from hyperglass.util import log
from hyperglass.constants import Supported
from hyperglass.exceptions import (
AuthError,
RestError,
ScrapeError,
DeviceTimeout,
ResponseEmpty,
)
from hyperglass.configuration import params, devices
from hyperglass.execution.encode import jwt_decode, jwt_encode
from hyperglass.execution.construct import Construct
class Connect:

View File

@@ -1,7 +1,7 @@
#!/usr/bin/env python3
"""hyperglass CLI management tool."""
# Project Imports
# Project
from cli import CLI
if __name__ == "__main__":

View File

@@ -1,12 +1,12 @@
"""hyperglass setuptools."""
# Standard Library Imports
# Standard Library
import sys
from pathlib import Path
from configparser import ConfigParser
from distutils.core import setup
from pathlib import Path
# Project Imports
# Project
from hyperglass import meta
# Project metadata