Skip to content

Commit

Permalink
dedup CNA API URL prefix
Browse files Browse the repository at this point in the history
Signed-off-by: Gerd Oberlechner <goberlec@redhat.com>
  • Loading branch information
geoberle committed Dec 20, 2022
1 parent e70a1dd commit a577a1c
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions reconcile/cna/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def __init__(self, ocm_client: OCMBaseClient, init_metadata: bool = False):
def _init_metadata(self) -> dict[AssetType, AssetTypeMetadata]:
asset_types_metadata: dict[AssetType, AssetTypeMetadata] = {}
for asset_type_ref in self._ocm_client.get(
api_path="/api/cna-management/v1/asset_types"
api_path=self._cna_api_v1_endpoint("/asset_types")
)["items"]:
raw_asset_type_metadata = self._ocm_client.get(
api_path=asset_type_ref["href"]
Expand Down Expand Up @@ -67,7 +67,7 @@ def list_assets(self) -> list[dict[str, Any]]:
of our assets
"""
# TODO: properly handle paging
cnas = self._ocm_client.get(api_path="/api/cna-management/v1/cnas")
cnas = self._ocm_client.get(api_path=self._cna_api_v1_endpoint("/cnas"))
return cnas.get("items", [])

def fetch_bindings_for_asset(self, asset: Asset) -> list[dict[str, str]]:
Expand All @@ -89,7 +89,7 @@ def create(self, asset: Asset, dry_run: bool = False):
)
return
self._ocm_client.post(
api_path="/api/cna-management/v1/cnas",
api_path=self._cna_api_v1_endpoint("/cnas"),
data=asset.api_payload(),
)

Expand Down Expand Up @@ -126,3 +126,6 @@ def update(self, asset: Asset, dry_run: bool = False):
api_path=asset.href,
data=asset.api_payload(),
)

def _cna_api_v1_endpoint(self, path: str) -> str:
return f"/api/cna-management/v1{path}"

0 comments on commit a577a1c

Please sign in to comment.