Module: Kontena::Cli::Master::Token::Common

Included in:
CreateCommand, CurrentCommand, ListCommand, ShowCommand
Defined in:
lib/kontena/cli/master/token/common.rb

Instance Method Summary collapse

Instance Method Details

#token_data_to_hash(data) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/kontena/cli/master/token/common.rb', line 4

def token_data_to_hash(data)
  output = {
    id: data["id"],
    token_type:  data["token_type"] || data["grant_type"],
    scopes: data["scopes"],
    user_id: data["user"]["id"],
    user_email: data["user"]["email"],
    user_name: data["user"]["name"],
    server_name: data["server"]["name"],
    description: data['description']
  }
  if data["token_type"] == "bearer"
    output[:access_token_last_four] = data["access_token_last_four"]
    output[:refresh_token_last_four] = data["refresh_token_last_four"]
    output[:token_type] =  data["token_type"]
    output[:access_token] = data["access_token"] if data["access_token"]
    output[:refresh_token] = data["refresh_token"] if data["refresh_token"]
    output[:expires_in] = data["expires_in"]
  else
    output[:code] = data["code"]
    output[:token_type] =  data["grant_type"]
  end
  output
end