Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Major DTO implementation #15

Merged
merged 123 commits into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
123 commits
Select commit Hold shift + click to select a range
e8a4d23
docs: adds intro paragraph
devraj Nov 12, 2023
8e3f9da
feat: adds division endpoints
devraj Nov 12, 2023
ce19045
feat: adds optional cli parameter to run a single test
devraj Nov 12, 2023
0c31386
feat: adds alarm list endpoints
devraj Nov 12, 2023
67934a0
refactor: package names to reflect docs
devraj Nov 12, 2023
2b532d7
fix: import post package refactor
devraj Nov 12, 2023
7dbc643
docs: adds usage stub
devraj Nov 12, 2023
0949d35
feat: adds api discovery endpoint
devraj Nov 14, 2023
5ebe920
feat: adds event endpoints
devraj Nov 14, 2023
65eae80
chore: adds package placeholder
devraj Nov 14, 2023
15ccf3a
refactor: renames APIBase to APIEndpoint
devraj Nov 21, 2023
752e7e1
feat: makes all features optional in discovery
devraj Nov 21, 2023
e43f834
docs: adds intention to api discovery parser
devraj Nov 21, 2023
d48390a
refactor: discover api endpoints dynamically
devraj Nov 24, 2023
2655b8c
refactor: renames utils to core REFS #5
devraj Nov 25, 2023
7871c75
feat: adds actions task
devraj Nov 26, 2023
b46c830
refactor: allows the test task to take an optional input
devraj Nov 26, 2023
22752f9
refactor: first attempt a dynamic discovery
devraj Nov 26, 2023
9ce564b
fix: adds missing checkout action
devraj Nov 26, 2023
641a31e
fix: adds environment variable from secret
devraj Nov 26, 2023
5de09ee
refactor: discover test disable temporarily
devraj Nov 26, 2023
68185e0
chore: update dependencies
devraj Nov 26, 2023
44aa5d9
chore: update meta data in preperation for pypi
devraj Nov 29, 2023
4ff5ef4
refactor: experinmental commit for dynamic discovery
devraj Dec 3, 2023
85e40ad
fix: version test post pubilshing alpha
devraj Dec 3, 2023
8602083
refactor: dynamic configuration primarily working
devraj Dec 3, 2023
d588eaf
fix: collect only endpoint for tasks
devraj Dec 3, 2023
7b3ff28
refactor: initialisation of the discovery endpoint
devraj Dec 3, 2023
be14035
refactor: formalises configuration pattern for dynamic configuration
devraj Dec 3, 2023
977ce9c
refactor: configuration of endpoints to the new design
devraj Dec 3, 2023
83ec6ee
fix: incorrect reference to capabilities
devraj Dec 3, 2023
5085415
fix: endpoint configuration
devraj Dec 3, 2023
163a2c0
Merge pull request #17 from anomaly/dynamic-config
devraj Dec 3, 2023
e1fdc1b
feat: adds cardholder list and detail endpoints
devraj Dec 3, 2023
66e99c4
refactor: singleton pattern on the baseclass
devraj Dec 3, 2023
6dd7d72
refactor: moves capabilities singleton out of base class
devraj Dec 5, 2023
b510508
refactor: configuration syntax of discover and endpoints
devraj Dec 6, 2023
263ba0b
chore: port issues template for github
devraj Dec 6, 2023
b6568c9
feat: configure typer and cli endpoint
devraj Dec 6, 2023
a3dde5f
fix: href reference post design change
devraj Dec 6, 2023
5327f66
Merge branch 'dto-implementation' into cli-prototype
devraj Dec 6, 2023
573e5c4
feat: basic layout of the cli
devraj Dec 6, 2023
fa32907
chore: adds rich to format cli
devraj Dec 6, 2023
a9e82b9
feat: basic prototype of cli working
devraj Dec 6, 2023
30ae2a5
refactor: moves api init out of cli handler
devraj Dec 7, 2023
ea76d54
chore: update packages
devraj Dec 10, 2023
60ca052
feat: sample detail feature for cardholders
devraj Dec 10, 2023
f3cb6ab
refactor: events endpoint with even type endpoint configuration
devraj Dec 15, 2023
5eb89df
feat: starts on search feature
devraj Dec 15, 2023
52ed349
docs: adds cli output
devraj Dec 15, 2023
7a8db13
feat: adds dto for event type/group feature
devraj Dec 15, 2023
6738a44
test: adds test for event types
devraj Dec 15, 2023
8efdb59
feat: exploration of enums for search ordering
devraj Dec 15, 2023
c15893c
fix: adhere to the data definition rules
devraj Dec 15, 2023
5d5131b
refactor: wire up events endpoints
devraj Dec 17, 2023
f733ac6
feat: wip wiring up events parser
devraj Dec 17, 2023
a5213b2
docs: update todo
devraj Dec 17, 2023
8b9384b
chore: update packages
devraj Dec 18, 2023
cc73e4e
chore: move to concurrency
devraj Dec 18, 2023
cdaa0b2
fix: circular dependency issues
devraj Dec 18, 2023
647c4ee
chore: resolve merge conflict
devraj Dec 18, 2023
86918f8
fix: basic lifecycle of asyncio working
devraj Dec 18, 2023
baaf841
refactor: all tests are now async
devraj Dec 18, 2023
ad51624
Merge pull request #22 from anomaly/asyncio-migration
devraj Dec 18, 2023
cc2be32
chore: adds typer with all option
devraj Dec 18, 2023
1dc72c1
fix: async await issue in test
devraj Dec 18, 2023
620b652
refactor: async support for cli
devraj Dec 18, 2023
0c0c959
refactor: move configuration to package root
devraj Dec 18, 2023
d556a56
refactor: start of splitting up dto into sub packages
devraj Dec 20, 2023
4fbb17f
docs: adds placeholder for cli
devraj Dec 20, 2023
3d4985d
feat: finishes separating dto classes
devraj Dec 20, 2023
15e785f
refactor: drops original dto files REFS #21
devraj Dec 20, 2023
11a2e01
fix: names of discovery classes
devraj Dec 20, 2023
31ed719
fix: imports post dto refactor REFS #21
devraj Dec 20, 2023
c952888
refactor: wire up ref classes at module level
devraj Dec 20, 2023
fadb74e
refactor: wire up response classes at module level
devraj Dec 20, 2023
1a5cca7
refactor: wire up summary classes at module level
devraj Dec 20, 2023
bd6cb03
chore: dropso discovery top level class
devraj Dec 20, 2023
32060e6
fix: missing import for division
devraj Dec 20, 2023
ecde082
refactor: wire up detail classes at module level
devraj Dec 20, 2023
797b30d
refactor: various imports across the library
devraj Dec 20, 2023
d74ca9a
refactor: circular depdency issues
devraj Dec 20, 2023
ad69801
refactor: switches to relative imports
devraj Dec 20, 2023
c8b40c0
fix: circular depdency issues for summary
devraj Dec 20, 2023
780269e
fix: import issues with detail package
devraj Dec 20, 2023
99e6d2d
fix: import issues in response package
devraj Dec 20, 2023
8707998
refactor: enables event response
devraj Dec 20, 2023
09f6ee7
Merge pull request #23 from anomaly/refactor-structure
devraj Dec 20, 2023
b8efb17
fix: ref configuration
devraj Dec 20, 2023
8d3e93c
refactor: removes unsolicitated code
devraj Dec 23, 2023
32352ab
test: adds event test
devraj Dec 23, 2023
5017e84
fix: optionals on cardholder missing default value
devraj Dec 23, 2023
ef68cf6
refactor: event log parsing working
devraj Dec 23, 2023
425f3ad
refactor: finishes events handler
devraj Dec 23, 2023
538251a
refactor: time stamps are now datetime objects
devraj Dec 23, 2023
e5cb185
docs: update todo
devraj Dec 23, 2023
aac14f8
feat: adds events cli
devraj Dec 23, 2023
cb13421
feat: use pyndatic hooks to set timestamp
devraj Dec 24, 2023
36728fa
fix: disable mode_post_init to see if tests pass
devraj Dec 24, 2023
94d2af7
fix: discovery response cache not being utilised
devraj Dec 27, 2023
69ca87c
chore: update depdenencies and version number
devraj Dec 27, 2023
1d201f0
chore: add annotations
devraj Jan 1, 2024
55b77ec
docs: adds thinking beihnd cli and api design
devraj Jan 1, 2024
a818cd2
refactor: adds annotations
devraj Jan 1, 2024
53bd8b8
refactor: adds annotations and raises exception by default
devraj Jan 1, 2024
27242e9
chore: adds tap support
devraj Jan 5, 2024
269c9db
refactor: separate poetry packages
devraj Jan 6, 2024
2237330
refactor: pyproject to separate installables REFS #26
devraj Jan 7, 2024
68e6d2d
docs: updated readme
devraj Jan 7, 2024
c97a80f
fix: typo
devraj Jan 7, 2024
d1b6443
feat: adds pdf discovery
devraj Jan 21, 2024
365219d
chore: adds textual REFS #25
devraj Jan 21, 2024
6ea4c2d
docs: update project definition
devraj Jan 21, 2024
5a6ae43
feat: adds runner for textual console REFS #25
devraj Jan 21, 2024
dfb3ef2
chore: update version number
devraj Jan 21, 2024
e2c14ae
refactor: adds tests for pdf list
devraj Jan 22, 2024
db010fa
refactor: rename console package to tui
devraj Feb 2, 2024
5802e10
refactor: moves dashboard code out of app
devraj Feb 4, 2024
aa08764
docs: update todo
devraj Feb 4, 2024
74ee474
refactor: python scripts
devraj Feb 4, 2024
2bd0013
chore: update packages
devraj Mar 4, 2024
8aa727f
refactor: update packages
devraj Mar 9, 2024
de4cc97
chore: updates packages
devraj Mar 27, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
name: Bug report
about: Create a report to help us improve
title: ''
labels: ''
assignees: ''

