Sha256: 8c94a0b0bf6dda4a6f3d707c51702282708cb56b25e1751877c9bfcab2239c31

Contents?: true

Size: 1.37 KB

Versions: 117

Compression:

Stored size: 1.37 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 ['--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[: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

      data.each do |key, value|
        puts "%26.26s : %s" % [key, value]
      end
    end
  end
end

Version data entries

117 entries across 117 versions & 1 rubygems

Version Path
kontena-cli-1.3.0.rc2 lib/kontena/cli/master/token/create_command.rb
kontena-cli-1.3.0.rc1 lib/kontena/cli/master/token/create_command.rb
kontena-cli-1.3.0.pre2 lib/kontena/cli/master/token/create_command.rb
kontena-cli-1.3.0.pre1 lib/kontena/cli/master/token/create_command.rb
kontena-cli-1.2.2 lib/kontena/cli/master/token/create_command.rb
kontena-cli-1.2.2.rc2 lib/kontena/cli/master/token/create_command.rb
kontena-cli-1.2.2.rc1 lib/kontena/cli/master/token/create_command.rb
kontena-cli-1.2.1 lib/kontena/cli/master/token/create_command.rb
kontena-cli-1.2.1.rc1 lib/kontena/cli/master/token/create_command.rb
kontena-cli-1.2.0 lib/kontena/cli/master/token/create_command.rb
kontena-cli-1.2.0.rc3 lib/kontena/cli/master/token/create_command.rb
kontena-cli-1.2.0.rc2 lib/kontena/cli/master/token/create_command.rb
kontena-cli-1.2.0.rc1 lib/kontena/cli/master/token/create_command.rb
kontena-cli-1.2.0.pre3 lib/kontena/cli/master/token/create_command.rb
kontena-cli-1.2.0.pre2 lib/kontena/cli/master/token/create_command.rb
kontena-cli-1.1.6 lib/kontena/cli/master/token/create_command.rb
kontena-cli-1.2.0.pre1 lib/kontena/cli/master/token/create_command.rb
kontena-cli-1.1.5 lib/kontena/cli/master/token/create_command.rb
kontena-cli-1.1.5.rc3 lib/kontena/cli/master/token/create_command.rb
kontena-cli-1.1.5.rc2 lib/kontena/cli/master/token/create_command.rb