Skip to content

Commit

Permalink
Removed mustache
Browse files Browse the repository at this point in the history
  • Loading branch information
Dani Guardiola committed Jan 9, 2018
1 parent 926cc30 commit 82836f9
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 45 deletions.
36 changes: 18 additions & 18 deletions features.md
Original file line number Diff line number Diff line change
Expand Up @@ -327,35 +327,35 @@ string, the returned response is the exact same as the contained wrapped respons

## vault.githubLogin()

`POST /auth/{{mount_point}}{{^mount_point}}github{{/mount_point}}/login`
`POST /auth/{{mount_point=github}}/login`

TODO: add description :S


## vault.userpassLogin()

`POST /auth/{{mount_point}}{{^mount_point}}userpass{{/mount_point}}/login/{{username}}`
`POST /auth/{{mount_point=userpass}}/login/{{username}}`

TODO: add description :S


## vault.ldapLogin()

`POST /auth/{{mount_point}}{{^mount_point}}ldap{{/mount_point}}/login/{{username}}`
`POST /auth/{{mount_point=ldap}}/login/{{username}}`

TODO: add description :S


## vault.oktaLogin()

`POST /auth/{{mount_point}}{{^mount_point}}okta{{/mount_point}}/login/{{username}}`
`POST /auth/{{mount_point=okta}}/login/{{username}}`

TODO: add description :S


## vault.radiusLogin()

`POST /auth/{{mount_point}}{{^mount_point}}radius{{/mount_point}}/login/{{username}}`
`POST /auth/{{mount_point=radius}}/login/{{username}}`

TODO: add description :S

Expand Down Expand Up @@ -481,91 +481,91 @@ TODO: add description :S

## vault.approleRoles()

`LIST /auth/{{mount_point}}{{^mount_point}}approle{{/mount_point}}/role`
`LIST /auth/{{mount_point=approle}}/role`

TODO: add description :S


## vault.addApproleRole()

`POST /auth/{{mount_point}}{{^mount_point}}approle{{/mount_point}}/role/{{role_name}}`
`POST /auth/{{mount_point=approle}}/role/{{role_name}}`

TODO: add description :S


## vault.getApproleRole()

`GET /auth/{{mount_point}}{{^mount_point}}approle{{/mount_point}}/role/{{role_name}}`
`GET /auth/{{mount_point=approle}}/role/{{role_name}}`

TODO: add description :S


## vault.deleteApproleRole()

`DELETE /auth/{{mount_point}}{{^mount_point}}approle{{/mount_point}}/role/{{role_name}}`
`DELETE /auth/{{mount_point=approle}}/role/{{role_name}}`

TODO: add description :S


## vault.getApproleRoleId()

`GET /auth/{{mount_point}}{{^mount_point}}approle{{/mount_point}}/role/{{role_name}}/role-id`
`GET /auth/{{mount_point=approle}}/role/{{role_name}}/role-id`

TODO: add description :S


## vault.updateApproleRoleId()

`POST /auth/{{mount_point}}{{^mount_point}}approle{{/mount_point}}/role/{{role_name}}/role-id`
`POST /auth/{{mount_point=approle}}/role/{{role_name}}/role-id`

TODO: add description :S


## vault.getApproleRoleSecret()

`POST /auth/{{mount_point}}{{^mount_point}}approle{{/mount_point}}/role/{{role_name}}/secret-id`
`POST /auth/{{mount_point=approle}}/role/{{role_name}}/secret-id`

TODO: add description :S


## vault.approleSecretAccessors()

`LIST /auth/{{mount_point}}{{^mount_point}}approle{{/mount_point}}/role/{{role_name}}/secret-id`
`LIST /auth/{{mount_point=approle}}/role/{{role_name}}/secret-id`

TODO: add description :S


## vault.approleSecretLookup()

`POST /auth/{{mount_point}}{{^mount_point}}approle{{/mount_point}}/role/{{role_name}}/secret-id/lookup`
`POST /auth/{{mount_point=approle}}/role/{{role_name}}/secret-id/lookup`

TODO: add description :S


## vault.approleSecretDestroy()

`POST /auth/{{mount_point}}{{^mount_point}}approle{{/mount_point}}/role/{{role_name}}/secret-id/destroy`
`POST /auth/{{mount_point=approle}}/role/{{role_name}}/secret-id/destroy`

TODO: add description :S


## vault.approleSecretAccessorLookup()

