@@ -768,6 +768,68 @@ func (c *Client) RecoverCertificate(
768768 return priv , leaf , chain , nil
769769}
770770
771+ // ChangeCertificateOwnerRole changes the certificate's owner. Users must be in the current owner's role and the new owner's role.
772+ // If removing the owner, leave both NewRoleId and NewRoleName empty in the request.
773+ // Calls PUT /Certificates/{id}/Owner endpoint.
774+ func (c * Client ) ChangeCertificateOwnerRole (
775+ certificateId int ,
776+ req * OwnerRequest ,
777+ params ... * CertificateOwnerChangeParams ,
778+ ) error {
779+ log .Printf ("[INFO] Changing owner of certificate with ID %d in Keyfactor" , certificateId )
780+
781+ // Validate certificate ID
782+ if certificateId <= 0 {
783+ return errors .New ("certificate ID must be a positive integer" )
784+ }
785+
786+ // Set Keyfactor-specific headers
787+ headers := & apiHeaders {
788+ Headers : []StringTuple {
789+ {"x-keyfactor-api-version" , "1" },
790+ {"x-keyfactor-requested-with" , "APIClient" },
791+ {"Content-Type" , "application/json" },
792+ },
793+ }
794+
795+ // Build URL with query parameters
796+ endpoint := fmt .Sprintf ("Certificates/%d/Owner" , certificateId )
797+ var queryParams []string
798+
799+ if len (params ) > 0 && params [0 ] != nil {
800+ param := params [0 ]
801+ if param .CollectionId != nil {
802+ queryParams = append (queryParams , fmt .Sprintf ("collectionId=%d" , * param .CollectionId ))
803+ }
804+ if param .ContainerId != nil {
805+ queryParams = append (queryParams , fmt .Sprintf ("containerId=%d" , * param .ContainerId ))
806+ }
807+ }
808+
809+ if len (queryParams ) > 0 {
810+ endpoint += "?" + strings .Join (queryParams , "&" )
811+ }
812+
813+ keyfactorAPIStruct := & request {
814+ Method : "PUT" ,
815+ Endpoint : endpoint ,
816+ Headers : headers ,
817+ Payload : req ,
818+ }
819+
820+ resp , err := c .sendRequest (keyfactorAPIStruct )
821+ if err != nil {
822+ return err
823+ }
824+
825+ // Check if the response indicates success (204 No Content expected)
826+ if resp .StatusCode != http .StatusNoContent {
827+ return fmt .Errorf ("failed to change certificate owner: HTTP %d" , resp .StatusCode )
828+ }
829+
830+ return nil
831+ }
832+
771833// createSubject builds the certificate subject string from a passed CertificateSubject argument.
772834func createSubject (cs CertificateSubject ) (string , error ) {
773835 var subject string
0 commit comments