@@ -478,6 +478,15 @@ type GetKeyRequest struct {
478478 KeyID string `json:"-"`
479479}
480480
481+ // GetPublicKeyRequest: get public key request.
482+ type GetPublicKeyRequest struct {
483+ // Region: region to target. If none is passed will use default region from the config.
484+ Region scw.Region `json:"-"`
485+
486+ // KeyID: ID of the key.
487+ KeyID string `json:"-"`
488+ }
489+
481490// ImportKeyMaterialRequest: import key material request.
482491type ImportKeyMaterialRequest struct {
483492 // Region: region to target. If none is passed will use default region from the config.
@@ -555,6 +564,11 @@ type ProtectKeyRequest struct {
555564 KeyID string `json:"-"`
556565}
557566
567+ // PublicKey: public key.
568+ type PublicKey struct {
569+ Pem string `json:"pem"`
570+ }
571+
558572// RotateKeyRequest: rotate key request.
559573type RotateKeyRequest struct {
560574 // Region: region to target. If none is passed will use default region from the config.
@@ -678,6 +692,37 @@ func (s *API) GetKey(req *GetKeyRequest, opts ...scw.RequestOption) (*Key, error
678692 return & resp , nil
679693}
680694
695+ // GetPublicKey: Retrieves the public portion of an asymmetric cryptographic key in PEM format.
696+ func (s * API ) GetPublicKey (req * GetPublicKeyRequest , opts ... scw.RequestOption ) (* PublicKey , error ) {
697+ var err error
698+
699+ if req .Region == "" {
700+ defaultRegion , _ := s .client .GetDefaultRegion ()
701+ req .Region = defaultRegion
702+ }
703+
704+ if fmt .Sprint (req .Region ) == "" {
705+ return nil , errors .New ("field Region cannot be empty in request" )
706+ }
707+
708+ if fmt .Sprint (req .KeyID ) == "" {
709+ return nil , errors .New ("field KeyID cannot be empty in request" )
710+ }
711+
712+ scwReq := & scw.ScalewayRequest {
713+ Method : "GET" ,
714+ Path : "/key-manager/v1alpha1/regions/" + fmt .Sprint (req .Region ) + "/keys/" + fmt .Sprint (req .KeyID ) + "/public-key" ,
715+ }
716+
717+ var resp PublicKey
718+
719+ err = s .client .Do (scwReq , & resp , opts ... )
720+ if err != nil {
721+ return nil , err
722+ }
723+ return & resp , nil
724+ }
725+
681726// UpdateKey: Modify a key's metadata including name, description and tags, specified by the `key_id` and `region` parameters.
682727func (s * API ) UpdateKey (req * UpdateKeyRequest , opts ... scw.RequestOption ) (* Key , error ) {
683728 var err error
0 commit comments