2018-09-25 16:28:26 +00:00
import { alias } from '@ember/object/computed' ;
import { computed } from '@ember/object' ;
2018-04-03 14:16:57 +00:00
import DS from 'ember-data' ;
import { fragment } from 'ember-data-model-fragments/attributes' ;
import fieldToAttrs , { expandAttributeMeta } from 'vault/utils/field-to-attrs' ;
import { memberAction } from 'ember-api-actions' ;
2019-08-13 21:54:51 +00:00
import apiPath from 'vault/utils/api-path' ;
import attachCapabilities from 'vault/lib/attach-capabilities' ;
2018-04-03 14:16:57 +00:00
const { attr , hasMany } = DS ;
2019-08-13 21:54:51 +00:00
let Model = DS . Model . extend ( {
2018-04-03 14:16:57 +00:00
authConfigs : hasMany ( 'auth-config' , { polymorphic : true , inverse : 'backend' , async : false } ) ,
2018-08-28 05:03:55 +00:00
path : attr ( 'string' ) ,
2018-04-03 14:16:57 +00:00
accessor : attr ( 'string' ) ,
name : attr ( 'string' ) ,
2018-08-28 05:03:55 +00:00
type : attr ( 'string' ) ,
2018-08-16 17:48:24 +00:00
// namespaces introduced types with a `ns_` prefix for built-in engines
// so we need to strip that to normalize the type
methodType : computed ( 'type' , function ( ) {
return this . get ( 'type' ) . replace ( /^ns_/ , '' ) ;
} ) ,
2018-04-03 14:16:57 +00:00
description : attr ( 'string' , {
editType : 'textarea' ,
} ) ,
config : fragment ( 'mount-config' , { defaultValue : { } } ) ,
2018-08-28 05:03:55 +00:00
local : attr ( 'boolean' , {
helpText :
2019-03-29 23:40:12 +00:00
'When Replication is enabled, a local mount will not be replicated across clusters. This can only be specified at mount time.' ,
2018-08-28 05:03:55 +00:00
} ) ,
sealWrap : attr ( 'boolean' , {
helpText :
'When enabled - if a seal supporting seal wrapping is specified in the configuration, all critical security parameters (CSPs) in this backend will be seal wrapped. (For K/V mounts, all values will be seal wrapped.) This can only be specified at mount time.' ,
} ) ,
2018-04-03 14:16:57 +00:00
// used when the `auth` prefix is important,
// currently only when setting perf mount filtering
apiPath : computed ( 'path' , function ( ) {
return ` auth/ ${ this . get ( 'path' ) } ` ;
} ) ,
localDisplay : computed ( 'local' , function ( ) {
return this . get ( 'local' ) ? 'local' : 'replicated' ;
} ) ,
tuneAttrs : computed ( function ( ) {
2018-07-05 18:28:12 +00:00
return expandAttributeMeta ( this , [
'description' ,
2018-11-07 19:34:33 +00:00
'config.{listingVisibility,defaultLeaseTtl,maxLeaseTtl,tokenType,auditNonHmacRequestKeys,auditNonHmacResponseKeys,passthroughRequestHeaders}' ,
2018-07-05 18:28:12 +00:00
] ) ;
2018-04-03 14:16:57 +00:00
} ) ,
//sys/mounts/auth/[auth-path]/tune.
tune : memberAction ( {
path : 'tune' ,
type : 'post' ,
urlType : 'updateRecord' ,
} ) ,
2018-09-25 16:28:26 +00:00
formFields : computed ( function ( ) {
return [
'type' ,
'path' ,
'description' ,
'accessor' ,
'local' ,
'sealWrap' ,
2018-11-07 19:34:33 +00:00
'config.{listingVisibility,defaultLeaseTtl,maxLeaseTtl,tokenType,auditNonHmacRequestKeys,auditNonHmacResponseKeys,passthroughRequestHeaders}' ,
2018-09-25 16:28:26 +00:00
] ;
} ) ,
2018-04-03 14:16:57 +00:00
2018-09-25 16:28:26 +00:00
formFieldGroups : computed ( function ( ) {
return [
{ default : [ 'path' ] } ,
{
'Method Options' : [
'description' ,
'config.listingVisibility' ,
'local' ,
'sealWrap' ,
2018-11-07 19:34:33 +00:00
'config.{defaultLeaseTtl,maxLeaseTtl,tokenType,auditNonHmacRequestKeys,auditNonHmacResponseKeys,passthroughRequestHeaders}' ,
2018-09-25 16:28:26 +00:00
] ,
} ,
] ;
} ) ,
2018-04-03 14:16:57 +00:00
attrs : computed ( 'formFields' , function ( ) {
return expandAttributeMeta ( this , this . get ( 'formFields' ) ) ;
} ) ,
fieldGroups : computed ( 'formFieldGroups' , function ( ) {
return fieldToAttrs ( this , this . get ( 'formFieldGroups' ) ) ;
} ) ,
2019-08-13 21:54:51 +00:00
canDisable : alias ( 'deletePath.canDelete' ) ,
canEdit : alias ( 'configPath.canUpdate' ) ,
} ) ;
2018-04-03 14:16:57 +00:00
2019-08-13 21:54:51 +00:00
export default attachCapabilities ( Model , {
2019-09-03 19:15:57 +00:00
deletePath : apiPath ` sys/auth/ ${ 'id' } ` ,
2019-08-13 21:54:51 +00:00
configPath : function ( context ) {
if ( context . type === 'aws' ) {
return apiPath ` auth/ ${ 'id' } /config/client ` ;
2018-04-03 14:16:57 +00:00
} else {
2019-08-13 21:54:51 +00:00
return apiPath ` auth/ ${ 'id' } /config ` ;
2018-04-03 14:16:57 +00:00
}
2019-08-13 21:54:51 +00:00
} ,
2018-04-03 14:16:57 +00:00
} ) ;