Sha256: 29c363957672d0d49a98c2e60a1d4e4ba9b05eeb83363b73da1f5b0061f6f3fd

Contents?: true

Size: 1.53 KB

Versions: 34

Compression:

Stored size: 1.53 KB

Contents

require_relative 'common'

module Kontena::Cli::Master::Token
  class CreateCommand < Kontena::Command

    include Kontena::Cli::Common
    include Common

    requires_current_master
    requires_current_master_token

    option ['-s', '--scopes'], '[SCOPES]', "Comma separated list of access scopes for the generated token", default: 'user'
    option ['-e', '--expires-in'], '[SECONDS]', "Access token expiration time. Use 0 for never.", default: '7200'
    option ['-c', '--code'], :flag, "Generate an authorization code"
    option ['-u', '--user'], '[EMAIL]', 'Generate a token for another user'
    option ['--id'], :flag, "Only output the token ID"
    option ['--token'], :flag, "Only output the access_token (or authorization code)"
    option ['-d', '--description'], '[DESCRIPTION]', 'Token description'

    option ['--return'], :flag, "Return the response hash", hidden: true

    def execute
      params = {
        response_type: self.code? ? 'code' : 'token',
        scope: self.scopes,
        expires_in: self.expires_in,
      }
      params[:description] = self.description if self.description
      params[:user] = self.user if self.user
      data = token_data_to_hash(client.post("/oauth2/authorize", params))

      return data if self.return?

      if self.id?
        puts data[:id]
        exit 0
      end

      if self.token?
        puts data[:access_token] || data[:code]
        exit 0
      end

      puts '%s:' % data.delete(:id)
      data.each do |key, value|
        puts "  %s: %s" % [key, value]
      end
    end
  end
end

Version data entries

34 entries across 34 versions & 2 rubygems

Version Path
krates-1.7.11 lib/kontena/cli/master/token/create_command.rb
krates-1.7.10 lib/kontena/cli/master/token/create_command.rb
krates-1.7.9 lib/kontena/cli/master/token/create_command.rb
krates-1.7.8 lib/kontena/cli/master/token/create_command.rb
krates-1.7.7 lib/kontena/cli/master/token/create_command.rb
krates-1.7.6 lib/kontena/cli/master/token/create_command.rb
krates-1.7.5 lib/kontena/cli/master/token/create_command.rb
krates-1.7.4 lib/kontena/cli/master/token/create_command.rb
krates-1.7.3 lib/kontena/cli/master/token/create_command.rb
krates-1.7.2 lib/kontena/cli/master/token/create_command.rb
krates-1.7.1 lib/kontena/cli/master/token/create_command.rb
krates-1.7.0 lib/kontena/cli/master/token/create_command.rb
krates-1.6.9 lib/kontena/cli/master/token/create_command.rb
krates-1.6.8 lib/kontena/cli/master/token/create_command.rb
krates-1.6.7 lib/kontena/cli/master/token/create_command.rb
krates-1.6.6 lib/kontena/cli/master/token/create_command.rb
krates-1.6.5 lib/kontena/cli/master/token/create_command.rb
krates-1.6.4 lib/kontena/cli/master/token/create_command.rb
krates-1.6.3 lib/kontena/cli/master/token/create_command.rb
krates-1.6.2 lib/kontena/cli/master/token/create_command.rb