---

**Describe the bug**
A clear and concise description of what the bug is.

**To Reproduce**
Steps to reproduce the behavior:
1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
4. See error

**Expected behavior**
A clear and concise description of what you expected to happen.

**Screenshots**
If applicable, add screenshots to help explain your problem.

**Desktop (please complete the following information):**
- OS: [e.g. iOS]
- Browser [e.g. chrome, safari]
- Version [e.g. 22]

**Smartphone (please complete the following information):**
- Device: [e.g. iPhone6]
- OS: [e.g. iOS8.1]
- Browser [e.g. stock browser, safari]
- Version [e.g. 22]

**Additional context**
Add any other context about the problem here.
20 changes: 20 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
name: Feature request
about: Suggest an idea for this project
title: ''
labels: ''
assignees: ''

---

**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

**Describe the solution you'd like**
A clear and concise description of what you want to happen.

**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.

**Additional context**
Add any other context or screenshots about the feature request here.
33 changes: 33 additions & 0 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Testing
on:
push:
branches:
- master
pull_request:
branches:
- master

jobs:
test:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version-file: pyproject.toml
- name: Install Task
uses: arduino/setup-task@v1
with:
version: 3.x
repo-token: ${{ secrets.GITHUB_TOKEN }}
- name: Install dependencies
run: |
pip install poetry
poetry install
- name: Run tests
run: |
export GACC_API_KEY=${{ secrets.GACC_API_KEY }}
task test
15 changes: 6 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
> Currently under heavy development, please check for stable release before use
# Gallagher Python Toolkit

