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

TSPS-322 Add functioning b2c login to CLI #139

Merged
merged 28 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
57f4f59
Change API repsonse to not break Python codegen
nmalfroy Sep 30, 2024
53e27d3
Example of how one might implement the cli with autogen
nmalfroy Sep 30, 2024
8255b48
Override parts of the oauth lib
nmalfroy Oct 3, 2024
18657f3
add poetry, still wip
mmorgantaylor Oct 4, 2024
de92701
wip refactoring
mmorgantaylor Oct 8, 2024
15332a4
remove totalResults from GetPipelinesResult
mmorgantaylor Oct 8, 2024
f35b0c4
some refactoring
mmorgantaylor Oct 9, 2024
c6f1a49
update readme
mmorgantaylor Oct 9, 2024
a35fc50
new poetry.lock
mmorgantaylor Oct 11, 2024
619dc70
refactor with help from cursor
mmorgantaylor Oct 15, 2024
557dcec
clean up, update README
mmorgantaylor Oct 15, 2024
72f6ab8
readme update
mmorgantaylor Oct 15, 2024
bbcf96e
more cleanup
mmorgantaylor Oct 15, 2024
b824e48
add pycache to .gitignore
mmorgantaylor Oct 15, 2024
cd6f3bd
ughhhh
mmorgantaylor Oct 15, 2024
7e6d6ae
restore gitignore for pycache
mmorgantaylor Oct 15, 2024
2a019a5
try this
mmorgantaylor Oct 15, 2024
65627c5
restore again
mmorgantaylor Oct 15, 2024
ec704be
try this x 32894r9823r89w38
mmorgantaylor Oct 15, 2024
214a52f
another try
mmorgantaylor Oct 15, 2024
0aa8c49
newline
mmorgantaylor Oct 15, 2024
e1581fa
update readme
mmorgantaylor Oct 15, 2024
a3c9f6b
some PR comments
mmorgantaylor Oct 16, 2024
fdb6864
update README
mmorgantaylor Oct 16, 2024
e7afb6f
awesome exception handling
mmorgantaylor Oct 16, 2024
353a306
simplify token file logic
mmorgantaylor Oct 16, 2024
25899ca
rename exception handler function
mmorgantaylor Oct 16, 2024
de9a542
use library oauth2_cli_auth.get_auth_url instead of custom function
mmorgantaylor Oct 23, 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
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,9 @@ gha-creds-*.json

### jEnv
.java-version

### Python CLI ###
/teaspoons-cli/teaspoons/__pycache__/
/teaspoons-cli/teaspoons/**/__pycache__/
/teaspoons-cli/venv/
/teaspoons-cli/teaspoons/generated/
12 changes: 7 additions & 5 deletions common/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -543,12 +543,14 @@ components:
$ref: '#/components/schemas/JobReport'

GetPipelinesResult:
type: array
items:
$ref: '#/components/schemas/Pipeline'
description: result of a getPipelines request
type: object
Copy link
Collaborator

@mmorgantaylor mmorgantaylor Oct 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changing from object to array will allow this response to be processed properly by pydantic, we think - see comment in teaspoons-cli/teaspoons/commands/pipelines.py: https://github.com/DataBiosphere/terra-scientific-pipelines-service/pull/139/files#diff-e76a95624e4f3d1403a026aba9a8900168703237cf6c6c6bd526637607c4a3a6R17

properties:
Pipeline:
$ref: '#/components/schemas/Pipeline'
results:
description: List of retrieved pipelines
type: array
items:
$ref: '#/components/schemas/Pipeline'

