Skip to content

Commit

Permalink
Fixed pre-commit (#710)
Browse files Browse the repository at this point in the history
  • Loading branch information
danyi1212 authored Dec 2, 2024
1 parent dd8dc96 commit 297e864
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 64 deletions.
62 changes: 37 additions & 25 deletions packages/opal-client/opal_client/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,22 @@ class EngineLogFormat(str, Enum):
class OpalClientConfig(Confi):
# opa client (policy store) configuration
POLICY_STORE_TYPE = confi.enum(
"POLICY_STORE_TYPE", PolicyStoreTypes, PolicyStoreTypes.OPA,
description="The type of policy store to use (e.g., OPA, Cedar, etc.)"
"POLICY_STORE_TYPE",
PolicyStoreTypes,
PolicyStoreTypes.OPA,
description="The type of policy store to use (e.g., OPA, Cedar, etc.)",
)
POLICY_STORE_URL = confi.str(
"POLICY_STORE_URL", "http://localhost:8181",
description="The URL of the policy store (e.g., OPA agent)."
"POLICY_STORE_URL",
"http://localhost:8181",
description="The URL of the policy store (e.g., OPA agent).",
)

POLICY_STORE_AUTH_TYPE = confi.enum(
"POLICY_STORE_AUTH_TYPE", PolicyStoreAuth, PolicyStoreAuth.NONE,
description="The authentication type to use for the policy store (e.g., NONE, TOKEN, etc.)"
"POLICY_STORE_AUTH_TYPE",
PolicyStoreAuth,
PolicyStoreAuth.NONE,
description="The authentication type to use for the policy store (e.g., NONE, TOKEN, etc.)",
)
POLICY_STORE_AUTH_TOKEN = confi.str(
"POLICY_STORE_AUTH_TOKEN",
Expand Down Expand Up @@ -138,8 +143,9 @@ def load_policy_store():

# whether or not OPAL should run OPA by itself in the same container
INLINE_OPA_ENABLED = confi.bool(
"INLINE_OPA_ENABLED", True,
description="Whether or not OPAL should run OPA by itself in the same container"
"INLINE_OPA_ENABLED",
True,
description="Whether or not OPAL should run OPA by itself in the same container",
)

INLINE_OPA_EXEC_PATH = confi.str(
Expand All @@ -158,16 +164,19 @@ def load_policy_store():
)

INLINE_OPA_LOG_FORMAT: EngineLogFormat = confi.enum(
"INLINE_OPA_LOG_FORMAT", EngineLogFormat, EngineLogFormat.NONE,
description="The log format to use for inline OPA logs"
"INLINE_OPA_LOG_FORMAT",
EngineLogFormat,
EngineLogFormat.NONE,
description="The log format to use for inline OPA logs",
)

# Cedar runner configuration (Cedar-engine can optionally be run by OPAL) ----------------

# whether or not OPAL should run the Cedar agent by itself in the same container
INLINE_CEDAR_ENABLED = confi.bool(
"INLINE_CEDAR_ENABLED", True,
description="Whether or not OPAL should run the Cedar agent by itself in the same container"
"INLINE_CEDAR_ENABLED",
True,
description="Whether or not OPAL should run the Cedar agent by itself in the same container",
)

INLINE_CEDAR_EXEC_PATH = confi.str(
Expand All @@ -186,25 +195,30 @@ def load_policy_store():
)

INLINE_CEDAR_LOG_FORMAT: EngineLogFormat = confi.enum(
"INLINE_CEDAR_LOG_FORMAT", EngineLogFormat, EngineLogFormat.NONE,
description="The log format to use for inline Cedar logs"
"INLINE_CEDAR_LOG_FORMAT",
EngineLogFormat,
EngineLogFormat.NONE,
description="The log format to use for inline Cedar logs",
)

# configuration for fastapi routes
ALLOWED_ORIGINS = ["*"]

# general configuration for pub/sub clients
KEEP_ALIVE_INTERVAL = confi.int(
"KEEP_ALIVE_INTERVAL", 0,
description="The interval (in seconds) for sending keep-alive messages"
"KEEP_ALIVE_INTERVAL",
0,
description="The interval (in seconds) for sending keep-alive messages",
)

# Opal Server general configuration -------------------------------------------

# opal server url
SERVER_URL = confi.str(
"SERVER_URL", "http://localhost:7002", flags=["-s"],
description="The URL of the OPAL server"
"SERVER_URL",
"http://localhost:7002",
flags=["-s"],
description="The URL of the OPAL server",
)
# opal server pubsub url
OPAL_WS_ROUTE = "/ws"
Expand All @@ -215,11 +229,12 @@ def load_policy_store():
"http", "ws"
)
),
description="The WebSocket URL of the OPAL server"
description="The WebSocket URL of the OPAL server",
)
SERVER_PUBSUB_URL = confi.str(
"SERVER_PUBSUB_URL", confi.delay("{SERVER_WS_URL}" + f"{OPAL_WS_ROUTE}"),
description="The Pub/Sub URL of the OPAL server"
"SERVER_PUBSUB_URL",
confi.delay("{SERVER_WS_URL}" + f"{OPAL_WS_ROUTE}"),
description="The Pub/Sub URL of the OPAL server",
)

