|
19 | 19 | import pkg_resources |
20 | 20 | import sys |
21 | 21 |
|
22 | | -from openstackclient.common import restapi |
| 22 | +from keystoneclient.auth.identity import v2 as v2_auth |
| 23 | +from keystoneclient.auth.identity import v3 as v3_auth |
| 24 | +from keystoneclient import session |
23 | 25 | from openstackclient.identity import client as identity_client |
24 | 26 |
|
25 | 27 |
|
@@ -80,24 +82,68 @@ def __init__(self, token=None, url=None, auth_url=None, |
80 | 82 | self._cacert = verify |
81 | 83 | self._insecure = False |
82 | 84 |
|
83 | | - self.session = restapi.RESTApi( |
84 | | - verify=verify, |
85 | | - debug=True, |
86 | | - ) |
| 85 | + ver_prefix = identity_client.AUTH_VERSIONS[ |
| 86 | + self._api_version[identity_client.API_NAME] |
| 87 | + ] |
87 | 88 |
|
88 | 89 | # Get logging from root logger |
89 | 90 | root_logger = logging.getLogger('') |
90 | 91 | LOG.setLevel(root_logger.getEffectiveLevel()) |
91 | | - restapi_logger = logging.getLogger('restapi') |
92 | | - restapi_logger.setLevel(root_logger.getEffectiveLevel()) |
93 | 92 |
|
94 | | - self.auth_ref = None |
| 93 | + # NOTE(dtroyer): These plugins are hard-coded for the first step |
| 94 | + # in using the new Keystone auth plugins. |
| 95 | + |
| 96 | + if self._url: |
| 97 | + LOG.debug('Using token auth %s', ver_prefix) |
| 98 | + if ver_prefix == 'v2': |
| 99 | + self.auth = v2_auth.Token( |
| 100 | + auth_url=url, |
| 101 | + token=token, |
| 102 | + ) |
| 103 | + else: |
| 104 | + self.auth = v3_auth.Token( |
| 105 | + auth_url=url, |
| 106 | + token=token, |
| 107 | + ) |
| 108 | + else: |
| 109 | + LOG.debug('Using password auth %s', ver_prefix) |
| 110 | + if ver_prefix == 'v2': |
| 111 | + self.auth = v2_auth.Password( |
| 112 | + auth_url=auth_url, |
| 113 | + username=username, |
| 114 | + password=password, |
| 115 | + trust_id=trust_id, |
| 116 | + tenant_id=project_id, |
| 117 | + tenant_name=project_name, |
| 118 | + ) |
| 119 | + else: |
| 120 | + self.auth = v3_auth.Password( |
| 121 | + auth_url=auth_url, |
| 122 | + username=username, |
| 123 | + password=password, |
| 124 | + trust_id=trust_id, |
| 125 | + user_domain_id=user_domain_id, |
| 126 | + user_domain_name=user_domain_name, |
| 127 | + domain_id=domain_id, |
| 128 | + domain_name=domain_name, |
| 129 | + project_id=project_id, |
| 130 | + project_name=project_name, |
| 131 | + project_domain_id=project_domain_id, |
| 132 | + project_domain_name=project_domain_name, |
| 133 | + ) |
| 134 | + |
| 135 | + self.session = session.Session( |
| 136 | + auth=self.auth, |
| 137 | + verify=verify, |
| 138 | + ) |
95 | 139 |
|
| 140 | + self.auth_ref = None |
96 | 141 | if not self._url: |
| 142 | + # Trigger the auth call |
| 143 | + self.auth_ref = self.session.auth.get_auth_ref(self.session) |
97 | 144 | # Populate other password flow attributes |
98 | | - self.auth_ref = self.identity.auth_ref |
99 | | - self._token = self.identity.auth_token |
100 | | - self._service_catalog = self.identity.service_catalog |
| 145 | + self._token = self.session.auth.get_token(self.session) |
| 146 | + self._service_catalog = self.auth_ref.service_catalog |
101 | 147 |
|
102 | 148 | return |
103 | 149 |
|
|
0 commit comments