GetPipelineRunsResponse:
type: object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,7 @@ public ResponseEntity<ApiPipelineWithDetails> getPipelineDetails(
static ApiGetPipelinesResult pipelinesToApi(List<Pipeline> pipelineList) {
ApiGetPipelinesResult apiResult = new ApiGetPipelinesResult();

for (Pipeline pipeline : pipelineList) {
apiResult.add(pipelineToApi(pipeline));
}
apiResult.setResults(pipelineList.stream().map(PipelinesApiController::pipelineToApi).toList());

return apiResult;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ void getPipelinesOk() throws Exception {
new ObjectMapper()
.readValue(result.getResponse().getContentAsString(), ApiGetPipelinesResult.class);

assertEquals(testPipelineList.size(), response.size());
assertEquals(testPipelineList.size(), response.getResults().size());
}

@Test
Expand Down
13 changes: 13 additions & 0 deletions teaspoons-cli/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Teaspoons API URL
TEASPOONS_API_URL=https://tsps.dsde-dev.broadinstitute.org
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i assume at some point we'll want to parameterized this so it can run on different environments

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, added to AC for TSPS-321


# Port to use for local server (for auth)
SERVER_PORT=10444

# Oauth config stuff
OAUTH_OPENID_CONFIGURATION_URI=https://terradevb2c.b2clogin.com/terradevb2c.onmicrosoft.com/b2c_1a_signup_signin_dev/v2.0/.well-known/openid-configuration
OAUTH_CLIENT_ID=bbd07d43-01cb-4b69-8fd0-5746d9a5c9fe

# Teaspoons storage (absolute path or relative to user's home directory)
LOCAL_STORAGE_PATH=.teaspoons

29 changes: 29 additions & 0 deletions teaspoons-cli/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
BSD 3-Clause License
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this came from CAS im assuming? Do we have to do anything with this to keep it "up to date"?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't think so, though probably update the year...


Copyright (c) 2024, Broad Institute
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
69 changes: 68 additions & 1 deletion teaspoons-cli/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,72 @@
# Teaspoons CLI

## Python CLI structure
The CLI code is structured as follows:
```
teaspoons-cli
├── teaspoons
│ └── commands
│ │ └── __init__.py
│ │ └── auth.py
│ │ └── pipelines.py
│ └── generated
│ │ └── [auto-generated files for thin client]
├── └── tests (to be created)
│ └── __init__.py
│ └── auth_helper.py
│ └── cli.py
│ └── config.py
│ └── teaspoons
├── pyproject.toml
├── poetry.lock
├── README.md
```

Inside the `teaspoons` directory, we have the following files:
- `teaspoons` is the entrypoint for the CLI. It contains the main function that is called when the CLI is run.
- `auth.py` contains the code for authenticating with the Teaspoons service (Terra, via b2c).
- `config.py` contains the code for managing the CLI configuration via environment variables.
- `cli.py` assembles the CLI sub-modules that are defined in `commands/`.
- A future file will be included to contain the business logic for the CLI commands.
- The `commands` directory contains the CLI sub-modules. This is effectively the controller layer for the CLI.
- The `generated` directory contains the auto-generated files for the thin client, containing the python model classes and API calls.


## Using the CLI
For now, the CLI requires poetry to be installed to run. See the [Development](#development) section for instructions on how to install poetry.

To run the CLI, navigate to the `teaspoons-cli/teaspoons/` directory and run the following command:
```bash
./teaspoons COMMAND [ARGS]
```

For example, to authenticate with the Teaspoons service, run the following command:
```bash
./teaspoons auth login
```

To list the pipelines in the Teaspoons service, run the following command:
```bash
./teaspoons pipelines list
```

See WIP documentation for the CLI [here](https://docs.google.com/document/d/1ovbcHCzdyuC8RjFfkVJZiuDTQ_UAVrglSxSGaZwppoY/edit?tab=t.0#heading=h.jfsr3j3x0zjr).


## Development
You'll need to have poetry installed to manage python dependencies. Instructions for installing poetry can be found [here](https://python-poetry.org/docs/).


## Python thick client auto-generation
To generate the Python thick client (which will also generate the thin client), run the following command:
```bash
./gradlew :teaspoons-cli:cliBuild
```


## Python thin client auto-generation
Note: If you've already built the thick client, you don't need to generate the thin client separately.

We use the [OpenAPI Generator](https://github.com/OpenAPITools/openapi-generator) to generate the "thin" Python client,
which is then used to build the Python-based "thick" CLI tool.

Expand All @@ -9,7 +75,8 @@ To generate the Python thin client, run the following command:
./gradlew :teaspoons-cli:openApiGenerate
```

This will produce generated files at `/teaspoons-cli/build/`.
This will produce generated files at `/teaspoons-cli/teaspoons/generated/`.

Note we do not run the openApiGenerate task as part of the main Teaspoons build, as it is not necessary for the
service itself and we don't want any potential bugs in the CLI to affect the service.

Loading
Loading