Skip to content
This repository was archived by the owner on Sep 4, 2022. It is now read-only.

Commit

Permalink
fix(configurations): align configurations with readme
Browse files Browse the repository at this point in the history
  • Loading branch information
nemoshlag committed Jun 6, 2022
1 parent a0deb1d commit dedecb9
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 88 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ pretty:
.PHONY: prep
prep:
make pretty
make deps
make test

.PHONY: bootstrap
Expand Down
69 changes: 33 additions & 36 deletions cisco_telescope/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,48 +77,43 @@ def __init__(
exporters: [ExporterOptions] = None,
):

# Set options parameters
self.service_name = service_name or os.environ.get(
Consts.SERVICE_NAME_KEY, Consts.DEFAULT_SERVICE_NAME
)
self.cisco_token = cisco_token or os.environ.get(Consts.CISCO_TOKEN_ENV)
if self.cisco_token is None and exporters is None:
raise ValueError("Can not initiate cisco-telescope without token")

if self.cisco_token is not None and exporters is not None:
logging.warning(
"Warning: Custom exporters do not use cisco token, it can be passed as a custom header"
)
self.debug = debug or strtobool(
os.environ.get(Consts.CISCO_DEBUG_ENV, str(Consts.DEFAULT_CISCO_DEBUG))
)

if not exporters or len(exporters) == 0: # Set default exporter
self.exporters = [
ExporterOptions(
exporter_type=Consts.DEFAULT_EXPORTER_TYPE,
collector_endpoint=Consts.DEFAULT_COLLECTOR_ENDPOINT,
custom_headers={
Consts.TOKEN_HEADER_KEY: verify_token(self.cisco_token)
},
)
]
else:
self.exporters = exporters

self.service_name = service_name

if payloads_enabled is None:
self.payloads_enabled = strtobool(
os.environ.get(
Consts.CISCO_PAYLOADS_ENABLED_ENV,
str(Consts.DEFAULT_PAYLOADS_ENABLED),
)
self.payloads_enabled = payloads_enabled or strtobool(
os.environ.get(
Consts.CISCO_PAYLOADS_ENABLED_ENV,
str(Consts.DEFAULT_PAYLOADS_ENABLED),
)
else:
self.payloads_enabled = payloads_enabled
)

if debug is None:
self.debug = strtobool(
os.environ.get(Consts.CISCO_DEBUG_ENV, str(Consts.DEFAULT_CISCO_DEBUG))
self.max_payload_size = max_payload_size or Consts.DEFAULT_MAX_PAYLOAD_SIZE

self.exporters = exporters or [
ExporterOptions(
exporter_type=Consts.DEFAULT_EXPORTER_TYPE,
collector_endpoint=Consts.DEFAULT_COLLECTOR_ENDPOINT,
custom_headers={
Consts.TOKEN_HEADER_KEY: verify_token(self.cisco_token)
},
)
else:
self.debug = debug
]

self.max_payload_size = max_payload_size or Consts.DEFAULT_MAX_PAYLOAD_SIZE
# Validate parameters
if self.cisco_token is None and exporters is None:
raise ValueError("Can not initiate cisco-telescope without token")

if self.cisco_token and exporters is not None:
logging.warning(
"Warning: Custom exporters do not use cisco token, it can be passed as a custom header"
)

def __str__(self):
return (
Expand All @@ -132,7 +127,9 @@ def __str__(self):

def verify_token(token: str) -> str:
auth_prefix = "Bearer "
if token.startswith(auth_prefix):
if not token:
return ""
if token and token.startswith(auth_prefix):
return token
else:
return auth_prefix + token
94 changes: 47 additions & 47 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Flask = "^2.1.2"
aiohttp = "^3.8.1"
argparse = "^1.4.0"
certifi = "^2022.5.18.1"
cisco-opentelemetry-specifications = "^0.0.17"
cisco-opentelemetry-specifications = "^0.0.18"
fastapi = "^0.78.0"
grpcio = "^1.46.3"
httpcore = "^0.15.0"
Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ black==22.3.0
bleach==5.0.0
certifi==2022.5.18.1
charset-normalizer==2.0.12
cisco-opentelemetry-specifications==0.0.17
cisco-opentelemetry-specifications==0.0.18
cisco-telescope==1.0.0
click==8.1.3
click-log==0.4.0
colorama==0.4.4
coverage==6.4
coverage==6.4.1
decorator==5.1.1
Deprecated==1.2.13
distlib==0.3.4
Expand Down
Loading

0 comments on commit dedecb9

Please sign in to comment.