-
Notifications
You must be signed in to change notification settings - Fork 273
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(platform): add client login to CLI
* Added login and logout commands (not included in the docs for now) * Auth logic for reading and storing client auth tokens (we use the local SQLite DB for this). * Auth logic for visiting the platform's login page, and for receiving redirects from that page containing a valid client token.
- Loading branch information
Showing
13 changed files
with
440 additions
and
37 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* Copyright (C) 2018-2020 Garden Technologies, Inc. <[email protected]> | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
import { Command, CommandParams, CommandResult } from "./base" | ||
import { printHeader } from "../logger/util" | ||
import dedent = require("dedent") | ||
import { login } from "../platform/auth" | ||
|
||
export class LoginCommand extends Command { | ||
name = "login" | ||
help = "Log in to Garden Cloud." | ||
hidden = true | ||
|
||
description = dedent` | ||
Logs you in to Garden Cloud. Subsequent commands will have access to platform features. | ||
` | ||
|
||
async action({ garden, log, headerLog }: CommandParams): Promise<CommandResult> { | ||
printHeader(headerLog, "Login", "cloud") | ||
|
||
if (garden.platformUrl) { | ||
await login(garden.platformUrl, log) | ||
} | ||
|
||
return {} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* Copyright (C) 2018-2020 Garden Technologies, Inc. <[email protected]> | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
import { Command, CommandParams, CommandResult } from "./base" | ||
import { printHeader } from "../logger/util" | ||
import dedent = require("dedent") | ||
import { clearAuthToken } from "../platform/auth" | ||
|
||
export class LogOutCommand extends Command { | ||
name = "logout" | ||
help = "Log out of Garden Cloud." | ||
hidden = true | ||
|
||
description = dedent` | ||
Logs you out of Garden Cloud. | ||
` | ||
|
||
async action({ log, headerLog }: CommandParams): Promise<CommandResult> { | ||
printHeader(headerLog, "Log out", "cloud") | ||
|
||
await clearAuthToken(log) | ||
|
||
return {} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/* | ||
* Copyright (C) 2018-2020 Garden Technologies, Inc. <[email protected]> | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
import { Entity, Column, Index } from "typeorm" | ||
import { GardenEntity } from "../base-entity" | ||
|
||
@Entity() | ||
@Index(["token"], { unique: true }) | ||
export class ClientAuthToken extends GardenEntity { | ||
@Column() | ||
token: string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.