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

Add cb logout command. #49

Merged
merged 1 commit into from
Jun 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Added
- `cb logout` to logout a user from the CLI.


## [2.1.0] - 2022-06-03
### Added
Expand Down
3 changes: 2 additions & 1 deletion src/cb/completion.cr
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ class CB::Completion
"--help\tShow help and usage",
"version\tShow version information",
"login\tStore API key",
"logout\tRemove stored API key and token",
"token\tGet current API token",
"list\tList clusters",
"team\tManage teams",
Expand All @@ -111,7 +112,7 @@ class CB::Completion
if @client
options
else
options.first 3
options.first 4
end
end

Expand Down
4 changes: 4 additions & 0 deletions src/cb/creds.cr
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,8 @@ struct CB::Creds
def delete
File.delete CONFIG/host
end

def self.delete(host)
File.delete(CONFIG/host) if File.exists?(CONFIG/host)
end
end
10 changes: 10 additions & 0 deletions src/cb/logout.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
require "./action"

module CB
class Logout < Action
def run
Creds.delete(CB::HOST)
Token.delete(CB::HOST)
end
end
end
4 changes: 4 additions & 0 deletions src/cb/token.cr
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ struct CB::Token
fetch? host
end

def self.delete(host)
File.delete(file_path(host)) if File.exists?(file_path(host))
end

def expires_at : Time
Time.unix expires
end
Expand Down
5 changes: 5 additions & 0 deletions src/cli.cr
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ op = OptionParser.new do |parser|
action = CB::Login.new
end

parser.on("logout", "Remove stored API key and tokens") do
parser.banner = "cb logout"
action = CB::Logout.new
end

parser.on("list", "List clusters") do
parser.banner = "cb list"
set_action List
Expand Down