@@ -559,15 +559,54 @@ retry:
559
559
return nil
560
560
}
561
561
562
- // CreateExternalAccountKey performs the POST /admin/eak request to the CA.
562
+ // GetExternalAccountKeysPaginate returns a page from the the GET /admin/acme/eab request to the CA.
563
+ func (c * AdminClient ) GetExternalAccountKeysPaginate (opts ... AdminOption ) (* adminAPI.GetExternalAccountKeysResponse , error ) {
564
+ var retried bool
565
+ o := new (adminOptions )
566
+ if err := o .apply (opts ); err != nil {
567
+ return nil , err
568
+ }
569
+ u := c .endpoint .ResolveReference (& url.URL {
570
+ Path : "/admin/acme/eab" ,
571
+ RawQuery : o .rawQuery (),
572
+ })
573
+ tok , err := c .generateAdminToken (u .Path )
574
+ if err != nil {
575
+ return nil , errors .Wrapf (err , "error generating admin token" )
576
+ }
577
+ req , err := http .NewRequest ("GET" , u .String (), nil )
578
+ if err != nil {
579
+ return nil , errors .Wrapf (err , "create GET %s request failed" , u )
580
+ }
581
+ req .Header .Add ("Authorization" , tok )
582
+ retry:
583
+ resp , err := c .client .Do (req )
584
+ if err != nil {
585
+ return nil , errors .Wrapf (err , "client GET %s failed" , u )
586
+ }
587
+ if resp .StatusCode >= 400 {
588
+ if ! retried && c .retryOnError (resp ) {
589
+ retried = true
590
+ goto retry
591
+ }
592
+ return nil , readAdminError (resp .Body )
593
+ }
594
+ // var body = new(GetExternalAccountKeysResponse)
595
+ // if err := readJSON(resp.Body, body); err != nil {
596
+ // return nil, errors.Wrapf(err, "error reading %s", u)
597
+ // }
598
+ // return body, nil
599
+ return nil , nil // TODO: fix correctly
600
+ }
601
+
602
+ // CreateExternalAccountKey performs the POST /admin/acme/eab request to the CA.
563
603
func (c * AdminClient ) CreateExternalAccountKey (eakRequest * adminAPI.CreateExternalAccountKeyRequest ) (* adminAPI.CreateExternalAccountKeyResponse , error ) {
564
604
var retried bool
565
- //body, err := protojson.Marshal(req)
566
605
body , err := json .Marshal (eakRequest )
567
606
if err != nil {
568
607
return nil , errs .Wrap (http .StatusInternalServerError , err , "error marshaling request" )
569
608
}
570
- u := c .endpoint .ResolveReference (& url.URL {Path : path .Join (adminURLPrefix , "eak " )})
609
+ u := c .endpoint .ResolveReference (& url.URL {Path : path .Join (adminURLPrefix , "acme/eab " )})
571
610
tok , err := c .generateAdminToken (u .Path )
572
611
if err != nil {
573
612
return nil , errors .Wrapf (err , "error generating admin token" )
@@ -596,7 +635,27 @@ retry:
596
635
return eakResp , nil
597
636
}
598
637
638
+ // GetExternalAccountKeys returns all ACME EAB Keys from the GET /admin/acme/eab request to the CA.
639
+ func (c * AdminClient ) GetExternalAccountKeys (opts ... AdminOption ) ([]* adminAPI.CreateExternalAccountKeyResponse , error ) {
640
+ var (
641
+ cursor = ""
642
+ eaks = []* adminAPI.CreateExternalAccountKeyResponse {}
643
+ )
644
+ for {
645
+ resp , err := c .GetExternalAccountKeysPaginate (WithAdminCursor (cursor ), WithAdminLimit (100 ))
646
+ if err != nil {
647
+ return nil , err
648
+ }
649
+ eaks = append (eaks , resp .EAKs ... )
650
+ if resp .NextCursor == "" {
651
+ return eaks , nil
652
+ }
653
+ cursor = resp .NextCursor
654
+ }
655
+ }
656
+
599
657
func readAdminError (r io.ReadCloser ) error {
658
+ // TODO: not all errors can be read (i.e. 404); seems to be a bigger issue
600
659
defer r .Close ()
601
660
adminErr := new (admin.Error )
602
661
if err := json .NewDecoder (r ).Decode (adminErr ); err != nil {
0 commit comments