Add 'token' option for easy token retrieval
Just do fuel token You can use this in manual curl requests: curl '<api-url>' -H "X-Auth-Token: $(fuel token)" DocImpact Change-Id: I634160beedd347b90a249b073560483f33586b98
This commit is contained in:
@@ -20,6 +20,7 @@ from fuelclient.cli.actions.deploy import DeployChangesAction
|
||||
from fuelclient.cli.actions.environment import EnvironmentAction
|
||||
from fuelclient.cli.actions.fact import DeploymentAction
|
||||
from fuelclient.cli.actions.fact import ProvisioningAction
|
||||
from fuelclient.cli.actions.token import TokenAction
|
||||
from fuelclient.cli.actions.health import HealthCheckAction
|
||||
from fuelclient.cli.actions.interrupt import ResetAction
|
||||
from fuelclient.cli.actions.interrupt import StopAction
|
||||
@@ -55,7 +56,8 @@ actions_tuple = (
|
||||
PluginAction,
|
||||
NodeGroupAction,
|
||||
NotificationsAction,
|
||||
NotifyAction
|
||||
NotifyAction,
|
||||
TokenAction
|
||||
)
|
||||
|
||||
actions = dict(
|
||||
|
||||
37
fuelclient/cli/actions/token.py
Normal file
37
fuelclient/cli/actions/token.py
Normal file
@@ -0,0 +1,37 @@
|
||||
# Copyright 2015 Mirantis, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import sys
|
||||
|
||||
from fuelclient.cli.actions.base import Action
|
||||
from fuelclient.client import APIClient
|
||||
|
||||
|
||||
class TokenAction(Action):
|
||||
"""Return a valid keystone auth token
|
||||
"""
|
||||
action_name = "token"
|
||||
|
||||
def __init__(self):
|
||||
super(TokenAction, self).__init__()
|
||||
|
||||
self.args = []
|
||||
self.flag_func_map = (
|
||||
(None, self.get_token),
|
||||
)
|
||||
|
||||
def get_token(self, params):
|
||||
"""Print out a valid Keystone auth token
|
||||
"""
|
||||
sys.stdout.write(APIClient.auth_token)
|
||||
37
fuelclient/tests/test_token_action.py
Normal file
37
fuelclient/tests/test_token_action.py
Normal file
@@ -0,0 +1,37 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Copyright 2015 Mirantis, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import io
|
||||
|
||||
import mock
|
||||
|
||||
from fuelclient.tests import base
|
||||
|
||||
|
||||
@mock.patch('fuelclient.client.requests')
|
||||
class TestPluginsActions(base.UnitTestCase):
|
||||
|
||||
@mock.patch('fuelclient.cli.actions.token.APIClient')
|
||||
def test_token_action(self, mAPIClient, mrequests):
|
||||
with mock.patch('sys.stdout', new=io.StringIO()) as mstdout:
|
||||
token = u'token123'
|
||||
mauth_token = mock.PropertyMock(return_value=token)
|
||||
type(mAPIClient).auth_token = mauth_token
|
||||
|
||||
self.execute(['fuel', 'token'])
|
||||
|
||||
self.assertEqual(mauth_token.call_count, 1)
|
||||
self.assertEqual(mstdout.getvalue(), token)
|
||||
Reference in New Issue
Block a user