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

With aptible login --sso, open browser for token. #286

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
27 changes: 26 additions & 1 deletion lib/aptible/cli/agent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,11 @@ def login
if options[:sso]
begin
token = options[:sso]
token = ask('Paste token copied from Dashboard:') if token == 'sso'
if token == 'sso'
browser_open_url('https://dashboard.aptible.com/settings/cli-sso-token')
sleep 0.5
token = ask('Paste token copied from Dashboard:')
end
Base64.urlsafe_decode64(token.split('.').first)
save_token(token)
CLI.logger.info "Token written to #{token_file}"
Expand Down Expand Up @@ -258,6 +262,27 @@ def version_string
def toolbelt?
ENV['APTIBLE_TOOLBELT']
end

# Open the specified URL in the default system web browser
def browser_open_url(url)
case RbConfig::CONFIG.fetch('host_os')
when /darwin/
cmd = 'open'
when /linux|bsd/
cmd = 'xdg-open'
when /mswin|mingw|cygwin/
cmd = 'start'
else
CLI.logger.warn("Unknown OS: #{RbConfig::CONFIG.fetch('host_os').inspect}")
cmd = 'open'
end

if system([cmd, cmd], url)
CLI.logger.info('Opening browser window...')
else
CLI.logger.warn("Failed to open in browser: #{url.inspect}")
end
end
end
end
end