# opal server auth token
Expand Down Expand Up @@ -339,10 +354,7 @@ def load_policy_store():

OPA_HEALTH_CHECK_POLICY_PATH = "engine/healthcheck/opal.rego"

SCOPE_ID = confi.str(
"SCOPE_ID", "default",
description="OPAL Scope ID"
)
SCOPE_ID = confi.str("SCOPE_ID", "default", description="OPAL Scope ID")

STORE_BACKUP_PATH = confi.str(
"STORE_BACKUP_PATH",
Expand Down
44 changes: 29 additions & 15 deletions packages/opal-common/opal_common/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,27 +108,35 @@ class OpalCommonConfig(Confi):
# Fetching Providers
# - where to load providers from
FETCH_PROVIDER_MODULES = confi.list(
"FETCH_PROVIDER_MODULES", ["opal_common.fetcher.providers"],
description="List of modules to load fetch providers from"
"FETCH_PROVIDER_MODULES",
["opal_common.fetcher.providers"],
description="List of modules to load fetch providers from",
)

# Fetching engine
# Max number of worker tasks handling fetch events concurrently
FETCHING_WORKER_COUNT = confi.int(
"FETCHING_WORKER_COUNT", 6, description="Max number of worker tasks handling fetch events concurrently"
"FETCHING_WORKER_COUNT",
6,
description="Max number of worker tasks handling fetch events concurrently",
)
# Time in seconds to wait on the queued fetch task.
FETCHING_CALLBACK_TIMEOUT = confi.int(
"FETCHING_CALLBACK_TIMEOUT", 10, description="Time in seconds to wait on the queued fetch task"
"FETCHING_CALLBACK_TIMEOUT",
10,
description="Time in seconds to wait on the queued fetch task",
)
# Time in seconds to wait for queuing a new task (if the queue is full)
FETCHING_ENQUEUE_TIMEOUT = confi.int(
"FETCHING_ENQUEUE_TIMEOUT", 10, description="Time in seconds to wait for queuing a new task (if the queue is full)"
"FETCHING_ENQUEUE_TIMEOUT",
10,
description="Time in seconds to wait for queuing a new task (if the queue is full)",
)

GIT_SSH_KEY_FILE = confi.str(
"GIT_SSH_KEY_FILE", str(Path.home() / ".ssh/opal_repo_ssh_key"),
description="Path to the SSH key file for Git"
"GIT_SSH_KEY_FILE",
str(Path.home() / ".ssh/opal_repo_ssh_key"),
description="Path to the SSH key file for Git",
)

# Trust self signed certificates (Advanced Usage - only affects OPAL client) -----------------------------
Expand All @@ -149,13 +157,17 @@ class OpalCommonConfig(Confi):

# security
AUTH_PUBLIC_KEY_FORMAT = confi.enum(
"AUTH_PUBLIC_KEY_FORMAT", EncryptionKeyFormat, EncryptionKeyFormat.ssh,
description="Format of the public key for authentication"
"AUTH_PUBLIC_KEY_FORMAT",
EncryptionKeyFormat,
EncryptionKeyFormat.ssh,
description="Format of the public key for authentication",
)
AUTH_PUBLIC_KEY = confi.delay(
lambda AUTH_PUBLIC_KEY_FORMAT=None: confi.public_key(
"AUTH_PUBLIC_KEY", default=None, key_format=AUTH_PUBLIC_KEY_FORMAT,
description="Public key for authentication"
"AUTH_PUBLIC_KEY",
default=None,
key_format=AUTH_PUBLIC_KEY_FORMAT,
description="Public key for authentication",
)
)
AUTH_JWT_ALGORITHM = confi.enum(
Expand All @@ -165,12 +177,14 @@ class OpalCommonConfig(Confi):
description="jwt algorithm, possible values: see: https://pyjwt.readthedocs.io/en/stable/algorithms.html",
)
AUTH_JWT_AUDIENCE = confi.str(
"AUTH_JWT_AUDIENCE", "https://api.opal.ac/v1/",
description="Audience for JWT authentication"
"AUTH_JWT_AUDIENCE",
"https://api.opal.ac/v1/",
description="Audience for JWT authentication",
)
AUTH_JWT_ISSUER = confi.str(
"AUTH_JWT_ISSUER", f"https://opal.ac/",
description="Issuer for JWT authentication"
"AUTH_JWT_ISSUER",
f"https://opal.ac/",
description="Issuer for JWT authentication",
)
POLICY_REPO_POLICY_EXTENSIONS = confi.list(
"POLICY_REPO_POLICY_EXTENSIONS",
Expand Down
5 changes: 4 additions & 1 deletion packages/opal-common/opal_common/tests/test_config.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
import pytest
from opal_common.config import opal_common_config
from opal_client.config import opal_client_config
from opal_common.config import opal_common_config
from opal_server.config import opal_server_config


def test_opal_common_config_descriptions():
for name, entry in opal_common_config.entries.items():
assert entry.description is not None, f"{name} is missing a description"


def test_opal_client_config_descriptions():
for name, entry in opal_client_config.entries.items():
assert entry.description is not None, f"{name} is missing a description"


def test_opal_server_config_descriptions():
for name, entry in opal_server_config.entries.items():
assert entry.description is not None, f"{name} is missing a description"
Loading

0 comments on commit 297e864

Please sign in to comment.