# Gallagher Command Centre REST API Client

> Python idiomatic client for Gallagher Command Centre API
> Python idiomatic REST API client, a command line interface and a text based console 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 @@ -19,8 +17,7 @@ from gallagher import cc, const

cc.api_key = "GH_"

cc.discover()
cc.Customer.create()
cc.Customer.list()
```

> Note this project is **NOT** officially affiliated with Gallagher Security
Expand Down Expand Up @@ -131,7 +128,7 @@ 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.

**DO NOT** run the tests against a production system.
> It's **not recommended** to run tests against a production system.

### Data Transfer Objects

Expand All @@ -155,7 +152,7 @@ Resources are `fetchable`, `queryable`, `creatable`, `updatable` and `deletable`

Responses can be the object itself or a response layout

# Configuring the Command Centre
## Configuring the Command Centre

The following requires you to have an understanding of the Gallagher Command Centre and how to configure it. If you are unsure, please contact your Gallagher representative.

Expand Down Expand Up @@ -183,6 +180,6 @@ To check your API key:

![Command Centre Cloud Connections](assets/gallagher-rest-properties.png)

# License
## License

Distributed under the MIT License.
36 changes: 17 additions & 19 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,37 @@

The following is tracking which endpoints are available along with their test cases

- [ ] Authentication
- [ ] Base API route design
- [x] Authentication
- [x] Base API route design

## Alarms, events, and non-cardholder items

- [ ] Alarm search
- [ ] Alarm updates
- [ ] Alarm summary
- [x] Alarm summary
- [ ] Alarm detail
- [ ] Alarm history entry
- [ ] Alarm update request
- [ ] Event search
- [ ] Event summary
- [x] Event summary
- [ ] Event detail
- [ ] Event POST body
- [ ] Event groups
- [ ] Divisions
- [ ] Division
- [x] Event groups
- [x] Divisions
- [x] Division
- [ ] Division PATCH and POST example
- [ ] Item search
- [X] Item summary
- [X] Item detail
- [X] Item types
- [x] Item summary
- [x] Item detail
- [x] Item types
- [ ] Item update
- [ ] Item update subscription


## Cardholders and related items

- [ ] Cardholder search
- [ ] Cardholder summary
- [ ] Cardholder detail
- [x] Cardholder summary
- [x] Cardholder detail
- [ ] Cardholder POST example
- [ ] Cardholder Update Location POST example
- [ ] Cardholder PATCH example
Expand Down Expand Up @@ -64,13 +63,13 @@ The following is tracking which endpoints are available along with their test ca
- [ ] Competency summary
- [ ] Competency detail
- [ ] Card type search
- [ ] Card type
- [x] Card type
- [ ] Operator group search
- [ ] Operator group summary
- [ ] Operator group detail
- [ ] Operator group membership
- [ ] PDF definition search
- [ ] PDF definition
- [x] PDF definition
- [ ] Reception search
- [ ] Reception
- [ ] Redaction
Expand All @@ -94,7 +93,7 @@ The following is tracking which endpoints are available along with their test ca
- [ ] Alarm Zone summary
- [ ] Alarm Zone detail
- [ ] Day category search
- [X] Day category
- [x] Day category
- [ ] Door search
- [ ] Door summary
- [ ] Door detail
Expand All @@ -117,17 +116,16 @@ The following is tracking which endpoints are available along with their test ca
- [ ] Output summary
- [ ] Output detail
- [ ] Schedule search
- [X] Schedule summary
- [x] Schedule summary
- [ ] Schedule detail
- [ ] Schedule POST and PATCH
- [ ] Override end time


## PIV cards

- [ ] PIV card GET
- [ ] PIV card type
- [ ] PIV card create example
- [ ] PIV card update example
- [ ] PIV card data
- [ ] CHUID
- [ ] CHUID
22 changes: 20 additions & 2 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,28 @@ tasks:
cmds:
- poetry build
test:
desc: runs tests inside the server container
desc: runs tests inside the virtualenv
summary:
runs all the tests inside the virtualenv, optionally
provide the name of the test as an argument to run a single test
cmds:
- poetry run coverage run -m pytest -s
- poetry run coverage run -m pytest -s --tap tests/{{.CLI_ARGS}}
test:list:
desc: lists the available tests
summary:
runs collect only on pytest to list the tests available
cmds:
- poetry run pytest --co
test:coverreport:
desc: runs coverage inside the server container
cmds:
- poetry run coverage report -m
dev:textual:
desc: runs the textual cli
cmds:
- poetry run textual --
dev:gcon:
desc: runs text gallagher console in dev mode
cmds:
- poetry run textual run --dev gallagher.console:main

47 changes: 47 additions & 0 deletions docs/docs/cli.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Command Line Interface

We provide a command line interface to interact with the Gallagher Command Centre. It uses the API client to communicate with the server, which doubly serves as a reference example of how to use the API client.

> We use [typer](https://typer.tiangolo.com) to construct the CLI, which in turn uses [click](https://click.palletsprojects.com). We also use [rich](https://rich.readthedocs.io/en/stable/) to make the output nicer. The CLI is decoupled from the API client, and is not install by default.

We follow a `git` like `command`, `sub-command` pattern, so it should feel quite familiar.

poetry will install the alias `gal` for you to interact with the CLI. You can ask for help with:

```
gal --help
```

which will list the available commands:

```
Usage: gal [OPTIONS] COMMAND [ARGS]...

