mirror of
https://github.com/hanzokms/terraform-provider.git
synced 2026-10-30 20:29:45 +00:00
100 lines
3.4 KiB
Go
100 lines
3.4 KiB
Go
package kmsclient
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/hanzokms/terraform-provider/internal/errors"
|
|
)
|
|
|
|
const (
|
|
operationCreateCertificateProfile = "CallCreateCertificateProfile"
|
|
operationGetCertificateProfile = "CallGetCertificateProfile"
|
|
operationUpdateCertificateProfile = "CallUpdateCertificateProfile"
|
|
operationDeleteCertificateProfile = "CallDeleteCertificateProfile"
|
|
)
|
|
|
|
func (client Client) CreateCertificateProfile(request CreateCertificateProfileRequest) (CreateCertificateProfileResponse, error) {
|
|
var profileResponse CreateCertificateProfileResponse
|
|
response, err := client.Config.HttpClient.
|
|
R().
|
|
SetResult(&profileResponse).
|
|
SetHeader("User-Agent", USER_AGENT).
|
|
SetBody(request).
|
|
Post("api/v1/cert-manager/certificate-profiles")
|
|
|
|
if err != nil {
|
|
return CreateCertificateProfileResponse{}, errors.NewGenericRequestError(operationCreateCertificateProfile, err)
|
|
}
|
|
|
|
if response.IsError() {
|
|
return CreateCertificateProfileResponse{}, errors.NewAPIErrorWithResponse(operationCreateCertificateProfile, response, nil)
|
|
}
|
|
|
|
return profileResponse, nil
|
|
}
|
|
|
|
func (client Client) GetCertificateProfile(request GetCertificateProfileRequest) (GetCertificateProfileResponse, error) {
|
|
var profileResponse GetCertificateProfileResponse
|
|
req := client.Config.HttpClient.
|
|
R().
|
|
SetResult(&profileResponse).
|
|
SetHeader("User-Agent", USER_AGENT)
|
|
|
|
if request.IncludeConfigs {
|
|
req.SetQueryParam("includeConfigs", "true")
|
|
}
|
|
|
|
response, err := req.Get(fmt.Sprintf("api/v1/cert-manager/certificate-profiles/%s", request.ProfileId))
|
|
|
|
if err != nil {
|
|
return GetCertificateProfileResponse{}, errors.NewGenericRequestError(operationGetCertificateProfile, err)
|
|
}
|
|
|
|
if response.IsError() {
|
|
if response.StatusCode() == 404 || response.StatusCode() == 422 {
|
|
return GetCertificateProfileResponse{}, ErrNotFound
|
|
}
|
|
return GetCertificateProfileResponse{}, errors.NewAPIErrorWithResponse(operationGetCertificateProfile, response, nil)
|
|
}
|
|
|
|
return profileResponse, nil
|
|
}
|
|
|
|
func (client Client) UpdateCertificateProfile(request UpdateCertificateProfileRequest) (UpdateCertificateProfileResponse, error) {
|
|
var profileResponse UpdateCertificateProfileResponse
|
|
response, err := client.Config.HttpClient.
|
|
R().
|
|
SetResult(&profileResponse).
|
|
SetHeader("User-Agent", USER_AGENT).
|
|
SetBody(request).
|
|
Patch(fmt.Sprintf("api/v1/cert-manager/certificate-profiles/%s", request.ProfileId))
|
|
|
|
if err != nil {
|
|
return UpdateCertificateProfileResponse{}, errors.NewGenericRequestError(operationUpdateCertificateProfile, err)
|
|
}
|
|
|
|
if response.IsError() {
|
|
return UpdateCertificateProfileResponse{}, errors.NewAPIErrorWithResponse(operationUpdateCertificateProfile, response, nil)
|
|
}
|
|
|
|
return profileResponse, nil
|
|
}
|
|
|
|
func (client Client) DeleteCertificateProfile(request DeleteCertificateProfileRequest) (DeleteCertificateProfileResponse, error) {
|
|
var profileResponse DeleteCertificateProfileResponse
|
|
response, err := client.Config.HttpClient.
|
|
R().
|
|
SetResult(&profileResponse).
|
|
SetHeader("User-Agent", USER_AGENT).
|
|
Delete(fmt.Sprintf("api/v1/cert-manager/certificate-profiles/%s", request.ProfileId))
|
|
|
|
if err != nil {
|
|
return DeleteCertificateProfileResponse{}, errors.NewGenericRequestError(operationDeleteCertificateProfile, err)
|
|
}
|
|
|
|
if response.IsError() {
|
|
return DeleteCertificateProfileResponse{}, errors.NewAPIErrorWithResponse(operationDeleteCertificateProfile, response, nil)
|
|
}
|
|
|
|
return profileResponse, nil
|
|
}
|