Skip to content

Commit

Permalink
TSPS-322 Add functioning b2c login to CLI (#139)
Browse files Browse the repository at this point in the history
Co-authored-by: Morgan Taylor <[email protected]>
  • Loading branch information
nmalfroy and mmorgantaylor authored Oct 23, 2024
1 parent c8c19bf commit 69a0212
Show file tree
Hide file tree
Showing 20 changed files with 702 additions and 12 deletions.
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
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

# 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

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

0 comments on commit 69a0212

Please sign in to comment.