╭─ Options ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ --install-completion Install completion for the current shell. │
│ --show-completion Show completion for the current shell, to copy it or customize the installation. │
│ --help Show this message and exit. │
╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
╭─ Commands ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ alarms list or query alarms in the command centre │
│ ch query or manage cardholders │
│ events query command centre events │
╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
```

A simple example to get a list of cardholders looks like:

```
(gallagher-py3.11) ➜ gallagher git:(dto-implementation) ✗ gal ch list
Cardholders
┏━━━━━━┳━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┓
┃ Id ┃ First name ┃ Last name ┃ Authorised ┃
┡━━━━━━╇━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━╇━━━━━━━━━━━━┩
│ 8246 │ Johnetta │ Abdallah │ yes │
│ 7936 │ Socorro │ Abrahams │ yes │
│ 8374 │ Geoffrey │ Acey │ yes │
│ 8370 │ Weldon │ Acuff │ yes │
│ 7922 │ Rusty │ Adelsperger │ yes │
```

you can also ask each sub command to give you in
58 changes: 58 additions & 0 deletions docs/docs/design.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Design

A central feature to this client is it's detailed design, focused on a superior developer experience and performance. We also ensure that we follow design patterns outlined by Gallagher

## Data Transfer Objects

This a central part of our design. There are three types of schema definitions, each one of them suffixed with their intent:

- **Ref** are `References` to other objects, they using contain a `href` and possibly additional meta data such as a `name` or `id`
- **Summary** is what is returned by the Gallagher API in operations such as [searches](https://gallaghersecurity.github.io/cc-rest-docs/ref/cardholders.html), these are generally a subset of the full object
- **Detail** are the full object found at a particular `href`, they compound on the `Summary` schema and add additional attributes

I additional we have classes that defined responses which are suffixed with **Response**, these wrap structures which returns `hrefs` for `next` and `previous` responses and usually have a collection to hold the response.

Ensure that each Endpoint defines their own DTOs so you can test them for authenticity. Avoid writing generic classes.

While `Refs`, `Summary` and `Detail` responses have fields, and it would make sense from an efficiency point of view to inherit e.g `Summary` builds on `Ref`, this should be avoided so logically an instance of a `Ref` class doesn't assert true for `isinstance` of a `Summary` class.

## API Client Core

The `core` package in `cc` provides two important classes:

- `APIEndpoint` which all endpoint consumers configuration must inherit from
- `EndpointConfig` an instance of which each class must return as a result of the `get_config` method

Every Endpoint Consumer Class is expected to return an instance of `EndpointConfig` from the `get_config` method. Each configuration provides references to paths that are dynamically discovered as part of our bootstrapping process.

Never hard code URLs as this violates the [HATEOAS](https://en.wikipedia.org/wiki/HATEOAS) design principle.

Additionally each configuration will provide references to DTO classes that is used to parse responses, and details of the body.

```
class Alarms(
APIEndpoint
):
""" Alarms
"""

@classmethod
async def get_config(cls) -> EndpointConfig:
return EndpointConfig(
endpoint=Capabilities.CURRENT.features.alarms.alarms,
dto_list=AlarmResponse,
dto_retrieve=AlarmZoneSummary,
)
```

The above example shows the `Alarms` class which is a consumer of the `alarms` endpoint. It nominates `AlarmResponse` as the class the infrastructure will use to parse `list` responses and `AlarmZoneSummary` as the class to parse `retrieve` responses.

It references the `Capabilities.CURRENT` singleton which is a `Capabilities` instance that is bootstrapped at runtime. This is a singleton that is used to provide references to all endpoints.

If a command centre does not have a certain capability then the objects are set to `None` and accessing the feature raises an exception (more on this in other sections).

### Designing Endpoints

## Layout

Layout of our files
Loading
Loading