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

Create a CLI to interact with Gallagher Command Centre #13

Open
devraj opened this issue Nov 12, 2023 · 4 comments
Open

Create a CLI to interact with Gallagher Command Centre #13

devraj opened this issue Nov 12, 2023 · 4 comments
Assignees
Milestone

Comments

@devraj
Copy link
Sponsor Member

devraj commented Nov 12, 2023

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 devraj self-assigned this Nov 21, 2023
@devraj
Copy link
Sponsor Member Author

devraj commented Dec 6, 2023

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: tiangolo/typer#88

devraj added a commit that referenced this issue Dec 6, 2023
basic layout of the cli application using typer and subcommands

REFS #13
devraj added a commit that referenced this issue Dec 6, 2023
subcommands have been setup in accordance to the documentation with typer
routing the cardholder commands and then fetching the data via the client
rich is rendering tables to the terminal

REFS #13
@devraj
Copy link
Sponsor Member Author

devraj commented Dec 6, 2023

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

@devraj
Copy link
Sponsor Member Author

devraj commented Dec 6, 2023

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.

devraj added a commit that referenced this issue Dec 7, 2023
moves assigning the environment variable to the top of the package
this should still check if the environment variable is available
before cli endpoints are executed

REFS #13
devraj added a commit that referenced this issue Dec 10, 2023
a proposed detail feature of the cli, this establishes a pattern
that we can use to build out the other parts of the cli

REFS #13

suggest that we merge this back into the dto-implementation branch
post this commit to continue development as a whole
devraj added a commit that referenced this issue Dec 18, 2023
moves the environment variable configuration to the root of the package
clean up various imports post asyncio workaround, see previous commit
for details on how typer asyncio works

REFS #18 #13
@devraj devraj added this to the alpha-3 milestone Apr 14, 2024
@devraj
Copy link
Sponsor Member Author

devraj commented May 5, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant