@@ -9,7 +9,6 @@ import { getOwner } from '@ember/application';
99import { isArray } from '@ember/array' ;
1010import { computed , get } from '@ember/object' ;
1111import { alias } from '@ember/object/computed' ;
12- import { assign } from '@ember/polyfills' ;
1312import Service , { inject as service } from '@ember/service' ;
1413import { capitalize } from '@ember/string' ;
1514import fetch from 'fetch' ;
@@ -118,9 +117,12 @@ export default Service.extend({
118117 }
119118 const backend = this . backendFromTokenName ( token ) ;
120119 const stored = this . getTokenData ( token ) ;
121-
122- return assign ( stored , {
123- backend : BACKENDS . findBy ( 'type' , backend ) ,
120+ return Object . assign ( stored , {
121+ backend : {
122+ // add mount path for password reset
123+ mountPath : stored . backend . mountPath ,
124+ ...BACKENDS . findBy ( 'type' , backend ) ,
125+ } ,
124126 } ) ;
125127 } ) ,
126128
@@ -184,7 +186,7 @@ export default Service.extend({
184186 if ( namespace ) {
185187 defaults . headers [ 'X-Vault-Namespace' ] = namespace ;
186188 }
187- const opts = assign ( defaults , options ) ;
189+ const opts = Object . assign ( defaults , options ) ;
188190
189191 return fetch ( url , {
190192 method : opts . method || 'GET' ,
@@ -223,10 +225,35 @@ export default Service.extend({
223225 } ;
224226 } ,
225227
228+ calculateRootNamespace ( currentNamespace , namespace_path , backend ) {
229+ // here we prefer namespace_path if its defined,
230+ // else we look and see if there's already a namespace saved
231+ // and then finally we'll use the current query param if the others
232+ // haven't set a value yet
233+ // all of the typeof checks are necessary because the root namespace is ''
234+ let userRootNamespace = namespace_path && namespace_path . replace ( / \/ $ / , '' ) ;
235+ // if we're logging in with token and there's no namespace_path, we can assume
236+ // that the token belongs to the root namespace
237+ if ( backend === 'token' && ! userRootNamespace ) {
238+ userRootNamespace = '' ;
239+ }
240+ if ( typeof userRootNamespace === 'undefined' ) {
241+ if ( this . authData ) {
242+ userRootNamespace = this . authData . userRootNamespace ;
243+ }
244+ }
245+ if ( typeof userRootNamespace === 'undefined' ) {
246+ userRootNamespace = currentNamespace ;
247+ }
248+ return userRootNamespace ;
249+ } ,
250+
226251 persistAuthData ( ) {
227252 const [ firstArg , resp ] = arguments ;
228253 const tokens = this . tokens ;
229254 const currentNamespace = this . namespaceService . path || '' ;
255+ // Tab vs dropdown format
256+ const mountPath = firstArg ?. selectedAuth || firstArg ?. data ?. path ;
230257 let tokenName ;
231258 let options ;
232259 let backend ;
@@ -238,7 +265,10 @@ export default Service.extend({
238265 backend = options . backend ;
239266 }
240267
241- const currentBackend = BACKENDS . findBy ( 'type' , backend ) ;
268+ const currentBackend = {
269+ mountPath,
270+ ...BACKENDS . findBy ( 'type' , backend ) ,
271+ } ;
242272 let displayName ;
243273 if ( isArray ( currentBackend . displayNamePath ) ) {
244274 displayName = currentBackend . displayNamePath . map ( ( name ) => get ( resp , name ) ) . join ( '/' ) ;
@@ -247,25 +277,7 @@ export default Service.extend({
247277 }
248278
249279 const { entity_id, policies, renewable, namespace_path } = resp ;
250- // here we prefer namespace_path if its defined,
251- // else we look and see if there's already a namespace saved
252- // and then finally we'll use the current query param if the others
253- // haven't set a value yet
254- // all of the typeof checks are necessary because the root namespace is ''
255- let userRootNamespace = namespace_path && namespace_path . replace ( / \/ $ / , '' ) ;
256- // if we're logging in with token and there's no namespace_path, we can assume
257- // that the token belongs to the root namespace
258- if ( backend === 'token' && ! userRootNamespace ) {
259- userRootNamespace = '' ;
260- }
261- if ( typeof userRootNamespace === 'undefined' ) {
262- if ( this . authData ) {
263- userRootNamespace = this . authData . userRootNamespace ;
264- }
265- }
266- if ( typeof userRootNamespace === 'undefined' ) {
267- userRootNamespace = currentNamespace ;
268- }
280+ const userRootNamespace = this . calculateRootNamespace ( currentNamespace , namespace_path , backend ) ;
269281 const data = {
270282 userRootNamespace,
271283 displayName,
@@ -285,7 +297,7 @@ export default Service.extend({
285297 ) ;
286298
287299 if ( resp . renewable ) {
288- assign ( data , this . calculateExpiration ( resp ) ) ;
300+ Object . assign ( data , this . calculateExpiration ( resp ) ) ;
289301 }
290302
291303 if ( ! data . displayName ) {
0 commit comments