Skip to content

Commit

Permalink
Merge pull request #11 from anomaly/pyndatic2-migration
Browse files Browse the repository at this point in the history
pyndatic2 migration
  • Loading branch information
devraj authored Nov 12, 2023
2 parents 09c1244 + d6b0298 commit 4d167af
Show file tree
Hide file tree
Showing 38 changed files with 428 additions and 293 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/deploy-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ jobs:
with:
python-version: 3.x
- run: pip install mkdocs
- run: pip install mkdocs-dracula-theme
- run: pip install mkdocs-terminal
- run: cd docs && mkdocs gh-deploy --force --clean --verbose
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# managed by direnv
.envrc

# Byte-compiled / optimized / DLL files
.secret
.DS_Store
Expand Down
23 changes: 19 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
> Currently under heavy development, please check for stable release before use
# Gallagher Command Centre REST API Client

> Python idiomatic client for Gallagher Command Centre API
Gallagher Security manufacture a variety of [security products](https://security.gallagher.com) all of which are controlled by their [Command Centre](https://products.security.gallagher.com/security/au/en_AU/products/software/command-centre/p/C201311) software. Traditionally Command Centre has been a Windows based server product. Version `8.6` introduced a REST API which allows you to interact with the system via HTTP requests. Gallagher also provide a [Cloud API Gateway](https://gallaghersecurity.github.io/docs/Command%20Centre%20Cloud%20Api%20Gateway%20TIP.pdf) which allows third party integrations to securely communicate with the Command Centre on site.
Expand All @@ -25,15 +27,18 @@ cc.Customer.create()
## API Notes

The Gallagher API uses `href` attributes to provide a the destination of referenced objects in the responses. These are prefixed with the server origin i.e if you are using the Cloud Gateway then all your URLs will be prefixed with the appropriate gateway's address.
The Gallagher API uses `href` attributes to provide a the destination of referenced objects in the responses. These are prefixed with the server origin i.e if you are using the Cloud Gateway then all your URLs will be prefixed with the appropriate gateway's address.

These appear in various forms, starting from as simple as the `href` itself:

```json
"cardholders": {
"href": "https://localhost:8904/api/access_groups/352/cardholders"
}
```

through to self recursive references with additional attributes:

```json
"parent": {
"href": "https://localhost:8904/api/access_groups/100",
Expand All @@ -56,7 +61,9 @@ class AccessGroupRef(
"""
name: str
```

where the `HrefMixin` provides the `href` attribute:

```python
class HrefMixin(BaseModel):
""" Href
Expand All @@ -66,7 +73,9 @@ class HrefMixin(BaseModel):
"""
href: str
```

These `Mixin` classes can also be used to declare attributes that seek to use the same pattern:

```python
class DivisionDetail(
AppBaseModel,
Expand All @@ -80,7 +89,9 @@ class DivisionDetail(
server_display_name: str
parent: Optional[HrefMixin]
```

where `parent` is simply an `href` without any other attributes. In the cases where these attributes have more than just an `href` we defined `Reference` classes:

```python
class AccessGroupRef(
AppBaseModel,
Expand All @@ -90,7 +101,9 @@ class AccessGroupRef(
"""
name: str
```

and use them to populate the attributes:

```python
class VisitorTypeDetail(
AppBaseModel,
Expand All @@ -102,6 +115,7 @@ class VisitorTypeDetail(
host_access_groups: list[AccessGroupSummary]
visitor_access_groups: list[AccessGroupSummary]
```

In this example the `AppGroupRef` has a `name` attribute which is not present in the `HrefMixin` class.

> Please see the schema section for naming conventions for `schema` classes
Expand All @@ -115,11 +129,11 @@ This API client primarily depends on the following libraries:

We use [Taskfile](https://taskfile.dev) to automate running tasks.

The project provides a comprehensive set of tests which can be run with `task test`. These tests do create objects in the Command Centre, we advice you to obtain a test license.
The project provides a comprehensive set of tests which can be run with `task test`. These tests do create objects in the Command Centre, we advice you to obtain a test license.

**DO NOT** run the tests against a production system.

### Schema
### Data Transfer Objects

There are three types of schema definitions, each one of them suffixed with their intent:

Expand Down Expand Up @@ -170,4 +184,5 @@ To check your API key:
![Command Centre Cloud Connections](assets/gallagher-rest-properties.png)

# License
Distributed under the MIT License.

Distributed under the MIT License.
2 changes: 1 addition & 1 deletion docs/mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ site_url: https://anomaly.github.io/gallagher/
repo_url: https://github.com/anomaly/gallagher/
site_author: Dev Mukherjee
theme:
name: dracula
name: terminal
19 changes: 13 additions & 6 deletions gallagher/cc/alarms/day_category.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,22 @@
"""

from ..utils import APIBase
from ...schema.day_category import DayCategoryResponse
from ..utils import (
APIBase,
EndpointConfig
)

from ...dto.day_category import (
DayCategoryResponse
)


class DayCategory(APIBase):
""" Day Categories
"""

class Config:

endpoint = "day_categories"
list_response_class = DayCategoryResponse
__config__ = EndpointConfig(
endpoint="day_categories",
dto_list=DayCategoryResponse,
dto_retrieve=DayCategoryResponse,
)
19 changes: 13 additions & 6 deletions gallagher/cc/alarms/divisions.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
from ..utils import APIBase
"""
"""

from ..utils import (
APIBase,
EndpointConfig
)


class Division(APIBase):
"""
Gallagher advises against hardcoding the URLs for divisions, and instead
recommends using the /api endpoint to discover the URLs from
events.divisions.href and alarms.division.href.
"""
class Config:

endpoint = "divisions"
"""

__config__ = EndpointConfig(
endpoint="divisions",
)
35 changes: 22 additions & 13 deletions gallagher/cc/alarms/items.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,38 @@
from ..utils import APIBase
from ...schema.items import ItemTypesResponse,\
ItemsSummaryResponse, ItemDetail
"""
"""
from ..utils import (
APIBase,
EndpointConfig
)

from ...dto.items import (
ItemTypesResponse,
ItemsSummaryResponse,
ItemDetail
)


class ItemsTypes(APIBase):
"""
Gallagher
"""

class Config:

endpoint = "items/types"
list_response_class = ItemTypesResponse
__config__ = EndpointConfig(
endpoint="items/types",
dto_list=ItemTypesResponse,
)


class Item(APIBase):
"""
Gallagher advises against hardcoding the URLs for divisions, and instead
recommends using the /api endpoint to discover the URLs from
events.divisions.href and alarms.division.href.
"""
class Config:
"""

endpoint = "items"
list_response_class = ItemsSummaryResponse
retrieve_response_class = ItemDetail
__config__ = EndpointConfig(
endpoint="items",
dto_list=ItemsSummaryResponse,
dto_retrieve=ItemDetail,
)
19 changes: 13 additions & 6 deletions gallagher/cc/alarms/schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,21 @@
"""

from ..utils import APIBase
from ...schema.schedule import ScheduleSummaryResponse
from ..utils import (
APIBase,
EndpointConfig
)

from ...dto.schedule import (
ScheduleSummaryResponse
)


class Schedule(APIBase):
""" Schedules
"""

class Config:

endpoint = "schedules"
list_response_class = ScheduleSummaryResponse
__config__ = EndpointConfig(
endpoint="schedules",
dto_list=ScheduleSummaryResponse,
)
22 changes: 15 additions & 7 deletions gallagher/cc/card/card_type.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
"""
"""
from ..utils import (
APIBase,
EndpointConfig
)

from ...dto.card_type import (
CardTypeResponse
)

from ..utils import APIBase
from ...schema.card_type import CardTypeResponse

class CardType(APIBase):
""" Card Types provide a list of support card types for the instance.
Expand All @@ -10,8 +19,7 @@ class CardType(APIBase):
of credentials available on this particular instance.
"""

class Config:

endpoint = "card_types"
list_response_class = CardTypeResponse

__config__ = EndpointConfig(
endpoint="card_types",
dto_list=CardTypeResponse,
)
Loading

0 comments on commit 4d167af

Please sign in to comment.