@@ -7,6 +7,7 @@ import TlsTransport from './transport/tls';
7
7
import KMIP from '.' ;
8
8
import * as werelogs from 'werelogs' ;
9
9
import { arsenalErrorKMIP } from '../utils'
10
+ import { KMSInterface } from '../KMSInterface' ;
10
11
11
12
const CRYPTOGRAPHIC_OBJECT_TYPE = 'Symmetric Key' ;
12
13
const CRYPTOGRAPHIC_ALGORITHM = 'AES' ;
@@ -53,6 +54,7 @@ const searchFilter = {
53
54
* @param cb - The callback triggered after the negotiation.
54
55
*/
55
56
function _negotiateProtocolVersion ( client : any , logger : werelogs . Logger , cb : any ) {
57
+ const startDate = Date . now ( ) ;
56
58
return client . kmip . request ( logger , 'Discover Versions' , [
57
59
KMIP . Structure ( 'Protocol Version' , [
58
60
KMIP . Integer ( 'Protocol Version Major' , 1 ) ,
@@ -67,10 +69,14 @@ function _negotiateProtocolVersion(client: any, logger: werelogs.Logger, cb: any
67
69
KMIP . Integer ( 'Protocol Version Minor' , 2 ) ,
68
70
] ) ,
69
71
] , ( err , response ) => {
72
+ const kmipLog = {
73
+ host : client . host ,
74
+ latencyMs : Date . now ( ) - startDate
75
+ } ;
70
76
if ( err ) {
71
77
const error = arsenalErrorKMIP ( err ) ;
72
78
logger . error ( 'KMIP::negotiateProtocolVersion' ,
73
- { error,
79
+ { error, kmip : kmipLog ,
74
80
vendorIdentification : client . vendorIdentification } ) ;
75
81
return cb ( error ) ;
76
82
}
@@ -82,7 +88,7 @@ function _negotiateProtocolVersion(client: any, logger: werelogs.Logger, cb: any
82
88
majorVersions . length !== minorVersions . length ) {
83
89
const error = arsenalErrorKMIP ( 'No suitable protocol version' ) ;
84
90
logger . error ( 'KMIP::negotiateProtocolVersion' ,
85
- { error,
91
+ { error, kmip : kmipLog ,
86
92
vendorIdentification : client . vendorIdentification } ) ;
87
93
return cb ( error ) ;
88
94
}
@@ -99,13 +105,18 @@ function _negotiateProtocolVersion(client: any, logger: werelogs.Logger, cb: any
99
105
* @param cb - The callback triggered after the extension mapping
100
106
*/
101
107
function _mapExtensions ( client : any , logger : werelogs . Logger , cb : any ) {
108
+ const startDate = Date . now ( ) ;
102
109
return client . kmip . request ( logger , 'Query' , [
103
110
KMIP . Enumeration ( 'Query Function' , 'Query Extension Map' ) ,
104
111
] , ( err , response ) => {
112
+ const kmipLog = {
113
+ host : client . host ,
114
+ latencyMs : Date . now ( ) - startDate
115
+ } ;
105
116
if ( err ) {
106
117
const error = arsenalErrorKMIP ( err ) ;
107
118
logger . error ( 'KMIP::mapExtensions' ,
108
- { error,
119
+ { error, kmip : kmipLog ,
109
120
vendorIdentification : client . vendorIdentification } ) ;
110
121
return cb ( error ) ;
111
122
}
@@ -114,7 +125,7 @@ function _mapExtensions(client: any, logger: werelogs.Logger, cb: any) {
114
125
if ( extensionNames . length !== extensionTags . length ) {
115
126
const error = arsenalErrorKMIP ( 'Inconsistent extension list' ) ;
116
127
logger . error ( 'KMIP::mapExtensions' ,
117
- { error,
128
+ { error, kmip : kmipLog ,
118
129
vendorIdentification : client . vendorIdentification } ) ;
119
130
return cb ( error ) ;
120
131
}
@@ -132,25 +143,31 @@ function _mapExtensions(client: any, logger: werelogs.Logger, cb: any) {
132
143
* @param cb - The callback triggered after the information discovery
133
144
*/
134
145
function _queryServerInformation ( client : any , logger : werelogs . Logger , cb : any ) {
146
+ const startDate = Date . now ( ) ;
135
147
client . kmip . request ( logger , 'Query' , [
136
148
KMIP . Enumeration ( 'Query Function' , 'Query Server Information' ) ,
137
149
] , ( err , response ) => {
150
+ const kmipLog = {
151
+ host : client . host ,
152
+ latencyMs : Date . now ( ) - startDate
153
+ } ;
138
154
if ( err ) {
139
155
const error = arsenalErrorKMIP ( err ) ;
140
156
logger . warn ( 'KMIP::queryServerInformation' ,
141
- { error } ) ;
157
+ { error, kmip : kmipLog } ) ;
142
158
/* no error returned, caller can keep going */
143
159
return cb ( ) ;
144
160
}
145
161
client . _setVendorIdentification (
146
162
response . lookup ( searchFilter . vendorIdentification ) [ 0 ] ) ;
147
163
client . _setServerInformation (
148
- JSON . stringify ( response . lookup ( searchFilter . serverInformation ) [ 0 ] ) ) ;
164
+ response . lookup ( searchFilter . serverInformation ) [ 0 ] ) ;
149
165
150
166
logger . info ( 'KMIP Server identified' ,
151
167
{ vendorIdentification : client . vendorIdentification ,
152
168
serverInformation : client . serverInformation ,
153
- negotiatedProtocolVersion : client . kmip . protocolVersion } ) ;
169
+ negotiatedProtocolVersion : client . kmip . protocolVersion ,
170
+ kmip : kmipLog } ) ;
154
171
return cb ( ) ;
155
172
} ) ;
156
173
}
@@ -166,14 +183,19 @@ function _queryServerInformation(client: any, logger: werelogs.Logger, cb: any)
166
183
* @param cb - The callback triggered after the information discovery
167
184
*/
168
185
function _queryOperationsAndObjects ( client : any , logger : werelogs . Logger , cb : any ) {
186
+ const startDate = Date . now ( ) ;
169
187
return client . kmip . request ( logger , 'Query' , [
170
188
KMIP . Enumeration ( 'Query Function' , 'Query Operations' ) ,
171
189
KMIP . Enumeration ( 'Query Function' , 'Query Objects' ) ,
172
190
] , ( err , response ) => {
191
+ const kmipLog = {
192
+ host : client . host ,
193
+ latencyMs : Date . now ( ) - startDate
194
+ } ;
173
195
if ( err ) {
174
196
const error = arsenalErrorKMIP ( err ) ;
175
197
logger . error ( 'KMIP::queryOperationsAndObjects' ,
176
- { error,
198
+ { error, kmip : kmipLog ,
177
199
vendorIdentification : client . vendorIdentification } ) ;
178
200
return cb ( error ) ;
179
201
}
@@ -204,21 +226,23 @@ function _queryOperationsAndObjects(client: any, logger: werelogs.Logger, cb: an
204
226
supportsEncrypt, supportsDecrypt,
205
227
supportsActivate, supportsRevoke,
206
228
supportsCreate, supportsDestroy,
207
- supportsQuery, supportsSymmetricKeys } ) ;
229
+ supportsQuery, supportsSymmetricKeys,
230
+ kmip : kmipLog } ) ;
208
231
} else {
209
232
logger . info ( 'KMIP Server provides the necessary feature set' ,
210
- { vendorIdentification : client . vendorIdentification } ) ;
233
+ { vendorIdentification : client . vendorIdentification ,
234
+ kmip : kmipLog } ) ;
211
235
}
212
236
return cb ( ) ;
213
237
} ) ;
214
238
}
215
239
216
-
217
- export default class Client {
240
+ export default class Client implements KMSInterface {
218
241
options : any ;
219
242
vendorIdentification : string ;
220
243
serverInformation : any [ ] ;
221
244
kmip : KMIP ;
245
+ host : string ;
222
246
223
247
/**
224
248
* Construct a high level KMIP driver suitable for cloudserver
@@ -255,6 +279,7 @@ export default class Client {
255
279
CodecClass : any ,
256
280
TransportClass : any ,
257
281
) {
282
+ this . host = options . kmip . transport . tls . host ;
258
283
this . options = options . kmip . client || { } ;
259
284
this . vendorIdentification = '' ;
260
285
this . serverInformation = [ ] ;
@@ -567,20 +592,23 @@ export default class Client {
567
592
}
568
593
569
594
healthcheck ( logger , cb ) {
595
+ const kmipLog = { host : this . host } ;
570
596
// the bucket does not have to exist, just passing a common bucket name here
571
597
this . createBucketKey ( 'kmip-healthcheck-test-bucket' , logger , ( err , bucketKeyId ) => {
572
598
if ( err ) {
573
599
logger . error ( 'KMIP::healthcheck: failure to create a test bucket key' , {
574
- error : err ,
600
+ error : err , kmip : kmipLog ,
575
601
} ) ;
576
602
return cb ( err ) ;
577
603
}
578
- logger . debug ( 'KMIP::healthcheck: success creating a test bucket key' ) ;
604
+ logger . debug ( 'KMIP::healthcheck: success creating a test bucket key' ,
605
+ { kmip : kmipLog } ) ;
579
606
this . destroyBucketKey ( bucketKeyId , logger , err => {
580
607
if ( err ) {
581
608
logger . error ( 'KMIP::healthcheck: failure to remove the test bucket key' , {
582
609
bucketKeyId,
583
610
error : err ,
611
+ kmip : kmipLog ,
584
612
} ) ;
585
613
}
586
614
} ) ;
0 commit comments