Skip to content

Commit

Permalink
First Apollo CLI commands: config, login, logout, and status (GMOD#354)
Browse files Browse the repository at this point in the history
* Remove clientId from plugin

* Consolidate to one login endpoint

* Fix menu items not appearing

* Stub for apollo login (issue GMOD#330 and GMOD#331)

* A few mostly automatic fixes

* Temporary commit with stubs for login using name and password

* Start implementing login with username and password

* Root login should work but needs tidying up for errors

* Misc cleanups

* Fix loading of commands

* Get one test working

* Get tests working even with imported files

* Add coverage to CLI tests

* Don't lint bin/ files

* Draft for apollo config cli

* Refactor to allow multiple profiles

* Add some validation and update tests

* Update oclif so we can use flagSortOrder

* Make login subcommand aware of profiles

* Add missing file

* Refactor Profile to have address and accessType not null

* Misc. cleanup

* Address [checklist](GMOD#354 (review))

This commit should address most of the items in
GMOD#354 (review)

There are tests for most of them.

`"default.rootCredentials.password" must be a string` occurs if an entry is
expected to be string and instead is a number without quotes. The cli quotes as
appropriate.

> Make sure all commands print a sensible error message if the config file is
> not valid YAML or doesn't pass validation

Currently, the cli fails with a fairly friendly message if the yaml is
malformed, but if it is valid, it will process it anyway

* Lint and formatting fixes

* Make sure tests work if config dir doesn't exist yet

* Disable one test until server can be mocked

---------

Co-authored-by: Garrett Stevens <stevens.garrett.j@gmail.com>
  • Loading branch information
dariober and garrettjstevens authored Feb 13, 2024
1 parent bf85e02 commit 955d683
Show file tree
Hide file tree
Showing 39 changed files with 7,191 additions and 179 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ dist/
.eslintrc.js
esm/
coverage/
bin/
7 changes: 7 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,13 @@ module.exports = {
},
env: { node: true },
},
{
files: ['./packages/apollo-cli/*.{c,}js'],
parserOptions: {
project: 'packages/apollo-cli/tsconfig.eslint.json',
},
env: { node: true },
},
// Specify Node env and tsconfig for cypress testing and config files
{
files: [
Expand Down
15 changes: 14 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,19 @@
"<node_internals>/**",
"**/.yarn/cache/**"
]
}
},
{
"type": "node",
"request": "launch",
"name": "Execute Command",
"skipFiles": [
"<node_internals>/**"
],
"program": "${workspaceFolder}/bin/dev.js",
"args": [
"hello",
"world",
],
},
],
}
7 changes: 7 additions & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ packageExtensions:
cypress-mongodb@*:
dependencies:
bson: ^4
fancy-test@*:
dependencies:
chai: "*"
material-ui-popup-state@*:
peerDependencies:
"@emotion/react": "*"
Expand All @@ -18,6 +21,10 @@ packageExtensions:
mobx-react@*:
peerDependencies:
react-dom: "*"
mocha@*:
dependencies:
ts-node: "*"
source-map-support: "*"
mongoose-id-validator@*:
peerDependencies:
mongoose: "*"
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"start:server": "yarn workspace apollo-collaboration-server run start",
"start:plugin": "yarn workspace jbrowse-plugin-apollo run start",
"start": "npm-run-all --print-label --parallel start:shared start:server start:plugin",
"test": "yarn workspace jbrowse-plugin-apollo run test:ci"
"test": "yarn workspaces foreach --all run test:ci"
},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^6.1.0",
Expand Down
14 changes: 14 additions & 0 deletions packages/apollo-cli/.mocharc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
require:
- ../../.pnp.cjs
watch-extensions:
- ts
recursive: true
reporter: spec
forbidOnly: true
timeout: 60000
node-option:
- import=tsx
- no-warnings=ExperimentalWarning
- loader=@istanbuljs/esm-loader-hook
- experimental-loader=../../.pnp.loader.mjs
8 changes: 8 additions & 0 deletions packages/apollo-cli/.nycrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
extends: '@istanbuljs/nyc-config-typescript'
all: true
reporter:
- lcov
- text
include:
- src/**
138 changes: 138 additions & 0 deletions packages/apollo-cli/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
# oclif-hello-world

oclif example Hello World CLI

[![oclif](https://img.shields.io/badge/cli-oclif-brightgreen.svg)](https://oclif.io)
[![CircleCI](https://circleci.com/gh/oclif/hello-world/tree/main.svg?style=shield)](https://circleci.com/gh/oclif/hello-world/tree/main)
[![GitHub license](https://img.shields.io/github/license/oclif/hello-world)](https://github.com/oclif/hello-world/blob/main/LICENSE)

<!-- toc -->

- [Usage](#usage)
- [Commands](#commands)
<!-- tocstop -->

# Usage

<!-- usage -->

```sh-session
$ npm install -g apollo-cli
$ apollo COMMAND
running command...
$ apollo (--version)
apollo-cli/0.0.0 linux-x64 node-v18.19.0
$ apollo --help [COMMAND]
USAGE
$ apollo COMMAND
...
```

<!-- usagestop -->

# Commands

<!-- commands -->

- [`apollo config [KEY] [VALUE]`](#apollo-config-key-value)
- [`apollo help [COMMANDS]`](#apollo-help-commands)
- [`apollo login`](#apollo-login)
- [`apollo logout`](#apollo-logout)
- [`apollo status`](#apollo-status)

## `apollo config [KEY] [VALUE]`

Get or set Apollo configuration options

```
USAGE
$ apollo config [KEY] [VALUE] [-p <value>]
ARGUMENTS
KEY Name of configuration parameter
VALUE Parameter value
FLAGS
-p, --profile=<value> [default: default] Set or get configuration for this profile
DESCRIPTION
Get or set Apollo configuration options
```

_See code:
[src/commands/config.ts](https://github.com/GMOD/Apollo3/blob/v0.0.0/packages/apollo-cli/src/commands/config.ts)_

## `apollo help [COMMANDS]`

Display help for apollo.

```
USAGE
$ apollo help [COMMANDS] [-n]
ARGUMENTS
COMMANDS Command to show help for.
FLAGS
-n, --nested-commands Include all nested commands in the output.
DESCRIPTION
Display help for apollo.
```

_See code:
[@oclif/plugin-help](https://github.com/oclif/plugin-help/blob/v6.0.8/src/commands/help.ts)_

## `apollo login`

Log in to Apollo

```
USAGE
$ apollo login [--profile <value>] [-a <value>] [-u <value>] [-p <value>] [-f]
FLAGS
-a, --address=<value> Address of Apollo server
-f, --force Force re-authentication even if user is already logged in
-p, --password=<value> Password for <username>
-u, --username=<value> Username for root login
--profile=<value> [default: default] Use credentials from this profile
DESCRIPTION
Log in to Apollo
```

_See code:
[src/commands/login.ts](https://github.com/GMOD/Apollo3/blob/v0.0.0/packages/apollo-cli/src/commands/login.ts)_

## `apollo logout`

Log out of Keycloak

```
USAGE
$ apollo logout
DESCRIPTION
Log out of Keycloak
```

_See code:
[src/commands/logout.ts](https://github.com/GMOD/Apollo3/blob/v0.0.0/packages/apollo-cli/src/commands/logout.ts)_

## `apollo status`

View authentication status

```
USAGE
$ apollo status
DESCRIPTION
View authentication status
```

_See code:
[src/commands/status.ts](https://github.com/GMOD/Apollo3/blob/v0.0.0/packages/apollo-cli/src/commands/status.ts)_

<!-- commandsstop -->
3 changes: 3 additions & 0 deletions packages/apollo-cli/bin/dev.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@echo off

node --loader ts-node/esm --no-warnings=ExperimentalWarning "%~dp0\dev" %*
9 changes: 9 additions & 0 deletions packages/apollo-cli/bin/dev.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env -S node --loader ts-node/esm --no-warnings=ExperimentalWarning

// eslint-disable-next-line node/shebang
async function main() {
const {execute} = await import('@oclif/core')
await execute({development: true, dir: import.meta.url})
}

await main()
3 changes: 3 additions & 0 deletions packages/apollo-cli/bin/run.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@echo off

node "%~dp0\run" %*
8 changes: 8 additions & 0 deletions packages/apollo-cli/bin/run.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env node

async function main() {
const {execute} = await import('@oclif/core')
await execute({dir: import.meta.url})
}

await main()
78 changes: 78 additions & 0 deletions packages/apollo-cli/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
{
"name": "apollo-cli",
"description": "CLI for managing an Apollo Collaboration Server",
"version": "0.0.0",
"author": "Apollo Team",
"repository": {
"type": "git",
"url": "https://github.com/GMOD/Apollo3.git",
"directory": "packages/apollo-cli"
},
"bin": {
"apollo": "./bin/run.js"
},
"type": "module",
"main": "",
"types": "dist/index.d.ts",
"exports": "./dist/index.js",
"engines": {
"node": ">=18.0.0"
},
"files": [
"/bin",
"/dist",
"/oclif.manifest.json"
],
"scripts": {
"build": "shx rm -rf dist && tsc -b",
"dev": "tsx bin/dev.js",
"postpack": "shx rm -f oclif.manifest.json",
"posttest": "yarn lint",
"prepack": "yarn build && oclif manifest && oclif readme",
"prepare": "yarn build",
"test": "mocha 'src/**/*.test.ts'",
"test:ci": "nyc mocha 'src/**/*.test.ts'",
"version": "oclif readme && git add README.md"
},
"dependencies": {
"@inquirer/input": "^1.2.14",
"@inquirer/password": "^1.1.14",
"@inquirer/select": "^1.3.1",
"@oclif/core": "^3.18.2",
"@oclif/plugin-help": "^6.0.8",
"joi": "^17.7.0",
"open": "^9.1.0",
"tslib": "^2.3.1",
"yaml": "^2.3.4"
},
"devDependencies": {
"@istanbuljs/esm-loader-hook": "^0.2.0",
"@istanbuljs/nyc-config-typescript": "^1.0.2",
"@oclif/test": "^3.1.3",
"@types/chai": "^4",
"@types/inquirer": "^9.0.7",
"@types/mocha": "^10",
"@types/node": "^18.14.2",
"babel-plugin-istanbul": "^6.1.1",
"mocha": "^10.2.0",
"nyc": "^15.1.0",
"oclif": "^4.4.2",
"shx": "^0.3.3",
"ts-node": "^10.3.0",
"tsx": "^4.6.2",
"typescript": "^5.1.6"
},
"oclif": {
"helpOptions": {
"flagSortOrder": "none"
},
"bin": "apollo",
"dirname": "apollo-cli",
"commands": "./dist/commands",
"plugins": [
"@oclif/plugin-help"
],
"repositoryPrefix": "<%- repo %>/blob/v<%- version %>/packages/apollo-cli/<%- commandPath %>",
"topicSeparator": " "
}
}
Loading

0 comments on commit 955d683

Please sign in to comment.