Class: Everywhere::Commands::PlatformAuthStatus
- Inherits:
-
Dry::CLI::Command
- Object
- Dry::CLI::Command
- Everywhere::Commands::PlatformAuthStatus
- Defined in:
- lib/everywhere/commands/platform/auth_status.rb
Overview
every platform auth status — show whether this machine is logged in, and
validate the saved token against the Platform.
Instance Method Summary collapse
Instance Method Details
#call(url: nil) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/everywhere/commands/platform/auth_status.rb', line 17 def call(url: nil, **) base = Everywhere::Platform::Client.base_url(url) creds = Everywhere::Platform::Credentials.load.for(base) return UI.warn("not logged in to #{base} — run `every platform login`") unless creds res = Everywhere::Platform::Client.new(base, token: creds["token"]).get("/cli/token") if res.ok? user = res.body["user"] || {} org = res.body["organization"] || {} tok = res.body["token"] || {} UI.ok("logged in to #{base}") UI.step("user: #{user["email"]}") UI.step("org: #{org["name"]} #{UI.dim("(#{org["id"]})")}") last = tok["last_used_at"] ? " · last used #{tok["last_used_at"]}" : "" UI.step("token: #{tok["hint"]}#{UI.dim(last)}") elsif res. UI.bad("saved token is invalid or revoked — run `every platform login`") else UI.bad("couldn't check status — HTTP #{res.status}") end rescue Everywhere::Error => e UI.bad(e.) end |