style: Change makefile for apiserver and nginx of skyline
1. fix makefile for apiserver and nginx of skyline 2. re-fmt and re-lint for project Change-Id: I4800b19dad0e3031462f540ff4427ca750d6324f
This commit is contained in:
parent
d1dd62fb8e
commit
f369b43f24
|
@ -1,5 +1,5 @@
|
|||
PYTHON ?= python3
|
||||
ROOT_DIR ?= $(shell git rev-parse --show-toplevel)
|
||||
PY_FILES := $(shell git ls-files -- *.py | xargs)
|
||||
|
||||
# Color
|
||||
no_color = \033[0m
|
||||
|
@ -35,17 +35,17 @@ package:
|
|||
|
||||
.PHONY: fmt
|
||||
fmt:
|
||||
poetry run isort $$(git ls-files -- **/*.py)
|
||||
poetry run black --config ../../pyproject.toml $$(git ls-files -- **/*.py)
|
||||
poetry run add-trailing-comma --py36-plus --exit-zero-even-if-changed $$(git ls-files -- **/*.py)
|
||||
poetry run isort $(PY_FILES)
|
||||
poetry run black --config ../../pyproject.toml $(PY_FILES)
|
||||
poetry run add-trailing-comma --py36-plus --exit-zero-even-if-changed $(PY_FILES)
|
||||
|
||||
|
||||
.PHONY: lint
|
||||
lint:
|
||||
# poetry run mypy --config-file=../../mypy.ini $$(git ls-files -- **/*.py)
|
||||
poetry run isort --check-only --diff $$(git ls-files -- **/*.py)
|
||||
poetry run black --check --diff --color --config ../../pyproject.toml $$(git ls-files -- **/*.py)
|
||||
poetry run flake8 $$(git ls-files -- **/*.py)
|
||||
# poetry run mypy --config-file=../../mypy.ini $(PY_FILES)
|
||||
poetry run isort --check-only --diff $(PY_FILES)
|
||||
poetry run black --check --diff --color --config ../../pyproject.toml $(PY_FILES)
|
||||
poetry run flake8 $(PY_FILES)
|
||||
|
||||
|
||||
.PHONY: test
|
||||
|
|
|
@ -20,7 +20,6 @@ from typing import Optional
|
|||
import jose
|
||||
from fastapi import HTTPException, Request, Response, status
|
||||
from fastapi.security import APIKeyCookie
|
||||
|
||||
from skyline_apiserver import schemas
|
||||
from skyline_apiserver.config import CONF
|
||||
from skyline_apiserver.core.security import generate_profile_by_token, parse_access_token
|
||||
|
|
|
@ -13,7 +13,6 @@
|
|||
# limitations under the License.
|
||||
|
||||
from fastapi import APIRouter
|
||||
|
||||
from skyline_apiserver.api.v1 import contrib, extension, login, policy, setting
|
||||
|
||||
api_router = APIRouter()
|
||||
|
|
|
@ -18,14 +18,13 @@ import asyncio
|
|||
from typing import Any, List
|
||||
|
||||
from fastapi import APIRouter, Header, HTTPException, status
|
||||
from skyline_log import LOG
|
||||
|
||||
from skyline_apiserver import schemas
|
||||
from skyline_apiserver.client.openstack import system
|
||||
from skyline_apiserver.client.openstack.system import get_endpoints
|
||||
from skyline_apiserver.config import CONF
|
||||
from skyline_apiserver.schemas import common
|
||||
from skyline_apiserver.types import constants
|
||||
from skyline_log import LOG
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
|
|
|
@ -22,7 +22,6 @@ from typing import List
|
|||
|
||||
from dateutil import parser
|
||||
from fastapi import APIRouter, Depends, Header, HTTPException, Query, status
|
||||
|
||||
from skyline_apiserver import schemas
|
||||
from skyline_apiserver.api import deps
|
||||
from skyline_apiserver.api.v1.openstack.base import OSPort, OSServer, OSVolume, OSVolumeSnapshot
|
||||
|
|
|
@ -18,8 +18,6 @@ from fastapi import APIRouter, Depends, Header, HTTPException, Request, Response
|
|||
from keystoneauth1.identity.v3 import Password
|
||||
from keystoneauth1.session import Session
|
||||
from keystoneclient.client import Client as KeystoneClient
|
||||
from skyline_log import LOG
|
||||
|
||||
from skyline_apiserver import schemas
|
||||
from skyline_apiserver.api import deps
|
||||
from skyline_apiserver.client import utils
|
||||
|
@ -36,9 +34,9 @@ from skyline_apiserver.core.security import (
|
|||
generate_profile_by_token,
|
||||
parse_access_token,
|
||||
)
|
||||
from skyline_apiserver.types import constants
|
||||
from skyline_apiserver.db import api as db_api
|
||||
from skyline_apiserver.types import constants
|
||||
from skyline_log import LOG
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
|
@ -94,7 +92,11 @@ async def login(
|
|||
reauthenticate=False,
|
||||
)
|
||||
session = Session(auth=unscope_auth, verify=False, timeout=constants.DEFAULT_TIMEOUT)
|
||||
unscope_client = KeystoneClient(session=session, endpoint=auth_url, interface=CONF.openstack.interface_type)
|
||||
unscope_client = KeystoneClient(
|
||||
session=session,
|
||||
endpoint=auth_url,
|
||||
interface=CONF.openstack.interface_type,
|
||||
)
|
||||
project_scope = unscope_client.auth.projects()
|
||||
# we must get the project_scope with enabled project
|
||||
project_scope = [scope for scope in project_scope if scope.enabled]
|
||||
|
|
|
@ -15,7 +15,6 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from fastapi import APIRouter, Depends, HTTPException, status
|
||||
|
||||
from skyline_apiserver import schemas
|
||||
from skyline_apiserver.api import deps
|
||||
from skyline_apiserver.client.utils import generate_session, get_access
|
||||
|
|
|
@ -15,7 +15,6 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from fastapi import APIRouter, Depends, HTTPException, status
|
||||
|
||||
from skyline_apiserver import schemas
|
||||
from skyline_apiserver.api import deps
|
||||
from skyline_apiserver.config import CONF
|
||||
|
|
|
@ -19,10 +19,9 @@ from typing import Any, Dict
|
|||
from fastapi import HTTPException, status
|
||||
from keystoneauth1.exceptions.http import Unauthorized
|
||||
from keystoneauth1.session import Session
|
||||
from starlette.concurrency import run_in_threadpool
|
||||
|
||||
from skyline_apiserver import schemas
|
||||
from skyline_apiserver.client import utils
|
||||
from starlette.concurrency import run_in_threadpool
|
||||
|
||||
|
||||
async def list_volumes(
|
||||
|
|
|
@ -19,10 +19,9 @@ from typing import Any, Dict
|
|||
from fastapi import HTTPException, status
|
||||
from keystoneauth1.exceptions.http import Unauthorized
|
||||
from keystoneauth1.session import Session
|
||||
from starlette.concurrency import run_in_threadpool
|
||||
|
||||
from skyline_apiserver import schemas
|
||||
from skyline_apiserver.client import utils
|
||||
from starlette.concurrency import run_in_threadpool
|
||||
|
||||
|
||||
async def list_images(
|
||||
|
|
|
@ -19,10 +19,9 @@ from typing import Any, Dict
|
|||
from fastapi import HTTPException, status
|
||||
from keystoneauth1.exceptions.http import Unauthorized
|
||||
from keystoneauth1.session import Session
|
||||
from starlette.concurrency import run_in_threadpool
|
||||
|
||||
from skyline_apiserver import schemas
|
||||
from skyline_apiserver.client import utils
|
||||
from starlette.concurrency import run_in_threadpool
|
||||
|
||||
|
||||
async def list_projects(
|
||||
|
|
|
@ -19,10 +19,9 @@ from typing import Any
|
|||
from fastapi import HTTPException, status
|
||||
from keystoneauth1.exceptions.http import Unauthorized
|
||||
from keystoneauth1.session import Session
|
||||
from starlette.concurrency import run_in_threadpool
|
||||
|
||||
from skyline_apiserver import schemas
|
||||
from skyline_apiserver.client import utils
|
||||
from starlette.concurrency import run_in_threadpool
|
||||
|
||||
|
||||
async def list_networks(
|
||||
|
|
|
@ -20,10 +20,9 @@ from fastapi import HTTPException, status
|
|||
from keystoneauth1.exceptions.http import Unauthorized
|
||||
from keystoneauth1.session import Session
|
||||
from novaclient.exceptions import BadRequest, Forbidden
|
||||
from starlette.concurrency import run_in_threadpool
|
||||
|
||||
from skyline_apiserver import schemas
|
||||
from skyline_apiserver.client import utils
|
||||
from starlette.concurrency import run_in_threadpool
|
||||
|
||||
|
||||
async def list_servers(
|
||||
|
|
|
@ -19,13 +19,12 @@ from typing import Any, Dict
|
|||
|
||||
from keystoneauth1.identity.v3 import Token
|
||||
from keystoneauth1.session import Session
|
||||
from skyline_log import LOG
|
||||
from starlette.concurrency import run_in_threadpool
|
||||
|
||||
from skyline_apiserver.client import utils
|
||||
from skyline_apiserver.client.utils import get_system_session
|
||||
from skyline_apiserver.config import CONF
|
||||
from skyline_apiserver.types import constants
|
||||
from skyline_log import LOG
|
||||
from starlette.concurrency import run_in_threadpool
|
||||
|
||||
|
||||
async def get_project_scope_token(
|
||||
|
|
|
@ -26,11 +26,10 @@ from keystoneclient.httpclient import HTTPClient
|
|||
from neutronclient.v2_0.client import Client as NeutronClient
|
||||
from novaclient.client import Client as NovaClient
|
||||
from osc_placement.http import SessionClient as PlacementClient
|
||||
from starlette.concurrency import run_in_threadpool
|
||||
|
||||
from skyline_apiserver import schemas
|
||||
from skyline_apiserver.config import CONF
|
||||
from skyline_apiserver.types import constants
|
||||
from starlette.concurrency import run_in_threadpool
|
||||
|
||||
SESSION = None
|
||||
|
||||
|
|
|
@ -18,7 +18,6 @@ import sys
|
|||
|
||||
import click
|
||||
import yaml
|
||||
|
||||
from skyline_apiserver.config import CONF, configure
|
||||
|
||||
|
||||
|
|
|
@ -18,7 +18,6 @@ import json
|
|||
import sys
|
||||
|
||||
import click
|
||||
|
||||
from skyline_apiserver.main import app
|
||||
|
||||
|
||||
|
|
|
@ -17,9 +17,8 @@ from __future__ import annotations
|
|||
from typing import Dict, List
|
||||
|
||||
from pydantic import HttpUrl, StrictInt, StrictStr
|
||||
from skyline_config import Opt
|
||||
|
||||
from skyline_apiserver.types import InterfaceType
|
||||
from skyline_config import Opt
|
||||
|
||||
keystone_url = Opt(
|
||||
name="keystone_url",
|
||||
|
|
|
@ -14,24 +14,15 @@
|
|||
|
||||
from __future__ import annotations
|
||||
|
||||
import base64
|
||||
import json
|
||||
import time
|
||||
import uuid
|
||||
import zlib
|
||||
from typing import Optional
|
||||
|
||||
from fastapi import HTTPException, status
|
||||
from jose import jwt
|
||||
from skyline_log import LOG
|
||||
|
||||
from skyline_apiserver import __version__
|
||||
from skyline_apiserver import schemas
|
||||
from skyline_apiserver import __version__, schemas
|
||||
from skyline_apiserver.client import utils
|
||||
from skyline_apiserver.client.utils import get_system_session
|
||||
from skyline_apiserver.config import CONF
|
||||
from skyline_apiserver.db import api as db_api
|
||||
from skyline_apiserver.types import constants
|
||||
|
||||
|
||||
def parse_access_token(token: str) -> (schemas.Payload):
|
||||
|
|
|
@ -16,11 +16,10 @@ from logging import StreamHandler, basicConfig
|
|||
|
||||
from alembic import context
|
||||
from databases import DatabaseURL
|
||||
from skyline_log import setup as log_setup
|
||||
from sqlalchemy import create_engine, pool
|
||||
|
||||
from skyline_apiserver.config import CONF, configure
|
||||
from skyline_apiserver.db.models import METADATA
|
||||
from skyline_log import setup as log_setup
|
||||
from sqlalchemy import create_engine, pool
|
||||
|
||||
configure("skyline")
|
||||
basicConfig()
|
||||
|
|
|
@ -18,9 +18,8 @@ import time
|
|||
from functools import wraps
|
||||
from typing import Any
|
||||
|
||||
from sqlalchemy import delete, func, insert, select, update
|
||||
|
||||
from skyline_apiserver.types import Fn
|
||||
from sqlalchemy import delete, func, insert, select, update
|
||||
|
||||
from .base import DB, inject_db
|
||||
from .models import RevokedToken, Settings
|
||||
|
|
|
@ -17,7 +17,6 @@ from __future__ import annotations
|
|||
from contextvars import ContextVar
|
||||
|
||||
from databases import Database, DatabaseURL, core
|
||||
|
||||
from skyline_apiserver.config import CONF
|
||||
|
||||
DATABASE = None
|
||||
|
|
|
@ -18,7 +18,6 @@ from typing import Any, Dict
|
|||
|
||||
import six
|
||||
from six.moves.urllib import parse
|
||||
|
||||
from skyline_apiserver.types import constants
|
||||
from skyline_apiserver.utils.httpclient import get_assert_200
|
||||
|
||||
|
|
|
@ -21,9 +21,8 @@ import attr
|
|||
from immutables import Map
|
||||
from keystoneauth1.access.access import AccessInfoV3
|
||||
from oslo_policy._checks import _check
|
||||
from skyline_policy_manager.policies.base import APIRule
|
||||
|
||||
from skyline_apiserver.config import CONF
|
||||
from skyline_policy_manager.policies.base import APIRule
|
||||
|
||||
|
||||
class UserContext(MutableMapping):
|
||||
|
|
|
@ -18,7 +18,6 @@ from typing import Any, Dict, List, Optional
|
|||
|
||||
from jose import jwt
|
||||
from pydantic import BaseModel
|
||||
|
||||
from skyline_apiserver import config
|
||||
from skyline_apiserver.types import constants
|
||||
|
||||
|
|
|
@ -15,7 +15,6 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from fastapi import HTTPException, status
|
||||
|
||||
from skyline_apiserver import schemas
|
||||
from skyline_apiserver.config import CONF
|
||||
|
||||
|
|
|
@ -16,7 +16,6 @@ import os
|
|||
|
||||
import pytest
|
||||
from httpx import AsyncClient
|
||||
|
||||
from skyline_apiserver import main
|
||||
from skyline_apiserver.config import CONF
|
||||
|
||||
|
|
|
@ -19,7 +19,6 @@ from typing import Any, Dict
|
|||
import pytest
|
||||
from httpx import AsyncClient
|
||||
from six.moves.urllib import parse
|
||||
|
||||
from skyline_apiserver import main
|
||||
|
||||
|
||||
|
|
|
@ -17,13 +17,11 @@ import time
|
|||
|
||||
import pytest
|
||||
from httpx import AsyncClient
|
||||
from utils import utils
|
||||
|
||||
from skyline_apiserver import __version__
|
||||
from skyline_apiserver import main
|
||||
from skyline_apiserver import __version__, main
|
||||
from skyline_apiserver.config import CONF
|
||||
from skyline_apiserver.db import api as db_api, setup as db_setup
|
||||
from skyline_apiserver.types import constants
|
||||
from utils import utils
|
||||
|
||||
|
||||
@pytest.mark.skipif(os.getenv("TEST_API") != "true", reason="No backend OpenStack for api-test.")
|
||||
|
|
|
@ -17,7 +17,6 @@ import uuid
|
|||
|
||||
import pytest
|
||||
from httpx import AsyncClient
|
||||
|
||||
from skyline_apiserver import main
|
||||
from skyline_apiserver.config import CONF
|
||||
from skyline_apiserver.types import constants
|
||||
|
|
|
@ -15,7 +15,6 @@
|
|||
import os
|
||||
|
||||
import pytest
|
||||
|
||||
from skyline_apiserver.config import base
|
||||
|
||||
|
||||
|
|
|
@ -13,7 +13,6 @@
|
|||
# limitations under the License.
|
||||
|
||||
import pytest
|
||||
|
||||
from skyline_apiserver.config.default import ALL_OPTS, GROUP_NAME
|
||||
|
||||
|
||||
|
|
|
@ -13,7 +13,6 @@
|
|||
# limitations under the License.
|
||||
|
||||
import pytest
|
||||
|
||||
from skyline_apiserver.config.openstack import ALL_OPTS, GROUP_NAME
|
||||
|
||||
|
||||
|
|
|
@ -16,9 +16,7 @@ import time
|
|||
import uuid
|
||||
|
||||
from httpx import AsyncClient
|
||||
|
||||
from skyline_apiserver import __version__
|
||||
from skyline_apiserver import config, main, schemas
|
||||
from skyline_apiserver import __version__, config, main, schemas
|
||||
|
||||
|
||||
def get_session_profile() -> schemas.Profile:
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
PYTHON ?= python3
|
||||
PY_FILES := $(shell git ls-files -- *.py | xargs)
|
||||
|
||||
|
||||
.PHONY: all
|
||||
|
@ -23,17 +24,17 @@ package:
|
|||
|
||||
.PHONY: fmt
|
||||
fmt:
|
||||
poetry run isort $$(git ls-files -- **/*.py)
|
||||
poetry run black --config ../../pyproject.toml $$(git ls-files -- **/*.py)
|
||||
poetry run add-trailing-comma --py36-plus --exit-zero-even-if-changed $$(git ls-files -- **/*.py)
|
||||
poetry run isort $(PY_FILES)
|
||||
poetry run black --config ../../pyproject.toml $(PY_FILES)
|
||||
poetry run add-trailing-comma --py36-plus --exit-zero-even-if-changed $(PY_FILES)
|
||||
|
||||
|
||||
.PHONY: lint
|
||||
lint:
|
||||
poetry run mypy --config-file=../../mypy.ini $$(git ls-files -- **/*.py)
|
||||
poetry run isort --check-only --diff $$(git ls-files -- **/*.py)
|
||||
poetry run black --check --diff --color --config ../../pyproject.toml $$(git ls-files -- **/*.py)
|
||||
poetry run flake8 $$(git ls-files -- **/*.py)
|
||||
# poetry run mypy --config-file=../../mypy.ini $(PY_FILES)
|
||||
poetry run isort --check-only --diff $(PY_FILES)
|
||||
poetry run black --check --diff --color --config ../../pyproject.toml $(PY_FILES)
|
||||
poetry run flake8 $(PY_FILES)
|
||||
|
||||
|
||||
.PHONY: test
|
||||
|
|
|
@ -17,20 +17,21 @@ from __future__ import annotations
|
|||
import sys
|
||||
from logging import StreamHandler
|
||||
from pathlib import Path, PurePath
|
||||
from typing import Any, Dict
|
||||
from typing import Dict
|
||||
from urllib.parse import urlparse
|
||||
|
||||
import click
|
||||
import skyline_nginx
|
||||
from pydantic import BaseModel
|
||||
from jinja2 import Template
|
||||
from keystoneauth1.identity.v3 import Password, Token
|
||||
from keystoneauth1.identity.v3 import Password
|
||||
from keystoneauth1.session import Session
|
||||
from keystoneclient.client import Client as KeystoneClient
|
||||
from pydantic import BaseModel
|
||||
from skyline_console import static_path
|
||||
from skyline_log import LOG, setup
|
||||
from skyline_nginx.config import CONF, configure
|
||||
|
||||
|
||||
class CommandException(Exception):
|
||||
EXIT_CODE = 1
|
||||
|
||||
|
@ -73,7 +74,9 @@ def get_proxy_endpoints() -> Dict[str, ProxyEndpoint]:
|
|||
if service is None:
|
||||
continue
|
||||
if f"{region}-{service_type}" in endpoints:
|
||||
raise KeyError(f"Region \"{region}\" service type \"{service_type}\" conflict in endpoints.")
|
||||
raise KeyError(
|
||||
f'Region "{region}" service type "{service_type}" conflict in endpoints.',
|
||||
)
|
||||
|
||||
proxy.part = f"# {region} {service}"
|
||||
location = PurePath("/").joinpath(
|
||||
|
@ -89,13 +92,9 @@ def get_proxy_endpoints() -> Dict[str, ProxyEndpoint]:
|
|||
raw_path = PurePath(raw_url.path)
|
||||
if len(raw_path.parts) > 1:
|
||||
if raw_path.match("%(tenant_id)s") or raw_path.match("$(project_id)s"):
|
||||
path = (
|
||||
"" if str(raw_path.parents[1]) == "/" else raw_path.parents[1]
|
||||
)
|
||||
path = "" if str(raw_path.parents[1]) == "/" else raw_path.parents[1]
|
||||
elif raw_path.match("v[0-9]") or raw_path.match("v[0-9][.][0-9]"):
|
||||
path = (
|
||||
"" if str(raw_path.parents[0]) == "/" else raw_path.parents[0]
|
||||
)
|
||||
path = "" if str(raw_path.parents[0]) == "/" else raw_path.parents[0]
|
||||
else:
|
||||
path = raw_path
|
||||
|
||||
|
@ -131,9 +130,7 @@ def main(output_file_path: str, ssl_certfile: str, ssl_keyfile: str) -> None:
|
|||
setup(StreamHandler(), debug=CONF.default.debug)
|
||||
|
||||
template_file_path = (
|
||||
Path(skyline_nginx.__file__).parent
|
||||
.joinpath("templates")
|
||||
.joinpath("nginx.conf.j2")
|
||||
Path(skyline_nginx.__file__).parent.joinpath("templates").joinpath("nginx.conf.j2")
|
||||
)
|
||||
content = ""
|
||||
with template_file_path.open() as f:
|
||||
|
|
Loading…
Reference in New Issue