anomaly/gallagher

Create a CLI to interact with Gallagher Command Centre

Opened this issue · 4 comments

devraj commented

While building the API, I found myself constantly making http requests to test payloads. I have also been moving a lot of my workloads to the command line for services like stripe or github via their CLI.

I also have a set of httpie based payloads that I use to support some of our clients e.g:

echo -n '
{
  "accessGroups": {
    "add": [{
      "accessGroup": {
	    "href": "https://commandcentre-api-au.security.gallagher.cloud/api/access_groups/1052"
      },
      "from": "2023-04-11T10:30:00Z",
      "until": "2023-05-11T10:30:00Z"
    }]
  }
}' | http patch https://commandcentre-api-au.security.gallagher.cloud/api/cardholders/4149 "Authorization: GGL-API-KEY $GH_API_KEY"

the above adds an access group to a cardholder

The proposal is to build upon the REST API client and provide a cli to interact with the command centre to perform various operations.

A sample of what the user would be able to do would look like:

gl cardholder search devraj

or

gl cardholder get 3222
devraj commented

There's a feature request to make the library async see #18 however if the cli uses typer (which in turn uses click) then we should ensure that it is possible to use the library inside of the cli.

See also: fastapi/typer#88

devraj commented

See the rich pretty print protocol to provide the highlighting syntax from the __repr__ method

devraj commented

typer allows checking for environment vars before the cli is executed. Their basic example

import typer
from typing_extensions import Annotated


def main(name: Annotated[str, typer.Argument(envvar="AWESOME_NAME")] = "World"):
    print(f"Hello Mr. {name}")


if __name__ == "__main__":
    typer.run(main)

does not highlight how to use this feature when designing commands and sub commands. We ought to research this via discussions before we head into implementing it.

Our basic requirement is to have the GACC_API_KEY environment variable set to the Gallagher API key, which is set to the api_key property of the package.

We use rich to display most of our output, here's are some handy rich commands that will help explore it's features:

poetry run python -m rich.spinner

Get a list of spinners that are available in rich

poetry run python -m rich.live

Get a demo of displaying live data (handy for polling requests #19)

poetry run python -m rich.progress

See the thinking example from for use with #19

poetry run python -m rich.status

To get some COVID jokes