kodeco 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +3 -2
- data/lib/periscope/cli.rb +2 -11
- data/lib/periscope/commands/logout.rb +47 -0
- data/lib/periscope/version.rb +1 -1
- data/lib/periscope.rb +1 -0
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 21e401351ab9adc6500a6f950ae55044bb443ca6de317ca57acf8bc25f89bbbd
|
|
4
|
+
data.tar.gz: b5ba461481bfa7a3023027cf780d0a58f1e570013364e433bbf3ffbf9fba7cad
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e2f70ef215eec74514d602c5d4de7fb1ef8f8fa15a7bbbafc5243b38ad07a7abeb4fecd7752885068e84776d850551a6b89876d7878405be05432e96443f657f
|
|
7
|
+
data.tar.gz: a6439d86cf76759ea24c873f9eb2c09a0c3b18a7ed38cba3035b2066f532734556eacc36946bf7b97f48cd51d73b9a37cfaf5f02114d60d13871f1da255ba93a
|
data/README.md
CHANGED
|
@@ -52,8 +52,9 @@ admin. A login gets whichever of the requested scopes you hold, and `login`
|
|
|
52
52
|
lists any that weren't granted; a grant added later needs a fresh
|
|
53
53
|
`kodeco login`.
|
|
54
54
|
|
|
55
|
-
`logout`
|
|
56
|
-
|
|
55
|
+
`logout` signs the session out on guardpost, then deletes the local
|
|
56
|
+
credentials. If guardpost can't be reached, it still deletes them and says
|
|
57
|
+
so; the session then ends within 7 days, or an admin can sign it out.
|
|
57
58
|
|
|
58
59
|
Every command takes:
|
|
59
60
|
|
data/lib/periscope/cli.rb
CHANGED
|
@@ -10,13 +10,14 @@ module Periscope
|
|
|
10
10
|
include Commands::Kerching
|
|
11
11
|
include Commands::Flags
|
|
12
12
|
include Commands::Shortlinks
|
|
13
|
+
include Commands::Logout
|
|
13
14
|
|
|
14
15
|
USAGE = <<~TEXT
|
|
15
16
|
Usage: kodeco <command> [options]
|
|
16
17
|
|
|
17
18
|
Commands:
|
|
18
19
|
login [--scopes "a b"] [--no-browser] Log in with guardpost's device-code flow
|
|
19
|
-
logout
|
|
20
|
+
logout Sign out on guardpost and delete the local credentials
|
|
20
21
|
whoami [--app guardpost|kerching|carolus]
|
|
21
22
|
Show who an app takes you to be
|
|
22
23
|
user <email|rwuuid> Show guardpost's customer summary
|
|
@@ -37,8 +38,6 @@ module Periscope
|
|
|
37
38
|
TEXT
|
|
38
39
|
|
|
39
40
|
COMMANDS = %w[login logout whoami user orders order subscription problems flags shortlinks].freeze
|
|
40
|
-
LOGOUT_NOTE = "guardpost has no revoke endpoint, so the server session lasts up to 7 days " \
|
|
41
|
-
"unless an admin revokes it."
|
|
42
41
|
|
|
43
42
|
def initialize(argv, env: ENV, stdout: $stdout, stderr: $stderr, login_options: {})
|
|
44
43
|
@argv = argv.dup
|
|
@@ -96,14 +95,6 @@ module Periscope
|
|
|
96
95
|
"then run kodeco login again."
|
|
97
96
|
end
|
|
98
97
|
|
|
99
|
-
def cmd_logout
|
|
100
|
-
parse_options
|
|
101
|
-
deleted = store.with_lock { store.delete }
|
|
102
|
-
emit({ "logged_out" => true, "had_credentials" => !deleted.nil?, "note" => LOGOUT_NOTE }) do
|
|
103
|
-
deleted ? "Logged out locally. #{LOGOUT_NOTE}" : "Not logged in; there was nothing to delete."
|
|
104
|
-
end
|
|
105
|
-
end
|
|
106
|
-
|
|
107
98
|
def cmd_whoami
|
|
108
99
|
opts = parse_options { |parser, o| parser.on("--app APP", Config::APPS) { |v| o[:app] = v } }
|
|
109
100
|
data = client.get(opts[:app] || "guardpost", "/api/v2/whoami")["data"] || {}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Periscope
|
|
4
|
+
module Commands
|
|
5
|
+
# kodeco logout
|
|
6
|
+
module Logout
|
|
7
|
+
REVOKE_PATH = "/api/v2/auth/revoke"
|
|
8
|
+
|
|
9
|
+
private
|
|
10
|
+
|
|
11
|
+
def cmd_logout
|
|
12
|
+
parse_options
|
|
13
|
+
revoked = false
|
|
14
|
+
reason = nil
|
|
15
|
+
deleted = store.with_lock do
|
|
16
|
+
refresh_token = store.read&.dig("refresh_token")
|
|
17
|
+
revoked, reason = revoke(refresh_token) if refresh_token
|
|
18
|
+
store.delete
|
|
19
|
+
end
|
|
20
|
+
emit({ "logged_out" => true, "had_credentials" => !deleted.nil?, "revoked" => revoked }) do
|
|
21
|
+
logout_text(deleted, revoked, reason)
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
# Returns [revoked, reason]. It doesn't raise for guardpost's answer or a
|
|
26
|
+
# network error, so the local credentials are deleted whatever happens.
|
|
27
|
+
def revoke(refresh_token)
|
|
28
|
+
res = http.post_form("#{config.url('guardpost')}#{REVOKE_PATH}",
|
|
29
|
+
token: refresh_token, token_type_hint: "refresh_token")
|
|
30
|
+
return [true, nil] if res.status == 200
|
|
31
|
+
|
|
32
|
+
[false, "guardpost answered #{res.status}#{": #{res.error_message}" if res.error_message}"]
|
|
33
|
+
rescue Error => e
|
|
34
|
+
[false, e.message]
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def logout_text(deleted, revoked, reason)
|
|
38
|
+
return "Not logged in; there was nothing to delete." unless deleted
|
|
39
|
+
return "Logged out, and signed out on guardpost." if revoked
|
|
40
|
+
return "Logged out locally. There was no refresh token to sign out on guardpost with." unless reason
|
|
41
|
+
|
|
42
|
+
"Logged out locally, but couldn't reach guardpost to end the session (#{reason}).\n" \
|
|
43
|
+
"The session ends within 7 days, or an admin can sign it out."
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
data/lib/periscope/version.rb
CHANGED
data/lib/periscope.rb
CHANGED
|
@@ -16,4 +16,5 @@ require_relative "periscope/commands/user"
|
|
|
16
16
|
require_relative "periscope/commands/kerching"
|
|
17
17
|
require_relative "periscope/commands/flags"
|
|
18
18
|
require_relative "periscope/commands/shortlinks"
|
|
19
|
+
require_relative "periscope/commands/logout"
|
|
19
20
|
require_relative "periscope/cli"
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: kodeco
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.3.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Kodeco
|
|
@@ -22,6 +22,7 @@ files:
|
|
|
22
22
|
- lib/periscope/client.rb
|
|
23
23
|
- lib/periscope/commands/flags.rb
|
|
24
24
|
- lib/periscope/commands/kerching.rb
|
|
25
|
+
- lib/periscope/commands/logout.rb
|
|
25
26
|
- lib/periscope/commands/shortlinks.rb
|
|
26
27
|
- lib/periscope/commands/user.rb
|
|
27
28
|
- lib/periscope/config.rb
|