kodeco 0.1.0 → 0.1.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9a8113bf48c09c6754ee161ccd1568779c99d1d873f943b31cb4c4901e9bd474
4
- data.tar.gz: f3ec99a38bbb68e90fc594d7702d1ddad0b3a916c3768d47e706b328f960ca07
3
+ metadata.gz: 92f1b3f3a2c07ef7de80d5e2bcf2e7dd6989cd5baa29c56d085ea8fe61294e66
4
+ data.tar.gz: 75794675c957b94474ece30dfaebb15c2c28f3b0798208b48242aa7989fb1e94
5
5
  SHA512:
6
- metadata.gz: 4a2ca478260ec6f8475be66981d8ae253dd6da00b2c3f23b249039332da5b355a18dc1783f99cd259e78264fd0fe898aabd5ac07f1a4ee8eef5631c63c042f27
7
- data.tar.gz: b36b0bfb1eb73c2db436102551a85736a7825ab18803641177a1b0d2a061ad784a75c38d3e9d7a406bfec916e972134f6b82a1bc60d44781c3bbbc49cdc6f315
6
+ metadata.gz: 95eac6af137ca2809784e1adc765a4143a54bf7f0891236f105810645b5296de87c08367012c72a304361dd96a82940aa31efe85bb2036eaf58a029f7bcf1a6b
7
+ data.tar.gz: 846d4357394ca12d042e4cf57476975866289452a0f3b74f764d0300e5503a0657e5efd45646ed155a531a4e1db39ddce6d39ebebfae2ed2650e078922232212
data/README.md CHANGED
@@ -34,8 +34,10 @@ for lists.
34
34
  `login` uses guardpost's device-code flow: it prints a code and a link to
35
35
  approve it, and opens the link in a browser when run in a terminal. The
36
36
  default scopes are `users:read support:read orders:read learning:read
37
- flags:read`. If you lack a grant for one of them, approval fails; run
38
- `kodeco login --scopes "..."` and leave it out.
37
+ flags:read`. Scopes other than `flags:read` need a grant from a guardpost
38
+ admin. A login gets whichever of the requested scopes you hold, and `login`
39
+ lists any that weren't granted; a grant added later needs a fresh
40
+ `kodeco login`.
39
41
 
40
42
  `logout` deletes the local credentials. guardpost has no revoke endpoint, so
41
43
  the server session lasts up to 7 days unless an admin revokes it.
data/lib/periscope/cli.rb CHANGED
@@ -68,9 +68,25 @@ module Periscope
68
68
  opener = method(:open_browser) if @stdout.tty? && opts.fetch(:browser, true)
69
69
  login = Login.new(config: config, store: store, http: http, out: @json ? @stderr : @stdout,
70
70
  opener: opener, **@login_options)
71
- credentials = login.call(opts[:scopes] || Login::DEFAULT_SCOPES)
72
- result = { "logged_in" => true, "scope" => credentials["scope"], "apps" => credentials["access_tokens"].keys }
73
- emit(result) { "Logged in to #{config.url('guardpost')} with scope: #{credentials['scope']}" }
71
+ requested = (opts[:scopes] || Login::DEFAULT_SCOPES).split
72
+ result = login_result(requested, login.call(requested.join(" ")))
73
+ emit(result) { login_text(result["granted"], result["missing"]) }
74
+ end
75
+
76
+ # guardpost approves a login with only the scopes the user holds, so
77
+ # compare what was asked for with what came back.
78
+ def login_result(requested, credentials)
79
+ granted = credentials["scope"].to_s.split
80
+ { "logged_in" => true, "requested" => requested, "granted" => granted, "missing" => requested - granted,
81
+ "scope" => credentials["scope"], "apps" => credentials["access_tokens"].keys }
82
+ end
83
+
84
+ def login_text(granted, missing)
85
+ text = "Logged in with: #{granted.empty? ? '(no scopes)' : granted.join(', ')}"
86
+ return text if missing.empty?
87
+
88
+ "#{text}\nNot granted: #{missing.join(', ')}. Ask an admin to add them on your guardpost user page, " \
89
+ "then run kodeco login again."
74
90
  end
75
91
 
76
92
  def cmd_logout
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Periscope
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.1"
5
5
  end
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.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kodeco