@@ -25,30 +25,30 @@ type SignerBuilder func(*v1alpha1.IssuerSpec, map[string][]byte) (Signer, error)
2525
2626func HealthCheckerFromIssuerAndSecretData (spec * v1alpha1.IssuerSpec , secretData map [string ][]byte ) (HealthChecker , error ) {
2727 return & signer {
28- siteUrl : spec .URL ,
29- caId : spec .CaId ,
30- clientId : spec .Authentication . UniversalAuth . ClientId ,
31- certificateTemplateId : spec .CertificateTemplateId ,
32- clientSecret : string (secretData ["clientSecret" ]),
28+ siteUrl : spec .URL ,
29+ projectId : spec .ProjectID ,
30+ certificateTemplateName : spec .CertificateTemplateName ,
31+ clientId : spec .Authentication . UniversalAuth . ClientId ,
32+ clientSecret : string (secretData ["clientSecret" ]),
3333 }, nil
3434}
3535
3636func SignerFromIssuerAndSecretData (spec * v1alpha1.IssuerSpec , secretData map [string ][]byte ) (Signer , error ) {
3737 return & signer {
38- siteUrl : spec .URL ,
39- caId : spec .CaId ,
40- certificateTemplateId : spec .CertificateTemplateId ,
41- clientId : spec .Authentication .UniversalAuth .ClientId ,
42- clientSecret : string (secretData ["clientSecret" ]),
38+ siteUrl : spec .URL ,
39+ projectId : spec .ProjectID ,
40+ certificateTemplateName : spec .CertificateTemplateName ,
41+ clientId : spec .Authentication .UniversalAuth .ClientId ,
42+ clientSecret : string (secretData ["clientSecret" ]),
4343 }, nil
4444}
4545
4646type signer struct {
47- siteUrl string
48- caId string
49- certificateTemplateId string
50- clientId string
51- clientSecret string
47+ siteUrl string
48+ projectId string
49+ certificateTemplateName string
50+ clientId string
51+ clientSecret string
5252}
5353
5454func (o * signer ) Check () error {
@@ -84,10 +84,10 @@ type AuthResponse struct {
8484}
8585
8686type SignCertificateRequest struct {
87- CaId string `json:"caId ,omitempty"`
88- CertificateTemplateId string `json:"certificateTemplateId ,omitempty"`
89- Csr string `json:"csr"`
90- Ttl string `json:"ttl,omitempty"`
87+ ProjectId string `json:"projectId ,omitempty"`
88+ CertificateTemplateName string `json:"certificateTemplateName ,omitempty"`
89+ Csr string `json:"csr"`
90+ Ttl string `json:"ttl,omitempty"`
9191}
9292
9393type SignCertificateResponse struct {
@@ -98,12 +98,6 @@ type SignCertificateResponse struct {
9898}
9999
100100func (o * signer ) Sign (cr certmanager.CertificateRequest ) ([]byte , []byte , error ) {
101-
102- // Ensure either caId or certificateTemplateId is provided
103- if o .caId == "" && o .certificateTemplateId == "" {
104- return nil , nil , fmt .Errorf ("Either caId or certificateTemplateId must be provided" )
105- }
106-
107101 csrBytes := cr .Spec .Request
108102 // csr, err := parseCSR(csrBytes)
109103 // if err != nil {
@@ -116,7 +110,7 @@ func (o *signer) Sign(cr certmanager.CertificateRequest) ([]byte, []byte, error)
116110 signCertificateResponse := SignCertificateResponse {}
117111
118112 // Login operation against Infisical
119- _ , err := client .R ().
113+ res , err := client .R ().
120114 SetHeader ("Content-Type" , "application/x-www-form-urlencoded" ).
121115 SetFormData (map [string ]string {
122116 "clientId" : o .clientId ,
@@ -129,33 +123,39 @@ func (o *signer) Sign(cr certmanager.CertificateRequest) ([]byte, []byte, error)
129123 if err != nil {
130124 return nil , nil , err
131125 }
126+ if res .IsError () {
127+ return nil , nil , fmt .Errorf ("%s" , res .String ())
128+ }
132129
133130 // Define the request body based on your CSR
134131 requestBody := SignCertificateRequest {
135- Csr : string (csrBytes ), // Required
136- Ttl : "90d" , // Default ttl
137- }
138-
139- if o .caId != "" {
140- requestBody .CaId = o .caId
141- }
142- if o .certificateTemplateId != "" {
143- requestBody .CertificateTemplateId = o .certificateTemplateId
132+ Csr : string (csrBytes ), // Required
133+ Ttl : "90d" , // Default ttl,
134+ ProjectId : o .projectId ,
135+ CertificateTemplateName : o .certificateTemplateName ,
144136 }
145137
146138 if cr .Spec .Duration != nil {
147139 requestBody .Ttl = fmt .Sprintf ("%ds" , int (cr .Spec .Duration .Duration .Seconds ()))
148140 }
149141
150142 // Make the POST request with Bearer token authentication and JSON body
151- _ , err = client .R ().
143+ res , err = client .R ().
152144 SetHeader ("Content-Type" , "application/json" ).
153145 SetHeader ("Authorization" , "Bearer " + authResponse .AccessToken ).
154146 SetBody (requestBody ).
155147 SetResult (& signCertificateResponse ).
156- Post (o .siteUrl + "/api/v1/pki/certificates/sign-certificate" )
148+ Post (o .siteUrl + "/api/v2/pki/certificate-templates/" + o .certificateTemplateName + "/sign-certificate" )
149+
150+ // Check for errors
151+ if err != nil {
152+ return nil , nil , err
153+ }
154+ if res .IsError () {
155+ return nil , nil , fmt .Errorf ("%s" , res .String ())
156+ }
157157
158- certificate := signCertificateResponse .Certificate // Leaf certificate
158+ certificate := signCertificateResponse .Certificate // Leaf certificate
159159 chainPem := signCertificateResponse .CertificateChain // Full chain (intermediate certs + root cert)
160160
161161 caChainCerts , rootCACert , err := splitRootCACertificate ([]byte (chainPem ))
0 commit comments