`POST /auth/{{mount_point}}{{^mount_point}}approle{{/mount_point}}/role/{{role_name}}/secret-id-accessor/lookup`
`POST /auth/{{mount_point=approle}}/role/{{role_name}}/secret-id-accessor/lookup`

TODO: add description :S


## vault.approleSecretAccessorDestroy()

`POST /auth/{{mount_point}}{{^mount_point}}approle{{/mount_point}}/role/{{role_name}}/secret-id-accessor/destroy`
`POST /auth/{{mount_point=approle}}/role/{{role_name}}/secret-id-accessor/destroy`

TODO: add description :S


## vault.approleLogin()

`POST /auth/{{mount_point}}{{^mount_point}}approle{{/mount_point}}/login`
`POST /auth/{{mount_point=approle}}/login`

TODO: add description :S

Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
],
"dependencies": {
"debug": "3.1.0",
"mustache": "^2.2.1",
"request": "^2.83.0",
"request-promise-native": "^1.0.5",
"tv4": "^1.2.7"
Expand Down
36 changes: 18 additions & 18 deletions src/interface/features.js
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ string, the returned response is the exact same as the contained wrapped respons
// third party tokens
githubLogin: {
method: 'POST',
path: '/auth/{{mount_point}}{{^mount_point}}github{{/mount_point}}/login',
path: '/auth/{{mount_point=github}}/login',
schema: {
req: {
type: 'object',
Expand All @@ -582,7 +582,7 @@ string, the returned response is the exact same as the contained wrapped respons
},
userpassLogin: {
method: 'POST',
path: '/auth/{{mount_point}}{{^mount_point}}userpass{{/mount_point}}/login/{{username}}',
path: '/auth/{{mount_point=userpass}}/login/{{username}}',
schema: {
req: {
type: 'object',
Expand All @@ -598,7 +598,7 @@ string, the returned response is the exact same as the contained wrapped respons
},
ldapLogin: {
method: 'POST',
path: '/auth/{{mount_point}}{{^mount_point}}ldap{{/mount_point}}/login/{{username}}',
path: '/auth/{{mount_point=ldap}}/login/{{username}}',
schema: {
req: {
type: 'object',
Expand All @@ -614,7 +614,7 @@ string, the returned response is the exact same as the contained wrapped respons
},
oktaLogin: {
method: 'POST',
path: '/auth/{{mount_point}}{{^mount_point}}okta{{/mount_point}}/login/{{username}}',
path: '/auth/{{mount_point=okta}}/login/{{username}}',
schema: {
req: {
type: 'object',
Expand All @@ -630,7 +630,7 @@ string, the returned response is the exact same as the contained wrapped respons
},
radiusLogin: {
method: 'POST',
path: '/auth/{{mount_point}}{{^mount_point}}radius{{/mount_point}}/login/{{username}}',
path: '/auth/{{mount_point=radius}}/login/{{username}}',
schema: {
req: {
type: 'object',
Expand Down Expand Up @@ -838,15 +838,15 @@ string, the returned response is the exact same as the contained wrapped respons
},
approleRoles: {
method: 'LIST',
path: '/auth/{{mount_point}}{{^mount_point}}approle{{/mount_point}}/role',
path: '/auth/{{mount_point=approle}}/role',
schema: {
res: APPROLE_RESPONSE_SCHEME
}
},
// - approle
addApproleRole: {
method: 'POST',
path: '/auth/{{mount_point}}{{^mount_point}}approle{{/mount_point}}/role/{{role_name}}',
path: '/auth/{{mount_point=approle}}/role/{{role_name}}',
schema: {
req: {
bind_secret_id: {
Expand Down Expand Up @@ -881,25 +881,25 @@ string, the returned response is the exact same as the contained wrapped respons
},
getApproleRole: {
method: 'GET',
path: '/auth/{{mount_point}}{{^mount_point}}approle{{/mount_point}}/role/{{role_name}}',
path: '/auth/{{mount_point=approle}}/role/{{role_name}}',
schema: {
res: APPROLE_RESPONSE_SCHEME
}
},
deleteApproleRole: {
method: 'DELETE',
path: '/auth/{{mount_point}}{{^mount_point}}approle{{/mount_point}}/role/{{role_name}}'
path: '/auth/{{mount_point=approle}}/role/{{role_name}}'
},
getApproleRoleId: {
method: 'GET',
path: '/auth/{{mount_point}}{{^mount_point}}approle{{/mount_point}}/role/{{role_name}}/role-id',
path: '/auth/{{mount_point=approle}}/role/{{role_name}}/role-id',
schema: {
res: APPROLE_RESPONSE_SCHEME
}
},
updateApproleRoleId: {
method: 'POST',
path: '/auth/{{mount_point}}{{^mount_point}}approle{{/mount_point}}/role/{{role_name}}/role-id',
path: '/auth/{{mount_point=approle}}/role/{{role_name}}/role-id',
schema: {
req: {
type: 'object',
Expand All @@ -914,7 +914,7 @@ string, the returned response is the exact same as the contained wrapped respons
},
getApproleRoleSecret: {
method: 'POST',
path: '/auth/{{mount_point}}{{^mount_point}}approle{{/mount_point}}' +
path: '/auth/{{mount_point=approle}}' +
'/role/{{role_name}}/secret-id',
schema: {
req: {
Expand All @@ -936,15 +936,15 @@ string, the returned response is the exact same as the contained wrapped respons
},
approleSecretAccessors: {
method: 'LIST',
path: '/auth/{{mount_point}}{{^mount_point}}approle{{/mount_point}}' +
path: '/auth/{{mount_point=approle}}' +
'/role/{{role_name}}/secret-id',
schema: {
res: APPROLE_RESPONSE_SCHEME
}
},
approleSecretLookup: {
method: 'POST',
path: '/auth/{{mount_point}}{{^mount_point}}approle{{/mount_point}}' +
path: '/auth/{{mount_point=approle}}' +
'/role/{{role_name}}/secret-id/lookup',
schema: {
req: {
Expand All @@ -961,7 +961,7 @@ string, the returned response is the exact same as the contained wrapped respons
},
approleSecretDestroy: {
method: 'POST',
path: '/auth/{{mount_point}}{{^mount_point}}approle{{/mount_point}}' +
path: '/auth/{{mount_point=approle}}' +
'/role/{{role_name}}/secret-id/destroy',
schema: {
req: {
Expand All @@ -977,7 +977,7 @@ string, the returned response is the exact same as the contained wrapped respons
},
approleSecretAccessorLookup: {
method: 'POST',
path: '/auth/{{mount_point}}{{^mount_point}}approle{{/mount_point}}' +
path: '/auth/{{mount_point=approle}}' +
'/role/{{role_name}}/secret-id-accessor/lookup',
schema: {
req: {
Expand All @@ -993,12 +993,12 @@ string, the returned response is the exact same as the contained wrapped respons
},
approleSecretAccessorDestroy: {
method: 'POST',
path: '/auth/{{mount_point}}{{^mount_point}}approle{{/mount_point}}' +
path: '/auth/{{mount_point=approle}}' +
'/role/{{role_name}}/secret-id-accessor/destroy'
},
approleLogin: {
method: 'POST',
path: '/auth/{{mount_point}}{{^mount_point}}approle{{/mount_point}}/login',
path: '/auth/{{mount_point=approle}}/login',
schema: {
req: {
type: 'object',
Expand Down
16 changes: 12 additions & 4 deletions src/main.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
const debug = require('debug')('node-vault')
// tv4 is a tool to validate json structures
const tv4 = require('tv4')
// mustache is a string templating tool used for
// the substitution of vault paths
const mustache = require('mustache')
const request = require('request-promise-native')

// ----------------
Expand Down Expand Up @@ -170,13 +167,22 @@ class VaultClient {
return options
}

_formatRequest (uriTemplate, values = {}) {
return uriTemplate.replace(/{{([\S]+?)}}/g, (a, b, c) => {
const parts = b.split('=')
const prop = parts[0]
const defaultValue = parts[1] || ''
return values[prop] || defaultValue
})
}

async _request (options = {}) {
// validate
if (!tv4.validate(options, REQUEST_SCHEMA)) throw tv4.error
// create URI template
const uriTemplate = `${this._getOption('endpoint')}/${this._getOption('apiVersion')}${options.path}`
// replace variables in uri
const uri = mustache.render(uriTemplate, options.json)
const uri = this._formatRequest(uriTemplate, options.json)
// replace unicode encodings
.replace(///g, '/')
// add URI
Expand Down Expand Up @@ -270,6 +276,8 @@ class VaultClient {
(...args) => this._generateFeature(...args)
client.request =
(...args) => this._request(...args)
client.formatRequest =
(...args) => this._formatRequest(...args)
}

// return the generated client
Expand Down
Loading

0 comments on commit 82836f9

Please sign in to comment.