const (
CsrHeaderName = "CSR"
- PkHeaderName = "PK"
+ PkHeaderName = "PK"
)
type CertServiceClient interface {
}
type CertServiceClientImpl struct {
- healthUrl string
+ healthUrl string
certificationUrl string
httpClient HTTPClient
}
TrustedCertificates []string `json:"trustedCertificates"`
}
+type ResponseException struct {
+ ErrorMessage string `json:"errorMessage"`
+}
+
func (client *CertServiceClientImpl) CheckHealth() error {
request, err := http.NewRequest("GET", client.healthUrl, nil)
if err != nil {
return err
}
- if response.StatusCode != 200 {
+ if response.StatusCode != http.StatusOK {
return fmt.Errorf("health check retured status code [%d]", response.StatusCode)
}
return nil
}
-
func (client *CertServiceClientImpl) GetCertificates(csr []byte, key []byte) (*CertificatesResponse, error) {
request, err := http.NewRequest("GET", client.certificationUrl, nil)
return nil, err
}
+ if response.StatusCode != http.StatusOK {
+ var responseException ResponseException
+ err = json.NewDecoder(response.Body).Decode(&responseException)
+ return nil, fmt.Errorf("CertService API returned status code [%d] and message [%s]",
+ response.StatusCode, responseException.ErrorMessage)
+ }
+
var certificatesResponse CertificatesResponse
err = json.NewDecoder(response.Body).Decode(&certificatesResponse)
if err != nil {