@@ -38,6 +38,9 @@ export { getCaIdentities, scGenCSR, getCaAffiliations, registerCaIdentity, enrol
38
38
function getCaIdentities ( opts : CaInput , cb : Function ) {
39
39
const options = JSON . parse ( JSON . stringify ( opts ) ) ;
40
40
options . body_obj = null ; // set null for token gen
41
+ // set path and method for token gen
42
+ options . path = build_ca_path ( options , '/api/v1/identities' ) ;
43
+ options . method = 'GET' ;
41
44
42
45
let called_cb = false ;
43
46
generateCaAuthToken ( options , ( _ : any , token : string ) => {
@@ -80,6 +83,9 @@ function getCaIdentities(opts: CaInput, cb: Function) {
80
83
function getCaAffiliations ( opts : CaInput , cb : Function ) {
81
84
const options = JSON . parse ( JSON . stringify ( opts ) ) ;
82
85
options . body_obj = null ; // set null for token gen
86
+ // set path and method for token gen
87
+ options . path = build_ca_path ( options , '/api/v1/affiliations' ) ;
88
+ options . method = 'GET' ;
83
89
84
90
let called_cb = false ;
85
91
generateCaAuthToken ( options , ( _ : any , token : string ) => {
@@ -160,6 +166,9 @@ function registerCaIdentity(opts: CaReg, cb: Function) {
160
166
type : options . new_identity . type ,
161
167
max_enrollments : Number ( options . new_identity . max_enrollments )
162
168
} ;
169
+ // set path and method for token gen
170
+ options . path = build_ca_path ( options , '/api/v1/identities' ) ;
171
+ options . method = 'POST' ;
163
172
164
173
let called_cb = false ;
165
174
generateCaAuthToken ( options , ( _ : any , token : string ) => {
@@ -283,6 +292,9 @@ function reenrollCaIdentity(opts: CaInput, cb: Function) {
283
292
caName : options . ca_name ,
284
293
certificate_request : csrPEM ,
285
294
} ;
295
+ // set path and method for token gen
296
+ options . path = build_ca_path ( options , '/api/v1/reenroll' ) ;
297
+ options . method = 'POST' ;
286
298
287
299
let called_cb = false ;
288
300
generateCaAuthToken ( options , ( _ : any , token : string ) => {
@@ -338,15 +350,18 @@ function get_CN_from_str(str: any) {
338
350
*/
339
351
function deleteCaIdentity ( opts : CaInput , cb : Function ) {
340
352
const options = JSON . parse ( JSON . stringify ( opts ) ) ;
353
+ const parsed = parseCertificate ( opts . client_cert_b64pem ) ;
354
+ const enroll_id = opts . enroll_id || get_CN_from_str ( parsed . subject_parts . CN ) ;
341
355
options . body_obj = null ; // set null for token gen
356
+ // set path and method for token gen
357
+ options . path = build_ca_path ( options , '/api/v1/identities/' + enroll_id ) ;
358
+ options . method = 'DELETE' ;
342
359
343
- const parsed = parseCertificate ( opts . client_cert_b64pem ) ;
344
360
if ( ! parsed || ! parsed . subject_parts || ! parsed . subject_parts . CN ) {
345
361
return cb ( fmt_ca_err ( { funk : 'deleteCaIdentity' } , null , 'unable to delete id b/c cannot find enroll id in cert' ) , null ) ;
346
362
} else {
347
363
let called_cb = false ;
348
364
generateCaAuthToken ( options , ( _ : any , token : string ) => {
349
- const enroll_id = opts . enroll_id || get_CN_from_str ( parsed . subject_parts . CN ) ;
350
365
const fetch_options = {
351
366
host : build_ca_url ( options , '/api/v1/identities/' + enroll_id ) ,
352
367
authorization : token ,
@@ -388,6 +403,21 @@ function build_ca_url(opts: { ca_name: string, host: string }, path: string) {
388
403
return opts . host ;
389
404
}
390
405
406
+ // ------------------------------------------------------------------------------------------------------
407
+ // construct the path to use for the ca, same logic as build_ca_url (above) but without the starting host
408
+ // ------------------------------------------------------------------------------------------------------
409
+ function build_ca_path ( opts : { ca_name : string , host : string } , path : string ) {
410
+ if ( opts . ca_name ) { // finding the ca name in input obj
411
+ return path + '?ca=' + opts . ca_name ;
412
+ } else {
413
+ const parts = opts . host . split ( '?' ) ; // finding the ca name in url as query param
414
+ if ( parts && parts . length >= 2 ) {
415
+ return path + '?' + parts [ 1 ] ; // parts[1] holds the ca name
416
+ }
417
+ }
418
+ return path ;
419
+ }
420
+
391
421
// ----------------------------------------------------------------
392
422
// Get some JSON data via Fetch - expects json response
393
423
// ----------------------------------------------------------------
@@ -505,6 +535,8 @@ interface CaInput {
505
535
ext : Ext | null ;
506
536
enroll_id : string | null ;
507
537
timeout_ms : number | null ;
538
+ path : string ;
539
+ method : string ;
508
540
}
509
541
510
542
interface CaReg extends CaInput {
0 commit comments