-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from Shackelford-Arden/as_updates
Adding Nomad Allocation ID Property & OTel Work
- Loading branch information
Showing
13 changed files
with
278 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
lint: | ||
poetry run pylint hc_pyconsul/ | ||
poetry run flake8 . | ||
poetry run mypy hc_pyconsul/ | ||
|
||
test: tests | ||
poetry run pytest --cov=hc_pyconsul tests/ --junitxml=report.xml --cov-report xml:coverage.xml | ||
|
||
pre-commit: | ||
make lint | ||
make test | ||
|
||
dev: pyproject.toml | ||
poetry install --no-root --no-interaction | ||
|
||
lint-ci: | ||
make dev | ||
make lint | ||
|
||
test-ci: | ||
make dev | ||
make test | ||
|
||
dev-pip: | ||
pip install . && pip install ".[testing]" |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import re | ||
|
||
from hc_pyconsul.models.helpers import NomadAllocation | ||
|
||
|
||
def extract_alloc_id_from_service_name(service_id: str) -> NomadAllocation: | ||
""" | ||
Extracts the Nomad allocation ID from a Consul service name. | ||
Parameters | ||
---------- | ||
service_id: str | ||
Returns | ||
------- | ||
alloc_id: NomadAllocation | ||
Raises | ||
------ | ||
FailedExtractingAllocID | ||
""" | ||
|
||
alloc_id = NomadAllocation() | ||
|
||
full_id = re.match(r'^_nomad-task-(\w+-\w+-\w+-\w+-\w+)', service_id) | ||
|
||
if not full_id: | ||
return alloc_id | ||
|
||
try: | ||
full_id_groups = full_id.groups()[0].split('-') | ||
alloc_id = NomadAllocation(id=full_id_groups[0], id_long='-'.join(full_id_groups)) | ||
except AttributeError: | ||
# Gracefully exit and allow default values of empty strings be provided. | ||
pass | ||
|
||
return alloc_id |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from typing import Optional | ||
|
||
from pydantic import BaseModel | ||
from pydantic import Field | ||
|
||
|
||
class NomadAllocation(BaseModel): | ||
id: Optional[str] = Field(default_factory=str) | ||
id_long: Optional[str] = Field(default_factory=str) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[tool.poetry] | ||
name = "hc_pyconsul" | ||
version = "0.2.0" | ||
version = "0.3.0" | ||
description = "API client for HashiCorp Consul" | ||
authors = ["Arden Shackelford <[email protected]>"] | ||
license = "Apache 2.0" | ||
|
@@ -11,21 +11,21 @@ packages = [ | |
|
||
|
||
[tool.poetry.dependencies] | ||
python = ">=3.8,<4.0" | ||
python = ">=3.8.1,<4.0" | ||
httpx = "^0.23.0" | ||
pydantic = "^1.9.0" | ||
opentelemetry-api = "^1.13.0" | ||
|
||
[tool.poetry.group.testing.dependencies] | ||
pytest-cov = "^3.0.0" | ||
pylint = "^2.15.0" | ||
flake8 = "^4.0.1" | ||
pylint = "^2.16.1" | ||
flake8 = "^6.0.0" | ||
mypy = "^0.950" | ||
respx = "^0.19.2" | ||
pytest = "^7.1.3" | ||
respx = "^0.20.1" | ||
pytest = "^7.2.1" | ||
|
||
[build-system] | ||
requires = ["poetry-core>=1.0.0"] | ||
requires = ["poetry-core>=1.4.0"] | ||
build-backend = "poetry.core.masonry.api" | ||
|
||
[tool.pylint.'MESSAGES CONTROL'] | ||
|
Oops, something went wrong.