Skip to content
Open
Show file tree
Hide file tree
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
4 changes: 3 additions & 1 deletion lib/kubeclient/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,9 @@ def fetch_user_key_data(user)

def fetch_user_auth_options(user)
options = {}
if user.key?('token')
if user.key?('tokenFile')
options[:bearer_token_file] = user['tokenFile']
elsif user.key?('token')
options[:bearer_token] = user['token']
elsif user.key?('exec_result') && user['exec_result'].key?('token')
options[:bearer_token] = user['exec_result']['token']
Expand Down
8 changes: 8 additions & 0 deletions test/config/userauth.kubeconfig
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ contexts:
namespace: default
user: system:admin:token
name: localhost/system:admin:token
- context:
cluster: localhost:6443
namespace: default
user: system:admin:token-file
name: localhost/system:admin:token-file
- context:
cluster: localhost:6443
namespace: default
Expand All @@ -21,6 +26,9 @@ users:
- name: system:admin:token
user:
token: 0123456789ABCDEF0123456789ABCDEF
- name: system:admin:token-file
user:
tokenFile: /path/to/secret/token
- name: system:admin:userpass
user:
username: admin
Expand Down
21 changes: 19 additions & 2 deletions test/test_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,18 +98,35 @@ def test_nouser
def test_user_token
config = Kubeclient::Config.read(config_file('userauth.kubeconfig'))
assert_equal(
['localhost/system:admin:token', 'localhost/system:admin:userpass'],
['localhost/system:admin:token',
'localhost/system:admin:token-file',
'localhost/system:admin:userpass'],
config.contexts
)
context = config.context('localhost/system:admin:token')
check_context(context, ssl: true, custom_ca: false, client_cert: false)
assert_equal('0123456789ABCDEF0123456789ABCDEF', context.auth_options[:bearer_token])
end

def test_user_token_file
config = Kubeclient::Config.read(config_file('userauth.kubeconfig'))
assert_equal(
['localhost/system:admin:token',
'localhost/system:admin:token-file',
'localhost/system:admin:userpass'],
config.contexts
)
context = config.context('localhost/system:admin:token-file')
check_context(context, ssl: true, custom_ca: false, client_cert: false)
assert_equal('/path/to/secret/token', context.auth_options[:bearer_token_file])
end

def test_user_password
config = Kubeclient::Config.read(config_file('userauth.kubeconfig'))
assert_equal(
['localhost/system:admin:token', 'localhost/system:admin:userpass'],
['localhost/system:admin:token',
'localhost/system:admin:token-file',
'localhost/system:admin:userpass'],
config.contexts
)
context = config.context('localhost/system:admin:userpass')
Expand Down
Loading