File tree Expand file tree Collapse file tree 5 files changed +59
-0
lines changed
Expand file tree Collapse file tree 5 files changed +59
-0
lines changed Original file line number Diff line number Diff line change 1+ // file: example/update.js
2+
3+ process . env . DEBUG = 'node-vault' ; // switch on debug mode
4+
5+ const vault = require ( './../src/index' ) ( ) ;
6+
7+ vault . update ( 'secret/hello' , { value : 'world' , lease : '1s' } )
8+ . then ( ( ) => vault . read ( 'secret/hello' ) )
9+ . catch ( ( err ) => console . error ( err . message ) ) ;
10+
11+ vault . update ( 'secret/hello' , { value : 'everyone' , lease : '1s' } )
12+ . then ( ( ) => vault . read ( 'secret/hello' ) )
13+ . catch ( ( err ) => console . error ( err . message ) ) ;
14+
15+ vault . update ( 'secret/hello' , { value : { 'foo' : 'bar' , 'world' : 'everyone' } } )
16+ . then ( ( ) => vault . read ( 'secret/hello' ) )
17+ . catch ( ( err ) => console . error ( err . message ) ) ;
Original file line number Diff line number Diff line change @@ -47,6 +47,7 @@ declare namespace NodeVault {
4747 read ( path : string , requestOptions ?: Option ) : Promise < any > ;
4848 list ( path : string , requestOptions ?: Option ) : Promise < any > ;
4949 delete ( path : string , requestOptions ?: Option ) : Promise < any > ;
50+ update ( path : string , data : any , requestOptions ?: Option ) : Promise < any > ;
5051
5152 generateFunction ( name : string , conf : functionConf ) : void ;
5253
Original file line number Diff line number Diff line change 7979 " Sean Gallavan (https://github.com/seangallavan)" ,
8080 " seyfert (https://github.com/seyfert)" ,
8181 " Simon Boulet (https://github.com/siboulet)" ,
82+ " skeletonz28 (https://github.com/skeletonz28)" ,
8283 " Tim Robinson (https://github.com/timjrobinson)" ,
8384 " Tom Vogel (https://github.com/tavogel)" ,
8485 " Trevor Robinson (https://github.com/trevorr)" ,
Original file line number Diff line number Diff line change @@ -127,6 +127,16 @@ module.exports = (config = {}) => {
127127 return client . request ( options ) ;
128128 } ;
129129
130+ client . update = ( path , data , requestOptions ) => {
131+ debug ( 'update %o to %s' , data , path ) ;
132+ const options = { ...config . requestOptions , ...requestOptions } ;
133+ options . path = `/${ path } ` ;
134+ options . json = data ;
135+ options . method = 'PATCH' ;
136+ options . headers = { 'Content-Type' : 'application/merge-patch+json' } ;
137+ return client . request ( options ) ;
138+ } ;
139+
130140 client . read = ( path , requestOptions ) => {
131141 debug ( `read ${ path } ` ) ;
132142 const options = { ...config . requestOptions , ...requestOptions } ;
Original file line number Diff line number Diff line change @@ -217,6 +217,36 @@ describe('node-vault', () => {
217217 } ) ;
218218 } ) ;
219219
220+ describe ( 'update(path, data, options)' , ( ) => {
221+ it ( 'should update data to path' , ( done ) => {
222+ const path = 'secret/hello' ;
223+ const data = {
224+ value : 'everyone' ,
225+ } ;
226+ const params = {
227+ method : 'PATCH' ,
228+ uri : getURI ( path ) ,
229+ } ;
230+ vault . update ( path , data )
231+ . then ( assertRequest ( request , params , done ) )
232+ . catch ( done ) ;
233+ } ) ;
234+
235+ it ( 'should handle undefined options' , ( done ) => {
236+ const path = 'secret/hello' ;
237+ const data = {
238+ value : 'everyone' ,
239+ } ;
240+ const params = {
241+ method : 'PATCH' ,
242+ uri : getURI ( path ) ,
243+ } ;
244+ vault . update ( path , data )
245+ . then ( assertRequest ( request , params , done ) )
246+ . catch ( done ) ;
247+ } ) ;
248+ } ) ;
249+
220250 describe ( 'read(path, options)' , ( ) => {
221251 it ( 'should read data from path' , ( done ) => {
222252 const path = 'secret/hello' ;
You can’t perform that action at this time.
0 commit comments