From cefe715031cc4b1b79a8a68fdb2b93d94fb128f0 Mon Sep 17 00:00:00 2001
From: Dean Troyer <dtroyer@gmail.com>
Date: Tue, 21 Jun 2016 14:54:27 -0500
Subject: [PATCH] Fix token/endpoint auth plugin

[This is not quite reduced from the original proposed fix as some
changes have merged that complicate the switch to OSC_Config and
v2 auth broke anyway.]

Fix the --os-token --os-url breakage in the switch to ksa.

Closes-bug: 1593664
Change-Id: I3ac23234fbf647fb145c7bd151d53c5c105462bf
---
 openstackclient/api/auth_plugin.py | 53 ++++++++++++++++--------------
 1 file changed, 29 insertions(+), 24 deletions(-)

diff --git a/openstackclient/api/auth_plugin.py b/openstackclient/api/auth_plugin.py
index 4434bc8ffc..56dc4de5d4 100644
--- a/openstackclient/api/auth_plugin.py
+++ b/openstackclient/api/auth_plugin.py
@@ -15,50 +15,55 @@
 
 import logging
 
-from oslo_config import cfg
-from six.moves.urllib import parse as urlparse
-
-from keystoneauth1.loading._plugins import admin_token as token_endpoint
+from keystoneauth1 import loading
 from keystoneauth1.loading._plugins.identity import generic as ksa_password
+from keystoneauth1 import token_endpoint
+from six.moves.urllib import parse as urlparse
 
 from openstackclient.i18n import _
 
 LOG = logging.getLogger(__name__)
 
 
-class TokenEndpoint(token_endpoint.AdminToken):
+class TokenEndpoint(loading.BaseLoader):
     """Auth plugin to handle traditional token/endpoint usage
 
-    Implements the methods required to handle token authentication
-    with a user-specified token and service endpoint; no Identity calls
-    are made for re-scoping, service catalog lookups or the like.
-
-    The purpose of this plugin is to get rid of the special-case paths
-    in the code to handle this authentication format. Its primary use
-    is for bootstrapping the Keystone database.
+    Keystoneauth contains a Token plugin class that now correctly
+    handles the token/endpoint auth compatible with OSC.  However,
+    the AdminToken loader deprecates the 'url' argument, which breaks
+    OSC compatibility, so make one that works.
     """
 
+    @property
+    def plugin_class(self):
+        return token_endpoint.Token
+
     def load_from_options(self, url, token, **kwargs):
         """A plugin for static authentication with an existing token
 
         :param string url: Service endpoint
         :param string token: Existing token
         """
-        return super(TokenEndpoint, self).load_from_options(endpoint=url,
-                                                            token=token)
+
+        return super(TokenEndpoint, self).load_from_options(
+            endpoint=url,
+            token=token,
+        )
 
     def get_options(self):
-        options = super(TokenEndpoint, self).get_options()
-
-        options.extend([
-            # Maintain name 'url' for compatibility
-            cfg.StrOpt('url',
-                       help=_('Specific service endpoint to use')),
-            cfg.StrOpt('token',
-                       secret=True,
-                       help=_('Authentication token to use')),
-        ])
+        """Return the legacy options"""
 
+        options = [
+            loading.Opt(
+                'url',
+                help=_('Specific service endpoint to use'),
+            ),
+            loading.Opt(
+                'token',
+                secret=True,
+                help=_('Authentication token to use'),
+            ),
+        ]
         return options